FapFap 13 Report post Posted September 24, 2018 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? Quote Share this post Link to post Share on other sites
FapFap 13 Report post Posted September 26, 2018 BUMP Quote Share this post Link to post Share on other sites
Eviles 179 Report post Posted September 27, 2018 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. 1 Quote Share this post Link to post Share on other sites
FapFap 13 Report post Posted October 1, 2018 (edited) 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 October 1, 2018 by FapFap Quote Share this post Link to post Share on other sites
mkhzaleh 131 Report post Posted October 1, 2018 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 Quote Share this post Link to post Share on other sites
FapFap 13 Report post Posted October 1, 2018 (edited) @mkhzaleh it doesn't add any points when clicking the item, also doesn't add the LG system "Imps System" Edited October 1, 2018 by FapFap Quote Share this post Link to post Share on other sites
iZae 55 Report post Posted October 1, 2018 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 Quote Share this post Link to post Share on other sites
Eviles 179 Report post Posted October 1, 2018 @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 Quote Share this post Link to post Share on other sites
FapFap 13 Report post Posted October 1, 2018 (edited) @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 October 1, 2018 by FapFap Quote Share this post Link to post Share on other sites
FapFap 13 Report post Posted October 2, 2018 (edited) @Satan I'm using this: 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 October 2, 2018 by FapFap Quote Share this post Link to post Share on other sites
Sultan 68 Report post Posted October 2, 2018 This will let your system to hang for couple of secs. I've stopped using it. You should use other "LuaSQL" version provided. Quote Share this post Link to post Share on other sites
FapFap 13 Report post Posted October 2, 2018 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 Quote Share this post Link to post Share on other sites
Sultan 68 Report post Posted October 2, 2018 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. Quote Share this post Link to post Share on other sites
FapFap 13 Report post Posted October 2, 2018 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? Quote Share this post Link to post Share on other sites
FapFap 13 Report post Posted October 3, 2018 BUMP?! Quote Share this post Link to post Share on other sites
mkhzaleh 131 Report post Posted October 3, 2018 dm me i will share one with u Quote Share this post Link to post Share on other sites
FapFap 13 Report post Posted October 3, 2018 @mkhzaleh i already did Quote Share this post Link to post Share on other sites
FapFap 13 Report post Posted October 4, 2018 (edited) 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: Instead of showing something like this: LuaSql.dll successfully loads on gameserver tho.. any one can help?@Wrexor @KONG Edited October 4, 2018 by FapFap Quote Share this post Link to post Share on other sites
Wrexor 61 Report post Posted October 5, 2018 Check that your connection info is correct, you have correct permissions and configuration for SQL Server. Quote Share this post Link to post Share on other sites
FapFap 13 Report post Posted October 5, 2018 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 Quote Share this post Link to post Share on other sites
FapFap 13 Report post Posted October 6, 2018 @Wrexor @Satan @mkhzaleh @Sultan guys why im having this error when i click the item: This is the DB Function: This is the itemeffect: Could anyone help?! UP thread i posted my whole LuaSQL function ( Tested on both versions "Clean" 1.36 & 1.38 both same problems )! Quote Share this post Link to post Share on other sites
mkhzaleh 131 Report post Posted October 6, 2018 4 hours ago, FapFap said: @Wrexor @Satan @mkhzaleh @Sultan guys why im having this error when i click the item: This is the DB Function: This is the itemeffect: 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 Quote Share this post Link to post Share on other sites
FapFap 13 Report post Posted October 6, 2018 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 Quote Share this post Link to post Share on other sites
Sultan 68 Report post Posted October 6, 2018 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. Quote Share this post Link to post Share on other sites
FapFap 13 Report post Posted October 6, 2018 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 Quote Share this post Link to post Share on other sites