• 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

Excellent OT User
Joined
Dec 23, 2014
Messages
2,307
Solutions
68
Reaction score
981
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...
Are you using a "," for seperating the words from the param? That is what is needed I believe. As for toNumber() it most definitely works, if you don't believe me try the talkaction !z or !x as they use the function toNumber() to make sure the param is a number data type..

I literally just released a big mod that heavily relies on toNumber() and works perfectly here

I'm pretty certain the issue is you aren't using the comma to seperate the words from param. Also, most people use param:lower() to turn the words into all lowercase as to make certain it matches your string like "all". I even see you used spaces as the "seperator" which I wouldn't recommend, yeah I guess some people have made it work, but seeing as you are running into the current issue you are having, just use the comma and then print(param) and you should get something instead of nothing next time.
 
Its really not making any sense. I have never had this issue before. I even tried my old banking codes which worked before and they don't now which were TFS 1.2 and didn't use anything not used now. The only time I can even get it to register like im using the !deposit talkaction is when I take the separator away. Then I type !deposit 1000 and i get an error:

data/talkactions/scripts/banking.lua:36: attempt to compare nil with number

Which is this line

Lua:
local amount = tonumber(param)

and that comes after this line of code so it really doesn't make sense.

Lua:
if not param then
            player:sendCancelMessage("Usage: !deposit all / !deposit amount")
            return false
        end

In my !x and !z files it also has the tonumber and it works fine. So that tells me the issue is with the param itself. I printed the param and it prints nothing when that error above occurs.

So switching it to revscript I was able to produce the following results:
1) !balance works
2) !deposit with no param works. It send a message "Usage: !deposit all / !deposit amount"

I cannot get it to continue past that no matter what I do. It seems like param is just not being set when there is something there.

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" then
        if param == "" then
            player:sendCancelMessage("Usage: !deposit all / !deposit amount")
            return false
        elseif param then
            print("Code Next")
           
            local amount = nil
            if param:lower() == "all" then
                amount = player:getMoney()
            else
                if tonumber(param) > 0 or tonumber(param) < 100000000 then
                    amount = tonumber(param)
                else
                    player:sendCancelMessage("You can only deposit between 1 and 100kk gold.")
                    return false
                end
            end
           
            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
        end
    end
    return false
end

banking:separator(",")
banking:register()
 
Last edited:
I was able to get the param to print after doing a split at the beginning of the code. As soon as It gets to the part of code that uses it though there are issues. This is the basic code.

Lua:
local banking = TalkAction("!balance","!deposit","!withdraw","!transfer")

function banking.onSay(player, words, param)
    local t = param:split(",")
    local valueOne = t[1]
    local valueTwo = t[2]
    print("String:"..valueOne) -- Does print (only if valueTwo is set also) --

    if words == "!balance" then
        player:popupFYI("[Balance]: "..player:getBankBalance())
        return false
   
    elseif words == "!deposit" then
        print("String:"..valueOne) -- No print --
        if valueOne and valueOne == "" then
            player:sendCancelMessage("Usage: !deposit all / !deposit amount")
            return false
        else -- !deposit all / !deposit 1000  Should trigger this. It does not. --
            player:getPosition():sendMagicEffect(10)
        end
    end
    return false
end

banking:separator(" ")
banking:register()
 
I can see if I can tinker with it when I get home, but I just got to work so it could be about 8-10 hrs, I did notice people use split alot on talkactions, can you tell me what did it print when you printed?
 
!deposit 123 -- Nothing prints
!deposit 123, 123 -- ValueOne will be printed and valueTwo if specified to print
!deposit all -- Nothing prints
Post automatically merged:

This is the c++ code which was changed when revscripts were introduced.

C++:
TalkActionResult_t TalkActions::playerSaySpell(Player* player, SpeakClasses type, const std::string& words) const
{
    size_t wordsLength = words.length();
    for (auto it = talkActions.begin(); it != talkActions.end(); ) {
        const std::string& talkactionWords = it->first;
        size_t talkactionLength = talkactionWords.length();
        if (wordsLength < talkactionLength || strncasecmp(words.c_str(), talkactionWords.c_str(), talkactionLength) != 0) {
            ++it;
            continue;
        }

        std::string param;
        if (wordsLength != talkactionLength) {
            param = words.substr(talkactionLength);
            if (param.front() != ' ') {
                ++it;
                continue;
            }
            trim_left(param, ' ');

            std::string separator = it->second.getSeparator();
            if (separator != " ") {
                if (!param.empty()) {
                    if (param != separator) {
                        ++it;
                        continue;
                    } else {
                        param.erase(param.begin());
                    }
                }
            }
        }

        if (it->second.fromLua) {
            if (it->second.getNeedAccess() && !player->getGroup()->access) {
                return TALKACTION_CONTINUE;
            }

            if (player->getAccountType() < it->second.getRequiredAccountType()) {
                return TALKACTION_CONTINUE;
            }
        }

        if (it->second.executeSay(player, words, param, type)) {
            return TALKACTION_CONTINUE;
        } else {
            return TALKACTION_BREAK;
        }
    }
    return TALKACTION_CONTINUE;
}
 
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 help get you back on the right track to finish the script the way you want it.
Post automatically merged:

