Jump to content
FapFap

Imp Item (Card)

Recommended Posts

Could someone help me make a Item that can add Imps
ex: 100 Points IMP Card, when double click it will automatically add 100 imps on account..
I'm already using LuaSQL.dll on gameserver i just need help with the item function, anyone?

Share this post


Link to post
Share on other sites

Hello @FapFap!

Creating such function we will call the SQL.Execute() from LuaSQL and the UPDATE Statement of SQL:

SQL Update Statement

sample of script:

function GiveMallPoints(role,amount)
	local characterID,characterName,accountName = GetPlayerID(GetChaPlayer(role)),GetChaDefaultName(role),GetActName(role)
	SQL.Execute("UPDATE GameDB.dbo.account SET mall_points = mall_points + "..amount.." WHERE con_name = '"..accountName.."'")
	LG('LuaSql','[GiveMallPoints] = ChaID:['..characterID..'] ChaName:['..characterName..'] ActName['..accountName..'] successfully added '..amount..' mall_points.')
end

for usage, just call function name and params on itemeffect and replace amount param to points which will be added to account.

  • Like 1

lelouch_signature_by_vahntheknight-d4uafwj.png

Share this post


Link to post
Share on other sites

Hello @Satan, thanks for the help, i added something like this:

function ItemUse_Points ( role , Item )
	local points = GiveMallPoints(role,100)
	if points == 1 then
		SystemNotice(role ,"You just got 100 points !")
    end

end

It says on LuaSql logs that 100 points has been added succesfully but it didn't add any points, also it freezes the server for 5-10 seconds when i click the item.

edit: no errors at luaerr

Edited by FapFap

Share this post


Link to post
Share on other sites

try this
 

function AddImpsPoints(Player, Amount)
	local AccountName = GetActName(Player)
	local String = "UPDATE "..SQL.GameDB.Name..".dbo.account SET mall_points = mall_points + "..Amount.." WHERE act_name = '"..AccountName.."'"
	local Connect, CID = LuaSQL("connect", SQL.GameDB.Host, SQL.GameDB.User, SQL.GameDB.Password)
	if Connect == SQL_SUCCESS_WITH_INFO then
		local Success, Query = LuaSQL("query", CID, String)
		if Success == SQL_SUCCESS_WITH_INFO then
			local Data = LuaSQL("fetch", CID, Query)
			LuaSQL("freehandle", CID, Query)
			LuaSQL("close", CID)
		elseif Success == SQL_SUCCESS then
			LuaSQL("freehandle", CID, Query)
			LuaSQL("close", CID)
			return -9999
		end
	end
end

and this inside ItemEffect
 

ImpsPointCard = function(Player, Item)
	local Name = GetChaDefaultName(Player)
	local ItemID = GetItemID(Item)

	
	local Points = {

		[19790] = 0100, -- change 19790 to your item id 
		[19811] = 1000
					}

	local Amount = Points[ItemID]
	SystemNotice(Player ,"You just got "..Amount.." points !")
	LG("Imps System", " Player:["..GetChaDefaultName(Player).."], used:["..GetItemName(ItemID).."], gained:["..Amount.."]")
	
end

 

Share this post


Link to post
Share on other sites

You used ImpsPointCard as itemeffect function name right?

in your script I see "function ItemUse_Points ( role , Item )"

in mkhzaleh I see "ImpsPointCard = function(Player, Item)"

 

