Try make new fuction, maybe problem is in
Lua:
function Player.transferMoneyTo(self, target, amount)
if not target then
return false -- target isn't set return false --
end
-- See if you can afford this transfer
local balance = self:getBankBalance()
if amount > balance then
return false
end
-- See if player is online
local targetPlayer = Player(target.guid) -- If player isn't online this will cause an error (unless you already checked if he is online and sent userdata --
if targetPlayer then -- Do a check that should of been done already because otherwise there is an error with above line --
targetPlayer:setBankBalance(targetPlayer:getBankBalance() + amount)
else -- Code will never reach this if player is not online. --
db.query("UPDATE `players` SET `balance` = `balance` + " .. amount .. " WHERE `id` = '" .. target.guid .. "'")
end
self:setBankBalance(self:getBankBalance() - amount)
return true
end
Try call diferent the fuction and call in the system, for example:
Lua:
function Player.transferMoneyToTalkaction(self, target, amount)
if not target then
return false -- target isn't set return false --
end
-- See if you can afford this transfer
local balance = self:getBankBalance()
if amount > balance then
return false
end
-- See if player is online
local targetPlayer = Player(target.guid) -- If player isn't online this will cause an error (unless you already checked if he is online and sent userdata --
if targetPlayer then -- Do a check that should of been done already because otherwise there is an error with above line --
targetPlayer:setBankBalance(targetPlayer:getBankBalance() + amount)
else -- Code will never reach this if player is not online. --
db.query("UPDATE `players` SET `balance` = `balance` + " .. amount .. " WHERE `id` = '" .. target.guid .. "'")
end
self:setBankBalance(self:getBankBalance() - amount)
return true
end
Put the second modified function at the top of the entire script.
And change in line 82
Lua:
player:transferMoneyTo(target, amount)
To:
Lua:
player:transferMoneyToTalkaction(target, amount)
and keep first changes in target
local targetPlayer = Player(target)