Second thoughts while tinkering, I discovered, words is not properly matching with !balance, i will keep experimenting, drawing from other examples
Post automatically merged:

Ok so I don't know why words won't properly match, but it seems if the words are spoken at all, then the logic is always called, however, again I can't seem to get the words to properly match, so the easiest fix for me was to seperate the commands and logic, anyways, all the prints work flawlessly and when expected, and when the value is a number, don't forget to make sure to create a new variable like local arg = tonumber(param) or else always use tonumber for everytime you want to use the number value. Here is the basic template to do what you wanted to do, you will find all the logic is being called when you expect and can be controlled quite easily from here.


Lua:
local balanceCheck = TalkAction("!balance","!bal")

function balanceCheck.onSay(player, words, param)
    player:popupFYI("[Balance]: "..player:getBankBalance())
    return true
end
balanceCheck:register()

local depositMoney = TalkAction("!deposit")

function depositMoney.onSay(player, words, param)
    if param == "" then
        player:sendCancelMessage("Usage: !deposit all / !deposit amount")
        return false
    end
    if param == "all" then
        print("it found all param")
    end
    if tonumber(param) ~= nil then
        print("it found the number and the value is " ..param.. "")
    end
end
depositMoney:separator(" ")
depositMoney:register()

local withdrawMoney = TalkAction("!withdraw")

function withdrawMoney.onSay(player, words, param)
    if param == "" then
        player:sendCancelMessage("Usage: !withdraw all / !withdraw amount")
        return false
    end
    if param == "all" then
        print("it found all param")
    end
    if tonumber(param) ~= nil then
        print("it found the number and the value is " ..param.. "")
    end
end
withdrawMoney:separator(" ")
withdrawMoney:register()

local transferMoney = TalkAction("!transfer")

function transferMoney.onSay(player, words, param)
    if param == "" then
        player:sendCancelMessage("Usage: !transfer all / !transfer amount")
        return false
    end
    if param == "all" then
        print("it found all param")
    end
    if tonumber(param) ~= nil then
        print("it found the number and the value is " ..param.. "")
    end
end
transferMoney:separator(" ")
transferMoney:register()

Hope that helps get you where you were trying to go, and have a bit different perspective on controlling the flow of info, but yeah the big problem you ran into is that words doesn't match exactly like words = "!balance" even though you can print(words) and get !balance... weird, trimming didn't help with it either....
 
Last edited:
Solution
Seems like something is wrong no? I have done this code atleast 5 times in the past. Making it better each time as my knowledge with coding improved. It seriously seems like there is an issue with the c++ code but that too looks fine to my eye.
 
Seems like something is wrong no? I have done this code atleast 5 times in the past. Making it better each time as my knowledge with coding improved. It seriously seems like there is an issue with the c++ code but that too looks fine to my eye.
Nah, you posted too soon, if there is anything wrong its just the words not matching like I said, but the above example I shared, works flawlessly, try it out and let me know what you think :D
 
I was able to get the param to print after doing a split at the beginning of the code. As soon as It gets to the part of code that uses it though there are issues. This is the basic code.

Lua:
local banking = TalkAction("!balance","!deposit","!withdraw","!transfer")

function banking.onSay(player, words, param)
    local t = param:split(",")
    local valueOne = t[1]
    local valueTwo = t[2]
    print("String:"..valueOne) -- Does print (only if valueTwo is set also) --

    if words == "!balance" then
        player:popupFYI("[Balance]: "..player:getBankBalance())
        return false
  
    elseif words == "!deposit" then
        print("String:"..valueOne) -- No print --
        if valueOne and valueOne == "" then
            player:sendCancelMessage("Usage: !deposit all / !deposit amount")
            return false
        else -- !deposit all / !deposit 1000  Should trigger this. It does not. --
            player:getPosition():sendMagicEffect(10)
        end
    end
    return false
end

banking:separator(" ")
banking:register()
When you try to print some value not valid or that this same is outsidethe stack, it is considered LUA_TNONE which is not the same as LUA_TNIL
However this is not your case, my guess is that you forgot to recharge correctly and are a bit confused ;)
 