Also you have to set this constants (in case you didn't do it before)

SQL.GameDB.Name, SQL.GameDB.Host, SQL.GameDB.User, SQL.GameDB.Password

 

Share this post


Link to post
Share on other sites

@FapFap you don't need check if the functions returned value 1. Try something like that below:

 

function ItemUse_Points(role, Item)
	local itemID	= GetItemID(Item)
	local impVar	= {}
	impVar[0885] 	= 100 --Key = ItemID, Value = Imp Amount; For new item just do the same as this line;

	local NocLock 	= KitbagLock(role, 0)
	if NocLock == LUA_FALSE then
		SystemNotice(role,"Your inventory is being binded.")
		UseItemFailed(role)
		return
	end
	
	local Cha_Boat	= 0
	Cha_Boat = GetCtrlBoat(role)
	if Cha_Boat ~= nil then
		SystemNotice(role,"Cannot use while sailing")
		UseItemFailed (role)
		return
	end
	
	if impVar[itemID] ~= nil then
		GiveMallPoints(role, impVar[itemID])
	else
		SystemNotice(role, "IMP Card no longer registered!")
		UseItemFailed(role)
		return
	end
end

 


lelouch_signature_by_vahntheknight-d4uafwj.png

Share this post


Link to post
Share on other sites

@Satan shows at logs that points are added, but still doesn't add them and also freezing server for 5-10 seconds when clicking the item.

@iZae you got the full function of it? with sql configure for its lua

Edited by FapFap

Share this post


Link to post
Share on other sites

@Satan I'm using this:
12345.png.ccbeef0a47ac9ef4f6004cf2e533a9e5.png

But server freezes when clicking item and it wont add the points at the account in database, still it creates the logs that points has been added succesfully..

@mkhzaleh @iZae

Edited by FapFap

Share this post


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

This will let your system to hang for couple of secs. I've stopped using it. You should use other "LuaSQL" version provided.

The lua script from @mkhzaleh doesn't freeze but aint working, he didn't gave the full function for connection x.x

Share this post


Link to post
Share on other sites

You must use other luasql system as I said. The one you're using will hang your system.

 

For example, if you use it for another purpose and many players logged and used it your gameserver will hang. 

Share this post


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

You must use other luasql system as I said. The one you're using will hang your system.

 

For example, if you use it for another purpose and many players logged and used it your gameserver will hang. 

Yeah i understand that, but is there another luasql system you would suggest?

Share this post


Link to post
Share on other sites

I'm now having this error, when im testing this script by @Angelix
 

LUA_ARG_ERROR = 10
SQL_SUCCESS = 0
SQL_SUCCESS_WITH_INFO = 1
SQL_ERROR = -1
SQL_INVALID_HANDLE = -2
SQL_NO_DATA = 100

SQL = {
	AccountServer = {	Name = "AccountServer",	Host = "127.0.0.1",	User = "sa",	Password = "Y87dc#$98"},
	GameDB = {			Name = "GameDB",		Host = "127.0.0.1",	User = "sa",	Password = "Y87dc#$98"},
	TradeDB = {			Name = "TradeDB",		Host = "127.0.0.1",	User = "sa",	Password = "Y87dc#$98"}
	}

function GetAccountName()
	print("--------------------------------------------------")
	local String = "SELECT act_name FROM GameDB.dbo.account WHERE act_id IN (SELECT act_id FROM GameDB.dbo.character WHERE cha_name = 'Test')"
	local Connect, ConnectID = LuaSQL("connect", SQL.GameDB.Host, SQL.GameDB.User, SQL.GameDB.Password)
	if Connect == SQL_SUCCESS_WITH_INFO then
		print("Successful connection.")
		local Success, Query = LuaSQL("query", ConnectID, String)
		if Success == SQL_SUCCESS_WITH_INFO then
			print("Successful query.")
			local Data = LuaSQL("fetch", ConnectID, Query)
			print("Account Name = "..Data["act_name"])
			LuaSQL("freehandle", ConnectID, Query)
			LuaSQL("close", ConnectID)
			return
		end
	end
	print("--------------------------------------------------")
end
GetAccountName()

I'm having char name " Test " as i changed on script aswell, but this errors Shows up on gameserver when i open gameserver:
234.png.250a7dc419d39d0e19ab8d18f7475d1e.png

Instead of showing something like this:
235.PNG.15e55a6b1603483151802e0b03901120.PNG

LuaSql.dll successfully loads on gameserver tho.. any one can help?

@Wrexor @KONG

Edited by FapFap

Share this post


Link to post
Share on other sites
6 hours ago, Wrexor said:

Check that your connection info is correct, you have correct permissions and configuration for SQL Server.

I already checked connection info & set all rights on database just to test, and still gives same error, im using sql 2014

Share this post


Link to post
Share on other sites
4 hours ago, FapFap said:

@Wrexor @Satan @mkhzaleh @Sultan guys why im having this error when i click the item:
5.png.8958d174faffcf18ed4fae738b131e19.png

This is the DB Function:
7.png.7c2c52155cb8da7cae8171b90ab6b767.png

This is the itemeffect:
8.png.6080348f0f79f669c0c346c4b3fc7926.png

Could anyone help?!

UP thread i posted my whole LuaSQL function ( Tested on both versions "Clean" 1.36 & 1.38 both same problems )!

use this
 

ImpsPointCard = function(Player, Item)
	local Name = GetChaDefaultName(Player)
	local ItemID = GetItemID(Item)

	
	local Points = {

		[19790] = 0100, -- change 19790 to your item id 
		[19811] = 1000
					}

	local Amount = Points[ItemID]
	SystemNotice(Player ,"You just got "..Amount.." points !")
	LG("Imps System", " Player:["..GetChaDefaultName(Player).."], used:["..GetItemName(ItemID).."], gained:["..Amount.."]")
	
end

and this error your username or password wrong since sql can't connect 

Share this post


Link to post
Share on other sites
3 hours ago, mkhzaleh said:

use this
 


ImpsPointCard = function(Player, Item)
	local Name = GetChaDefaultName(Player)
	local ItemID = GetItemID(Item)

	
	local Points = {

		[19790] = 0100, -- change 19790 to your item id 
		[19811] = 1000
					}

	local Amount = Points[ItemID]
	SystemNotice(Player ,"You just got "..Amount.." points !")
	LG("Imps System", " Player:["..GetChaDefaultName(Player).."], used:["..GetItemName(ItemID).."], gained:["..Amount.."]")
	
end

and this error your username or password wrong since sql can't connect 

This itemeffect you shared doesn't give any imps when using the item, it just making the Logs that they been added successfully.. but no imps, also the SQL user / pw are Correct, i also test host as SQL Instance name but wont work
 

Share this post


Link to post
Share on other sites

is the LuaSql system working/loaded just fine? From error in LUA_ERR specified it says that it doesn't know what is "LuaSql" to begin with.

Share this post


Link to post
Share on other sites
22 minutes ago, Sultan said:

is the LuaSql system working/loaded just fine? From error in LUA_ERR specified it says that it doesn't know what is "LuaSql" to begin with.

Well it gameserver it says LuaSQL.dll Loaded, also the luasql file is loaded and i guess it work, i posted my luasql.lua function up this page

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...