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

TFS 1.X+ TFS 1.3 onSay param broken...

Itutorial

Legendary OT User
Joined
Dec 23, 2014
Messages
2,334
Solutions
68
Reaction score
1,012
So I am making a banking code and I can't seem to use param at all...

Lua:
function onSay(player, words, param)
    if words == "!balance" then
        player:popupFYI("[Balance]: "..player:getBankBalance())
        return false
   
    elseif words == "!deposit" then
        if not param then
            player:sendCancelMessage("Usage: !deposit all / !deposit amount")
            return false
        end
       
        if param == "all" then
            local amount = player:getMoney()
           
            if not amount then
                player:sendCancelMessage("You do not have any gold to deposit.")
                return false
            end
           
            player:removeMoney(amount)
            local oldBalance = player:getBankBalance()
            player:setBankBalance(player:getBankBalance() + amount)
            player:popupFYI("[Old Balance]: "..oldBalance.."\n[New Balance]: "..player:getBankBalance())
            return false
        else
            local amount = tonumber(param)
           
            if amount < 0 or amount > 100000000 then
                player:sendCancelMessage("You can only deposit 1-100kk gold at a time.")
                return false
            end
           
            if not player:removeMoney(amount) then
                player:sendCancelMessage("You do not have that much gold.")
                return false
            end
           
            local oldBalance = player:getBankBalance()
            player:setBankBalance(player:getBankBalance() + amount)
            player:popupFYI("[Old Balance]: "..oldBalance.."\n[New Balance]: "..player:getBankBalance())
            return false
        end
       
       
       
       
    end
    return false
end

I can use !balance but I can't do !deposit all or !deposit 1000. I cant even print the param it is just empty....

in xml

XML:
<talkaction words="!balance" separator=" " script="banking.lua" />
    <talkaction words="!deposit" separator=" " script="banking.lua" />
    <talkaction words="!withdraw" separator=" " script="banking.lua" />
    <talkaction words="!transfer" separator=" " script="banking.lua" />
 
Last edited:
Solution
print("String:"..valueOne)
this will bring you error because you didn't concatenate it correctly, it needs another string value after to complete the concat... Like this

print("String: " ..valueOne.. "")

Anyways the problem with the logic is that you are first assuming that someone has included a parameter, but with the command !balance, there is no parameter needed! So that is the issue, logically, you want to first check if there is a param, then, from there you want to decide what is next for when it has a parameter, and when it doesn't , would be a good point to determing how many parameters right after you have determined there is a parameter, and/or the parameter type. I am working on an example to share back with you to...
This can be done simpler as I did in my script: local amount = math.abs(tonumber(param) or 0) < this will always return a positive, easy and bulletproof number
Lua:
 if param:find("-") then
                param = param:gsub("-", "")
            end
            amount = tonumber(param)
end

This check is wrong, use if amount <= 0 instead of if amount < 0, unless you want to transfer, withdraw or deposit 0 coins :D
Lua:
        if amount < 0 or amount > 100000000 then
Actually forgot to check the amount transfered too so its 1-100kk. updated
 
Last edited:
Back
Top