• 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!

TalkAction RevScript Banking

Itutorial

Premium User
Premium User
Joined
Dec 23, 2014
Messages
1,956
Solutions
52
Reaction score
649
TFS 1.3+

!balance, !deposit, !withdraw, !transfer

Lua:
local banking = TalkAction("!balance","!deposit","!withdraw","!transfer")
function banking.onSay(player, words, param)
    if (words == "!balance") then
        player:popupFYI("[Balance]: "..player:getBankBalance())
        return false
 
    elseif (words == "!deposit") or (words == "!withdraw") then
        if param == "" then
            player:sendCancelMessage("Usage: !deposit all / !deposit amount")
            return false
        end
 
        local amount = nil
        if param == "all" then
            if (words == "!withdraw") then
                player:sendCancelMessage("You must type an amount to withdraw. You cannot without all.")
                return false
            end
            amount = player:getMoney()
        elseif tonumber(param) ~= nil then
            amount = math.abs(tonumber(param) or 0)
        end
 
        if amount <= 0 or amount > 100000000 then
            player:sendCancelMessage("You can only withdraw or deposit 1-100kk gold.")
            return false
        end
 
        if (words == "!deposit") then
            if player:removeMoney(amount) then
                local oldBalance = player:getBankBalance()
                player:setBankBalance(oldBalance + amount)
                player:popupFYI("[Old Balance]: "..oldBalance.."\n[New Balance]: "..player:getBankBalance().."\n\n[Deposit]: "..amount)
            else
                player:sendCancelMessage("You do not have that much gold.")
            end
        elseif (words == "!withdraw") then
            if player:getBankBalance() < amount then
                player:sendCancelMessage("You do not have that much gold in your bank.")
            return false
            end
    
            local oldBalance = player:getBankBalance()
            player:setBankBalance(player:getBankBalance() - amount)
            player:addMoney(amount)
            player:popupFYI("[Old Balance]: "..oldBalance.."\n[New Balance]: "..player:getBankBalance().."\n\n[Withdraw]: "..amount)
        end
 
    elseif (words == "!transfer") then
   
local t = param:split(",")
        local target = t[1]
        local amount = t[2]
       
        if not target or not amount then
            player:sendCancelMessage("Usage: !transfer player, amount")
        return false
        end
   
        if tonumber(amount) == nil then
            player:sendCancelMessage("Usage: !transfer player, amount")
            return false
        end
    
        if target:lower() == player:getName():lower() then
            player:sendCancelMessage("Why even try.")
            return false
        end
   
        amount = math.abs(tonumber(amount) or 0)
   
        if amount <= 0 or amount > 100000000 then
            player:sendCancelMessage("You can only transfer 1-100kk gold.")
            return false
        end
   
        if player:getBankBalance() < amount then
            player:sendCancelMessage("You do not have that much gold in your bank.")
            return false
        end
   
        local targetPlayer = Player(target)
        local oldBalance = player:getBankBalance()
        local info = getPlayerDatabaseInfo(target)

        if not info then
                player:sendCancelMessage("Player does not exist.")
        return false
        end

        player:transferMoneyTo(info, amount)
        player:popupFYI("[Old Balance]: "..oldBalance.."\n[New Balance]: "..player:getBankBalance().."\n\n[Transfer]: "..amount)
    end
    return false
end

banking:separator(" ")
banking:register()
 
Last edited:

Sarah Wesker

ค∂vαηcε รүηтαx ❤
Support Team
Joined
Mar 16, 2017
Messages
1,032
Solutions
102
Reaction score
1,083
Location
London
GitHub
MillhioreBT
elseif tonumber(param) ~= nil then
I see that you are checking the parameter a lot param
When I said it was bulletproof, I meant it
you can put anything into that function, it will only return positive numbers, and if you insert something that cannot be converted to numbers, it just returns 0
Here the visual example
1627666272050.png
I just want to teach you little tricks, it is not to annoy, in fact there is nothing wrong with always double checking things ;)
 
OP
OP
Itutorial

Itutorial

Premium User
Premium User
Joined
Dec 23, 2014
Messages
1,956
Solutions
52
Reaction score
649
elseif tonumber(param) ~= nil then
I see that you are checking the parameter a lot param
When I said it was bulletproof, I meant it
you can put anything into that function, it will only return positive numbers, and if you insert something that cannot be converted to numbers, it just returns 0
Here the visual example
View attachment 60759
I just want to teach you little tricks, it is not to annoy, in fact there is nothing wrong with always double checking things ;)
You are good. Honestly after having so much trouble with it I didn't really go through it very well once I got it working in one script. I released it here so it wouldn't just sit in the support area. I will go through it again another time and update this eventually.

I do know how math.abs works but I was more focused on why things weren't working that should of which seems to be fixed with the changes you pulled for on github. I appreciate you sharing your knowledge at anytime unless its to be vindictive or cocky which plenty do on here.
 

Sarah Wesker

ค∂vαηcε รүηтαx ❤
Support Team
Joined
Mar 16, 2017
Messages
1,032
Solutions
102
Reaction score
1,083
Location
London
GitHub
MillhioreBT
TFS 1.3+

!balance, !deposit, !withdraw, !transfer


First you need to fix a problem in TFS 1.3 data/lib/core/player.lua

Lua:
function Player.transferMoneyTo(self, target, amount)

change
Lua:
local targetPlayer = Player(target.guid)

to
Lua:
local targetPlayer = Player(target)