I will try your way doing multiple interfaces but I have never had to do that before. That's the only things that is kind of bugging me. As I said I have even tried using an old code that I know worked previous the revscript change. So there is something wrong with this now if you think it should work as it did before. Thanks for the help.
 
I will try your way doing multiple interfaces but I have never had to do that before. That's the only things that is kind of bugging me. As I said I have even tried using an old code that I know worked previous the revscript change. So there is something wrong with this now if you think it should work as it did before. Thanks for the help.
You are welcome!

I can't speak for scripts working before or after, but I know for sure that the problem is with the words parameter, even though it prints what you expect, it doesn't match what you expect.

If my post for the workaround is something you will use as the base for rewriting your desired script, please mark as solution and change thread to solved.
 
I just checked that if it is a problem with the sources, I just thought you were referring to param but no to the words, this parameter returns the entire string of what you wrote, however I do not see much sense to this, I will open a PR to fix this in the sources, in a moment I will compile it and test it, so thanks for realizing this and sorry for my answer

FIX PR: [TalkAction.onSay] Fix pass the correct parameter by MillhioreBT · Pull Request #3518 · otland/forgottenserver (https://github.com/otland/forgottenserver/pull/3518/files)

~Here's a crappy example of what you wanted to do, good luck~ ;)
Now it's okay :D
Lua:
local talk = TalkAction("!balance", "!deposit", "!withdraw", "!transfer")

function talk.onSay(player, words, param, type)
    if words == "!balance" then
        player:popupFYI(string.format("[Balance]: %d", player:getBankBalance()))
        return false
    elseif words == "!deposit" then
        if param == "" then
            player:sendCancelMessage("Usage: !deposit all / !deposit amount")
            return false
        elseif param == "all" then
            local amount = player:getMoney()
            if amount == 0 then
                player:sendCancelMessage("You do not have any gold to deposit.")
                return false
            end

            player:removeMoney(amount)
            local oldBalance = player:getBankBalance()
            player:setBankBalance(oldBalance + amount)
            player:popupFYI(string.format("[Old Balance]: %d\n[New Balance]: %d", oldBalance, player:getBankBalance()))
            return false
        else
            local amount = math.abs(tonumber(param) or 0)
            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(oldBalance + amount)
            player:popupFYI(string.format("[Old Balance]: %d\n[New Balance]: %d", oldBalance, player:getBankBalance()))
            return false
        end
    elseif words == "!withdraw" then
        if param == "" then
            player:sendCancelMessage("Usage: !withdraw all / !withdraw amount")
            return false
        elseif param == "all" then
            local bankBalance = player:getBankBalance()
            if bankBalance == 0 then
                player:sendCancelMessage("You do not have any gold to withdraw.")
                return false
            end

            player:addMoney(bankBalance)
            player:setBankBalance(0)
            player:popupFYI(string.format("[Old Balance]: %d\n[New Balance]: 0", bankBalance))
            return false
        else
            local amount = math.abs(tonumber(param) or 0)
            if amount <= 0 or amount > 100000000 then
                player:sendCancelMessage("You can only withdraw 1-100kk gold at a time.")
                return false
            end

            local bankBalance = player:getBankBalance()
            if bankBalance < amount then
                player:sendCancelMessage("You do not have that much gold.")
                return false
            end

            player:addMoney(amount)
            player:setBankBalance(bankBalance - amount)
            player:popupFYI(string.format("[Old Balance]: %d\n[New Balance]: %d", bankBalance, player:getBankBalance()))
            return false
        end
    elseif words == "!transfer" then
        if param == "" then
            player:sendCancelMessage("Usage: !transfer name,all / !transfer name,amount")
            return false
        end

        local name, amount = unpack(param:split(","))
        local target = Player(name)
        if not target then
            player:sendCancelMessage("Player not online!")
            return false
        elseif target == player then
            player:sendCancelMessage("JAjajajaja!")
            return false
        end

        if amount == "all" then
            local bankBalance = player:getBankBalance()
            if bankBalance == 0 then
                player:sendCancelMessage("You do not have any gold to withdraw.")
                return false
            end

            local oldBalance = target:getBankBalance()
            target:setBankBalance(oldBalance + bankBalance)
            player:setBankBalance(0)
            player:popupFYI(string.format("[Old Balance]: %d\n[New Balance]: 0", bankBalance))
            target:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, string.format("[Old Balance]: %d\n[New Balance]: %d", oldBalance, target:getBankBalance()))
            return false
        else
            amount = math.abs(tonumber(param) or 0)
            if amount <= 0 or amount > 100000000 then
                player:sendCancelMessage("You can only transfer 1-100kk gold at a time.")
                return false
            end

            local bankBalance = player:getBankBalance()
            if bankBalance < amount then
                player:sendCancelMessage("You do not have that much gold.")
                return false
            end

            local oldBalance = target:getBankBalance()
            player:setBankBalance(bankBalance - amount)
            target:setBankBalance(oldBalance + amount)
            player:popupFYI(string.format("[Old Balance]: %d\n[New Balance]: %d", bankBalance, player:getBankBalance()))
            target:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, string.format("[Old Balance]: %d\n[New Balance]: %d", oldBalance, target:getBankBalance()))
            return false
        end
    end
    return false
