Jump to content
kyleflow

Help on lua coding

Recommended Posts

Hi guys, I've finally found a gameserver.exe that would make the code from the forum for crystals by mobs extension. For that I attached a gameserver.exe that already added by LuaSQL.dll in the link provided for 1.36 or 1.38 server files.

 

https://drive.google.com/drive/folders/1KHu1Txlj1thwgbiUtiBEwYPFlgR2aBti?usp=sharing

 

Moving on to the question, this is the coding for crystal by mobs from the forum.

print("* Loading CrystalByMob Extension <init.lua>")
--[[ IGS Crystal By Mob Extension made By Vasil pkoDev,Please do not claim or redistribute the credits :)
*Requirements:
-LuaSQL by Wrexor
-TradeServer Program
-TradeDB 
-SQL 2008 or higher

*Configuration:
I guess the example i gave is clear
Just if you're going to use .\SQLEXPRESS , make it x2 dashes otherwise it will be as .SQLEXPRESS
e.g : .\\SQLEXPRESS

Just change the map that the function will run inside and the monster ID that will give the IGSP

If encountering any bug or flaw or glitch,please contact me - Vasil

--]]
SQLConnector = {};
SQLConnector.sql = { host = "127.0.0.1\\SQLEXPRESS", user = "sa", pass = "Y87dc#$98", db = "TradeDB" };

CrystalByMobHook = GetExp_PKM
GetExp_PKM = function( dead , atk , money  )
	CrystalByMobHook(dead,atk, money)
	local DeadMonster = GetChaID(dead)
	local accountName = GetActName(atk)
	local Money = Money
	local Rum = { };
	Rum['Money'] = Money;

	if(GetChaMapName(atk) == "garner" or GetChaMapName(atk) == "crystal") then
		if(DeadMonster == 1526)then
			QueryAsync(
			SQLConnector.sql['host'],
			SQLConnector.sql['user'],
			SQLConnector.sql['pass'],
			"UPDATE "..SQLConnector.sql['db']..".dbo.AccountInfo SET Money = Money + 1 WHERE accName = '"..accountName.."'"
	);
			BickerNotice( atk, "[IGSP]:You have obtained 1 IGS Crystal from "..GetChaDefaultName(dead) )
		end 
	end
end

 

Based on the coding, this bit does not declared the 'crystal' when checking for MapName.

 

if(GetChaMapName(atk) == "garner" or GetChaMapName(atk) == "crystal") then

 

So, how do I made that crystal stored all the maps name that I desired so that I don't have individually put the map name.

I searched the example on internet but still unable to understand it well and when tested on the files, it did not detected the map name stored.

Hope community can response about this. Thanks

Share this post


Link to post
Share on other sites

If you want to apply this to all map, then you can simply remove this condition.

 

Additionally, unrelated to your question, you’re not checking if “QueryAsync” call was successful before showing BickerNotice, so basically if the call did not go through for whatever reason, the user will still see a message saying they’ve received the crystals.

Share this post


Link to post
Share on other sites
1 hour ago, champ said:

If you want to apply this to all map, then you can simply remove this condition.

 

Additionally, unrelated to your question, you’re not checking if “QueryAsync” call was successful before showing BickerNotice, so basically if the call did not go through for whatever reason, the user will still see a message saying they’ve received the crystals.

Why did I not see it that perspective before. Simply remove the conditions and it still should work right. Thanks a lot mate. But for learning purpose. Is there a way to make that map check works.

Share this post


Link to post
Share on other sites

You can, I’ve not done any Lua code in top in a while, but you can create an array of all your maps that you want to alow and then loop through it in your code.

Share this post


Link to post
Share on other sites
On 6/23/2023 at 10:11 PM, champ said:

You can, I’ve not done any Lua code in top in a while, but you can create an array of all your maps that you want to alow and then loop through it in your code.

Or without any loops:

print("* Loading CrystalByMob Extension <init.lua>")
--[[ IGS Crystal By Mob Extension made By Vasil pkoDev,Please do not claim or redistribute the credits :)
*Requirements:
-LuaSQL by Wrexor
-TradeServer Program
-TradeDB 
-SQL 2008 or higher

*Configuration:
I guess the example i gave is clear
Just if you're going to use .\SQLEXPRESS , make it x2 dashes otherwise it will be as .SQLEXPRESS
e.g : .\\SQLEXPRESS

Just change the map that the function will run inside and the monster ID that will give the IGSP

If encountering any bug or flaw or glitch,please contact me - Vasil

--]]
SQLConnector = {};
SQLConnector.sql = { host = "127.0.0.1\\SQLEXPRESS", user = "sa", pass = "Y87dc#$98", db = "TradeDB" };
CrystalByMobHook = GetExp_PKM
local maps = {
  garner = true,
  crystal = true
}
GetExp_PKM = function( dead , atk , money  )
	CrystalByMobHook(dead,atk, money)
	local DeadMonster = GetChaID(dead)
	local accountName = GetActName(atk)
    local currentMap = GetChaMapName(atk)

	if maps[currentMap] then
		if DeadMonster == 1526 then
			QueryAsync(
			SQLConnector.sql['host'],
			SQLConnector.sql['user'],
			SQLConnector.sql['pass'],
			"UPDATE "..SQLConnector.sql['db']..".dbo.AccountInfo SET Money = Money + 1 WHERE accName = '"..accountName.."'"
	);
			BickerNotice( atk, "[IGSP]: You have obtained 1 IGS Crystal from "..GetChaDefaultName(dead) )
		end 
	end
end

 

  • Like 2

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...