• 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!
  • If you're using Gesior 2012 or MyAAC, please review this thread for information about a serious security vulnerability and a fix.

stable 1.2 tfs bank system

Itutorial

Excellent OT User
Joined
Dec 23, 2014
Messages
2,279
Solutions
68
Reaction score
919
in talkactions/scripts

Code:
function onSay(player, words, param)
    if words == "!deposit" then
        t = string.split(param, ",")
       
        amount = t[1]
        if amount ~= "all" then
       
        amount = tonumber(t[1])
       
        if amount > 0 then
            if player:removeMoney(amount) then
            local old_balance = getPlayerBalance(player)
                doPlayerSetBalance(player, getPlayerBalance(player) + amount)
                doPlayerPopupFYI(player, "[old balance]: "..old_balance.."\n[new balance]: "..getPlayerBalance(player))
            else
                player:sendCancelMessage("You do not have this much gold.")
            return false
            end
        end
        else
            player_gold = player:getMoney()
           
            if player_gold > 0 then
            local old_balance = getPlayerBalance(player)
                player:removeMoney(player_gold)
                doPlayerSetBalance(player, player_gold)
                doPlayerPopupFYI(player, "[old balance]: "..old_balance.."\n[new balance]: "..getPlayerBalance(player))
            else
                player:sendCancelMessage("You do not have any gold to deposit.")
            return false
            end
        end
       
    elseif words == "!withdraw" then
   
        t = string.split(param, ",")
       
        amount = tonumber(t[1])
       
        if amount <= 0 then
            player:sendCancelMessage("You must type a number value to withdraw.")
        return false
        end
       
        if amount > 100000000 then
            player:sendCancelMessage("You cannot withdraw more then 100 million gold.")
        return false
        end
       
        if getPlayerBalance(player) < amount then
            player:sendCancelMessage("You do not have this much gold!")
        return false
        end
       
       
        if doPlayerSetBalance(player, getPlayerBalance(player) - amount) then
            player:addMoney(amount)
            doPlayerPopupFYI(player, "[balance]: "..getPlayerBalance(player))
        end
       
    elseif words == "!balance" then
        doPlayerPopupFYI(player, "[balance]: "..getPlayerBalance(player))
       
    elseif words == "!transfer" then
   
        t = string.split(param, ",")
       
        target = Player(t[1])
        amount = tonumber(t[2])
       
        if not t[1] or not t[2] then
            player:sendCancelMessage("Type: !transfer player, amount")
        return false
        end
       
        if not target then
            player:sendCancelMessage("Player must be online.")
        return false
        end
       
        if target:getName() == player:getName() then
            player:sendCancelMessage("You cannot tranfer gold to yourself.")
        return false
        end
       
        if amount <= 0 then
            player:sendCancelMessage("You must transfer 1 or more gold.")
        return false
        end
       
        if getPlayerBalance(player) < amount then
            player:sendCancelMessage("You do not have this much gold.")
        return false
        end
       
        doPlayerSetBalance(player, getPlayerBalance(player) - amount)
        doPlayerSetBalance(target, getPlayerBalance(target) + amount)
        doPlayerPopupFYI(player, "You have added gold to his balance.")
       
    end
    return false
end

in talkactions.xml

Code:
    <talkaction words="!deposit" separator=" " script="banking.lua" />
    <talkaction words="!withdraw" separator=" " script="banking.lua" />
    <talkaction words="!balance" separator=" " script="banking.lua" />
    <talkaction words="!transfer" separator=" " script="banking.lua" />
 

demon088

#088 in the Horde
Joined
Jun 17, 2009
Messages
236
Solutions
3
Reaction score
26
Location
Hell
in talkactions/scripts