end

talk:separator(" ")
talk:register()
 
Last edited:
For anyone that wants to see the result.

Lua:
local balanceCheck = TalkAction("!balance","!bal")
function balanceCheck.onSay(player, words, param)
    player:popupFYI("[Balance]: "..player:getBankBalance())
    return true
end
balanceCheck:register()

local depositMoney = TalkAction("!deposit")
function depositMoney.onSay(player, words, param)
    if param == "" then
        player:sendCancelMessage("Usage: !deposit all / !deposit amount")
        return false
    end
    
    local amount = nil
    
    if param == "all" then
        amount = player:getMoney()
    elseif tonumber(param) ~= nil then
        if param:find("-") then
            param = param:gsub("-", "")
        end
        amount = tonumber(param)
    end
    
    if amount < 0 or amount > 100000000 then
        player:sendCancelMessage("You can only deposit 1-100kk gold.")
        return false
    end
    
    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
    return false
end
depositMoney:separator(" ")
depositMoney:register()

local withdrawMoney = TalkAction("!withdraw")
function withdrawMoney.onSay(player, words, param)
    if param == "" then
        player:sendCancelMessage("Usage: !withdraw all / !withdraw amount")
        return false
    end
    
    if tonumber(param) ~= nil then
        if param:find("-") then
            param = param:gsub("-", "")
        end
        
        local amount = tonumber(param)
        
        if player:getBankBalance() < amount then
            player:sendCancelMessage("You do not have that much gold in your bank.")
            return false
        end
        
        player:setBankBalance(player:getBankBalance() - amount)
        player:addMoney(amount)
        local oldBalance = player:getBankBalance()
        player:popupFYI("[Old Balance]: "..oldBalance.."\n[New Balance]: "..player:getBankBalance().."\n\n[Withdraw]: "..amount)
    end
end
withdrawMoney:separator(" ")
withdrawMoney:register()

local transferMoney = TalkAction("!transfer")
function transferMoney.onSay(player, words, param)
    if param == "" then
        player:sendCancelMessage("Usage: !transfer all / !transfer amount")
        return false
    end
    
    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 amount:find("-") then
        amount = amount:gsub("-", "")
    end
    
    if tonumber(amount) == nil then
        player:sendCancelMessage("Usage: !transfer player, amount")
        return false
    end
    
    target = Player(target)
    amount = tonumber(amount)
    
    if not target then
        player:sendCancelMessage("Player must be online to transfer gold.")
        return false
    end
    
    if target:getName() == player:getName() then
        player:sendCancelMessage("Why even try.")
        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:setBankBalance(player:getBankBalance() - amount)
    target:setBankBalance(target:getBankBalance() + amount)
    player:popupFYI("[Old Balance]: "..oldBalance.."\n[New Balance]: "..player:getBankBalance().."\n\n[Transfer]: "..amount)
    return false
end
transferMoney:separator(" ")
transferMoney:register()
Post automatically merged:

I will try your way doing multiple interfaces but I have never had to do that before. That's the only things that is kind of bugging me. As I said I have even tried using an old code that I know worked previous the revscript change. So there is something wrong with this now if you think it should work as it did before. Thanks for the help.
Thank you again codina. Its not as pretty as I want but it will work for now.
Post automatically merged:

I just checked that if it is a problem with the sources, I just thought you were referring to param but no to the words, this parameter returns the entire string of what you wrote, however I do not see much sense to this, I will open a PR to fix this in the sources, in a moment I will compile it and test it, so thanks for realizing this and sorry for my answer

FIX PR: [TalkAction.onSay] Fix pass the correct parameter by MillhioreBT · Pull Request #3518 · otland/forgottenserver (https://github.com/otland/forgottenserver/pull/3518/files)

Here's a crappy example of what you wanted to do, good luck ;)
Lua:
local talk = TalkAction("!balance", "!deposit", "!withdraw", "!transfer")