Lua:
local banking = TalkAction("!balance","!deposit","!withdraw","!transfer")
function banking.onSay(player, words, param)
    if (words == "!balance") then
        player:popupFYI("[Balance]: "..player:getBankBalance())
        return false
  
    elseif (words == "!deposit") or (words == "!withdraw") then
        if param == "" then
            player:sendCancelMessage("Usage: !deposit all / !deposit amount")
            return false
        end
 
        local amount = nil
        if param == "all" then
            if (words == "!withdraw") then
                player:sendCancelMessage("You must type an amount to withdraw. You cannot without all.")
                return false
            end
            amount = player:getMoney()
        elseif tonumber(param) ~= nil then
            amount = math.abs(tonumber(param) or 0)
        end
 
        if amount <= 0 or amount > 100000000 then
            player:sendCancelMessage("You can only withdraw or deposit 1-100kk gold.")
            return false
        end
  
        if (words == "!deposit") then
            if player:removeMoney(amount) then
                local oldBalance = player:getBankBalance()
                player:setBankBalance(oldBalance + amount)
                player:popupFYI("[Old Balance]: "..oldBalance.."\n[New Balance]: "..player:getBankBalance().."\n\n[Deposit]: "..amount)
            else
                player:sendCancelMessage("You do not have that much gold.")
            end
        elseif (words == "!withdraw") then
            if player:getBankBalance() < amount then
                player:sendCancelMessage("You do not have that much gold in your bank.")
            return false
            end
      
            local oldBalance = player:getBankBalance()
            player:setBankBalance(player:getBankBalance() - amount)
            player:addMoney(amount)
            player:popupFYI("[Old Balance]: "..oldBalance.."\n[New Balance]: "..player:getBankBalance().."\n\n[Withdraw]: "..amount)
        end
  
    elseif (words == "!transfer") then
     
local t = param:split(",")
        local target = t[1]
        local amount = t[2]
         
        if not target or not amount then
            player:sendCancelMessage("Usage: !transfer player, amount")
        return false
        end
     
        if tonumber(amount) == nil then
            player:sendCancelMessage("Usage: !transfer player, amount")
            return false
        end
      
        if target:lower() == player:getName():lower() then
            player:sendCancelMessage("Why even try.")
            return false
        end
     
        amount = math.abs(tonumber(amount) or 0)
     
        if amount <= 0 or amount > 100000000 then
            player:sendCancelMessage("You can only transfer 1-100kk gold.")
            return false
        end
     
        if player:getBankBalance() < amount then
            player:sendCancelMessage("You do not have that much gold in your bank.")
            return false
        end
     
        local oldBalance = player:getBankBalance()
        player:transferMoneyTo(target, amount)
        player:popupFYI("[Old Balance]: "..oldBalance.."\n[New Balance]: "..player:getBankBalance().."\n\n[Transfer]: "..amount)
    end
    return false
end

banking:separator(" ")
banking:register()
In fact, recommending changing this is somewhat troll, since you would be breaking the Npc that comes by default in TFS: Better investigate a little why this function uses guid, instead of thinking that it is an error, I will leave it for you as homework, to save me the explanation ;)
and it can be used normally anyway;), you just have to know how to pass the arguments correctly

This damages the TFS Banker Npc:
Lua:
function Player.transferMoneyTo(self, target, amount)

change
Lua:
local targetPlayer = Player(target.guid)

to
Lua:
local targetPlayer = Player(target)
 
OP
OP
Itutorial

Itutorial

Premium User
Premium User
Joined
Dec 23, 2014
Messages
1,956
Solutions
52
Reaction score
649
In fact, recommending changing this is somewhat troll, since you would be breaking the Npc that comes by default in TFS: Better investigate a little why this function uses guid, instead of thinking that it is an error, I will leave it for you as homework, to save me the explanation ;)
and it can be used normally anyway;), you just have to know how to pass the arguments correctly

This damages the TFS Banker Npc:
Lua:
function Player.transferMoneyTo(self, target, amount)

change
Lua:
local targetPlayer = Player(target.guid)

to
Lua:
local targetPlayer = Player(target)
If someone is using this talkaction I doubt they will use a banking npc. If they still wanted an NPC they could pass the player name in the npc file rather than the userdata. I think for versatility it is better without the userdata because the code can be called without an error without having to pass userdata of a player. (meaning the only way to transfer money is if the player is online because the code would throw an error if he isn't).

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
 

Sarah Wesker

ค∂vαηcε รүηтαx ❤
Support Team
Joined
Mar 16, 2017
Messages
1,032
Solutions
102
Reaction score
1,083
Location
London
GitHub
MillhioreBT
You can simply adapt your script and submit a table with the guid key
per example: player:transferMoneyTo({guid=target:getGuid()}, amount)
I say this, because if someone comes later asking for help that the npc bank does not work
 

EvulMastah

๏̯͡๏﴿
Premium User
Joined
Aug 19, 2007
Messages
4,865
Reaction score
274
change
Lua:
db.query("UPDATE `players` SET `balance` = `balance` + " .. amount .. " WHERE `id` = '" .. target.guid .. "'")

to
Lua:
db.query("UPDATE `players` SET `balance` = `balance` + " .. amount .. " WHERE `name` = '" .. target .. "'")
top kek
 
OP
OP
Itutorial

Itutorial

Premium User
Premium User
Joined
Dec 23, 2014
Messages
1,956
Solutions
52
Reaction score
649
So it looks like an array is sent in the place of target. I don't really see how that was the best way to go there. Anyway, I will post a different way to do it in the talkaction instead of changing the transfer code though I think it shouldn't be set up like that.

Should probably make a little note of that kind of stuff above the functions
 
Last edited:
Top