Code:
function onSay(player, words, param)
    if words == "!deposit" then
        t = string.split(param, ",")
      
        amount = t[1]
        if amount ~= "all" then
      
        amount = tonumber(t[1])
      
        if amount > 0 then
            if player:removeMoney(amount) then
            local old_balance = getPlayerBalance(player)
                doPlayerSetBalance(player, getPlayerBalance(player) + amount)
                doPlayerPopupFYI(player, "[old balance]: "..old_balance.."\n[new balance]: "..getPlayerBalance(player))
            else
                player:sendCancelMessage("You do not have this much gold.")
            return false
            end
        end
        else
            player_gold = player:getMoney()
          
            if player_gold > 0 then
            local old_balance = getPlayerBalance(player)
                player:removeMoney(player_gold)
                doPlayerSetBalance(player, player_gold)
                doPlayerPopupFYI(player, "[old balance]: "..old_balance.."\n[new balance]: "..getPlayerBalance(player))
            else
                player:sendCancelMessage("You do not have any gold to deposit.")
            return false
            end
        end
      
    elseif words == "!withdraw" then
  
        t = string.split(param, ",")
      
        amount = tonumber(t[1])
      
        if amount <= 0 then
            player:sendCancelMessage("You must type a number value to withdraw.")
        return false
        end
      
        if amount > 100000000 then
            player:sendCancelMessage("You cannot withdraw more then 100 million gold.")
        return false
        end
      
        if getPlayerBalance(player) < amount then
            player:sendCancelMessage("You do not have this much gold!")
        return false
        end
      
      
        if doPlayerSetBalance(player, getPlayerBalance(player) - amount) then
            player:addMoney(amount)
            doPlayerPopupFYI(player, "[balance]: "..getPlayerBalance(player))
        end
      
    elseif words == "!balance" then
        doPlayerPopupFYI(player, "[balance]: "..getPlayerBalance(player))
      
    elseif words == "!transfer" then
  
        t = string.split(param, ",")
      
        target = Player(t[1])
        amount = tonumber(t[2])
      
        if not t[1] or not t[2] then
            player:sendCancelMessage("Type: !transfer player, amount")
        return false
        end
      
        if not target then
            player:sendCancelMessage("Player must be online.")
        return false
        end
      
        if target:getName() == player:getName() then
            player:sendCancelMessage("You cannot tranfer gold to yourself.")
        return false
        end
      
        if amount <= 0 then
            player:sendCancelMessage("You must transfer 1 or more gold.")
        return false
        end
      
        if getPlayerBalance(player) < amount then
            player:sendCancelMessage("You do not have this much gold.")
        return false
        end
      
        doPlayerSetBalance(player, getPlayerBalance(player) - amount)
        doPlayerSetBalance(target, getPlayerBalance(target) + amount)
        doPlayerPopupFYI(player, "You have added gold to his balance.")
      
    end
    return false
end

in talkactions.xml

Code:
    <talkaction words="!deposit" separator=" " script="banking.lua" />
    <talkaction words="!withdraw" separator=" " script="banking.lua" />
    <talkaction words="!balance" separator=" " script="banking.lua" />
    <talkaction words="!transfer" separator=" " script="banking.lua" />
I am using it and it is all okay! Thank you! I'm using TFS 1.2.
 

demon088

#088 in the Horde
Joined
Jun 17, 2009
Messages
236
Solutions
3
Reaction score
26
Location
Hell
in talkactions/scripts

Code:
function onSay(player, words, param)
    if words == "!deposit" then
        t = string.split(param, ",")
      
        amount = t[1]
        if amount ~= "all" then
      
        amount = tonumber(t[1])
      
        if amount > 0 then
            if player:removeMoney(amount) then
            local old_balance = getPlayerBalance(player)
                doPlayerSetBalance(player, getPlayerBalance(player) + amount)
                doPlayerPopupFYI(player, "[old balance]: "..old_balance.."\n[new balance]: "..getPlayerBalance(player))
            else
                player:sendCancelMessage("You do not have this much gold.")
            return false
            end
        end
        else
            player_gold = player:getMoney()
          
            if player_gold > 0 then
            local old_balance = getPlayerBalance(player)
                player:removeMoney(player_gold)
                doPlayerSetBalance(player, player_gold)
                doPlayerPopupFYI(player, "[old balance]: "..old_balance.."\n[new balance]: "..getPlayerBalance(player))
            else
                player:sendCancelMessage("You do not have any gold to deposit.")
            return false
            end
        end
      
    elseif words == "!withdraw" then
  
        t = string.split(param, ",")
      
        amount = tonumber(t[1])
      
        if amount <= 0 then
            player:sendCancelMessage("You must type a number value to withdraw.")
        return false
        end
      
        if amount > 100000000 then
            player:sendCancelMessage("You cannot withdraw more then 100 million gold.")
        return false
        end
      
        if getPlayerBalance(player) < amount then
            player:sendCancelMessage("You do not have this much gold!")
        return false
        end
      
      
        if doPlayerSetBalance(player, getPlayerBalance(player) - amount) then
            player:addMoney(amount)
            doPlayerPopupFYI(player, "[balance]: "..getPlayerBalance(player))
        end
      
    elseif words == "!balance" then
        doPlayerPopupFYI(player, "[balance]: "..getPlayerBalance(player))
      
    elseif words == "!transfer" then
  
        t = string.split(param, ",")
      
        target = Player(t[1])
        amount = tonumber(t[2])
      
        if not t[1] or not t[2] then
            player:sendCancelMessage("Type: !transfer player, amount")
        return false
        end
      
        if not target then
            player:sendCancelMessage("Player must be online.")
        return false
        end
      
        if target:getName() == player:getName() then
            player:sendCancelMessage("You cannot tranfer gold to yourself.")
        return false
        end
      
        if amount <= 0 then
            player:sendCancelMessage("You must transfer 1 or more gold.")
        return false
        end
      
        if getPlayerBalance(player) < amount then
            player:sendCancelMessage("You do not have this much gold.")
        return false
        end
      
        doPlayerSetBalance(player, getPlayerBalance(player) - amount)
        doPlayerSetBalance(target, getPlayerBalance(target) + amount)
        doPlayerPopupFYI(player, "You have added gold to his balance.")
      
    end
    return false