function talk.onSay(player, words, param, type)
    if words == "!balance" then
        player:popupFYI(string.format("[Balance]: %d", player:getBankBalance()))
        return false
    elseif words == "!deposit" then
        if param == "" then
            player:sendCancelMessage("Usage: !deposit all / !deposit amount")
            return false
        elseif param == "all" then
            local amount = player:getMoney()
            if amount == 0 then
                player:sendCancelMessage("You do not have any gold to deposit.")
                return false
            end

            player:removeMoney(amount)
            local oldBalance = player:getBankBalance()
            player:setBankBalance(oldBalance + amount)
            player:popupFYI(string.format("[Old Balance]: %d\n[New Balance]: %d", oldBalance, player:getBankBalance()))
            return false
        else
            local amount = tonumber(param)
            if not amount or (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(oldBalance + amount)
            player:popupFYI(string.format("[Old Balance]: %d\n[New Balance]: %d", oldBalance, player:getBankBalance()))
            return false
        end
    elseif words == "!withdraw" then
        if param == "" then
            player:sendCancelMessage("Usage: !withdraw all / !withdraw amount")
            return false
        elseif param == "all" then
            local bankBalance = player:getBankBalance()
            if bankBalance == 0 then
                player:sendCancelMessage("You do not have any gold to withdraw.")
                return false
            end

            player:addMoney(bankBalance)
            player:setBankBalance(0)
            player:popupFYI(string.format("[Old Balance]: %d\n[New Balance]: 0", bankBalance))
            return false
        else
            local amount = tonumber(param)
            if not amount or (amount < 0 or amount > 100000000) then
                player:sendCancelMessage("You can only withdraw 1-100kk gold at a time.")
                return false
            end

            local bankBalance = player:getBankBalance()
            if bankBalance < amount then
                player:sendCancelMessage("You do not have that much gold.")
                return false
            end

            player:addMoney(amount)
            player:setBankBalance(bankBalance - amount)
            player:popupFYI(string.format("[Old Balance]: %d\n[New Balance]: %d", bankBalance, player:getBankBalance()))
            return false
        end
    elseif words == "!transfer" then
        if param == "" then
            player:sendCancelMessage("Usage: !transfer name,all / !transfer name,amount")
            return false
        end

        local name, amount = unpack(param:split(","))
        local target = Player(name)
        if not target then
            player:sendCancelMessage("Player not online!")
            return false
        elseif target == player then
            player:sendCancelMessage("JAjajajaja!")
            return false
        end

        if amount == "all" then
            local bankBalance = player:getBankBalance()
            if bankBalance == 0 then
                player:sendCancelMessage("You do not have any gold to withdraw.")
                return false
            end

            player:addMoney(bankBalance)
            player:setBankBalance(0)
            player:popupFYI(string.format("[Old Balance]: %d\n[New Balance]: 0", bankBalance))
            return false
        else
            amount = tonumber(param)
            if not amount or (amount < 0 or amount > 100000000) then
                player:sendCancelMessage("You can only transfer 1-100kk gold at a time.")
                return false
            end

            local bankBalance = player:getBankBalance()
            if bankBalance < amount then
                player:sendCancelMessage("You do not have that much gold.")
                return false
            end

            local oldBalance = target:getBankBalance()
            player:setBankBalance(bankBalance - amount)
            target:setBankBalance(oldBalance + amount)
            player:popupFYI(string.format("[Old Balance]: %d\n[New Balance]: %d", bankBalance, player:getBankBalance()))
            target:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, string.format("[Old Balance]: %d\n[New Balance]: %d", oldBalance, target:getBankBalance()))
            return false
        end
    end
    return false
end

talk:separator(" ")
talk:register()
Crappy example indeed, but still thank you. Remember, TFS isn't perfect and sometimes there is actually problems (even if they aren't problems with the code being broken, and its just that the system changed a bit and broke backwards capability or something). You are a lot better at this than I am but when I know something I know it. I messed with that talkaction for like 2 hours before coming here, sadly, just because I was zoned in on what used to work but doesn't now.
 
Last edited:
Crappy example indeed, but still thank you. Remember, TFS isn't perfect and sometimes there is actually problems (even if they aren't problems with the code being broken, and its just that the system changed a bit and broke backwards capability or something). You are a lot better at this than I am but when I know something I know it. I messed with that talkaction for like 2 hours before coming here, sadly, just because I was zoned in on what used to work but doesn't now.
Nobody has said that TFS is perfect and that it is the best in the world XD
If it is still in development, it is because there is a long way to go

But I'm glad to know that your problem was solved using 4 separate events, what matters is that it work!
 
Last message

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()
 
Last edited:
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
 
Back
Top