• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua MySQL: How to update rightaway?

darkshin

New old member
Joined
Dec 14, 2010
Messages
231
Reaction score
22
Hey Guys!!

I have the following function and I am trying to update a character balance at MySql, but it only updates if the characters is online, logs out and then logs in. How can I make it update rightaway via MySql?

Code:
function setBalanceByGuid(guid, money)

local oldBalance = getBalanceByGuid(guid)
local newBalance = oldBalance + money
print(oldBalance, newBalance)
    db.query("UPDATE`players` SET `balance` = "..newBalance.." WHERE `id` = "..guid..";")
end
 
If the player is online you should use getPlayerBalance(cid)/doPlayerSetBalance(cid, balance). The players table (as most tables in the TFS's database) is loaded when needed (i.e a player logs in) and saved when appropriate (i.e the player logs off), that is why any player changes might be lost when he logs off.
 
If the player is online you should use getPlayerBalance(cid)/doPlayerSetBalance(cid, balance). The players table (as most tables in the TFS's database) is loaded when needed (i.e a player logs in) and saved when appropriate (i.e the player logs off), that is why any player changes might be lost when he logs off.
I see, so there's no way to do update while player is online. Ill make a check before calling the functions. Thank you!
 
Back
Top