end

in talkactions.xml

Code:
    <talkaction words="!deposit" separator=" " script="banking.lua" />
    <talkaction words="!withdraw" separator=" " script="banking.lua" />
    <talkaction words="!balance" separator=" " script="banking.lua" />
    <talkaction words="!transfer" separator=" " script="banking.lua" />
I have tested this system and it has this error:
When you use deposit all it replaces the amount added with your balance. So, if you deposit 10k and you had 5k, you will have 10k instead of 15k on your balance.
I have corrected this and also added withdraw all into the system in the next script:
Lua:
function onSay(player, words, param)
    if words == "!deposit" then
        t = string.split(param, ",")
      
        amount = t[1]
        if amount ~= "all" then       
        amount = tonumber(t[1])       
        if amount > 0 then
            if player:removeMoney(amount) then
            local old_balance = getPlayerBalance(player)
                doPlayerSetBalance(player, old_balance + amount)
                doPlayerPopupFYI(player, "[Previous balance]: "..old_balance.."\n[Actual balance]: "..getPlayerBalance(player))
            else
                player:sendCancelMessage("You do not have this much gold.")
            return false
            end
        end
        else
            player_gold = player:getMoney()           
            if player_gold > 0 then
            local old_balance = getPlayerBalance(player)
                player:removeMoney(player_gold)
                doPlayerSetBalance(player, old_balance + player_gold)
                doPlayerPopupFYI(player, "[Previous balance]: "..old_balance.."\n[Actual balance]: "..getPlayerBalance(player))
            else
                player:sendCancelMessage("You do not have any gold to deposit.")
            return false
            end
        end
      
    elseif words == "!withdraw" then   
        t = string.split(param, ",") 
    amount = t[1]
if amount ~= "all" then   
amount = tonumber(t[1])
        if amount <= 0 then
            player:sendCancelMessage("You must type a valid value to withdraw.")
        return false
        end       
        if amount > 100000000 then
            player:sendCancelMessage("You cannot withdraw more then 100 million gold.")
        return false
        end       
        if getPlayerBalance(player) < amount then
            player:sendCancelMessage("You do not have this much gold!")
        return false
        end   
      
        if doPlayerSetBalance(player, getPlayerBalance(player) - amount) then
            player:addMoney(amount)
            doPlayerPopupFYI(player, "[Balance]: "..getPlayerBalance(player))
        end
else
       local balance = getPlayerBalance(player)
       if balance > 0 then
            local old_balance = getPlayerBalance(player)
        if doPlayerSetBalance(player, getPlayerBalance(player) - balance) then
            player:addMoney(balance)
            doPlayerPopupFYI(player, "[Previous balance]: "..old_balance.."\n[Actual balance]: "..getPlayerBalance(player))
        end   
    else
       player:sendCancelMessage("You do not have gold to withraw!")   
    end
end      
    elseif words == "!balance" then
        doPlayerPopupFYI(player, "[Balance]: "..getPlayerBalance(player))
      
    elseif words == "!transfer" then
  
        t = string.split(param, ",")
      
        target = Player(t[1])
        amount = tonumber(t[2])
      
        if not t[1] or not t[2] then
            player:sendCancelMessage("You must type like: !transfer player, amount")
        return false
        end
      
        if not target then
            player:sendCancelMessage("Player must be online.")
        return false
        end
      
        if target:getName() == player:getName() then
            player:sendCancelMessage("You cannot transfer gold to yourself.")
        return false
        end
      
        if amount <= 0 then
            player:sendCancelMessage("You must transfer 1 or more gold.")
        return false
        end
      
        if getPlayerBalance(player) < amount then
            player:sendCancelMessage("You do not have this much gold.")
        return false
        end
      
        doPlayerSetBalance(player, getPlayerBalance(player) - amount)
        doPlayerSetBalance(target, getPlayerBalance(target) + amount)
        doPlayerPopupFYI(player, "You transfered: "..amount.." gold to this player!")
    end
    return false
end
This code is working without errors in my OTS, if I find more bugs I will comment again. However, thanks for this script it is great!
 
Top