Jump to content

SAMP Bank System


Recommended Posts

Hi. I made a old time samp bank script, i got 1 little problem. 

The deposit command looks like this:

The problem is, when i just type /deposit, it show the syntax, but when i type something /deposit xdxd (Not number) then i get this debug error:

14: bad argument #1 to 'ceil'  (number expected, got string)

How can i make that, when player type something, return to syntax?

 

addCommandHandler("deposit",function(player,cmd,money)
   local money = tonumber(math.ceil(money)) -- line 14
    if not money then
        outputChatBox(syntax.." /"..cmd.." [Amount]",player,38,194,129,true)
    else
        if (money) <= 0 then
            outputChatBox(error.." Bigger hatn 0.",player,177,9,45,true)
        elseif exports["rc_core"]:getMoney(player) >= tonumber(money) then
            exports["rc_core"]:takeMoney(player,tonumber(money))
               giveBankMoney(player,money)
        else
        outputChatBox(error.." You cant afford that.",player,177,9,45,true)
        end
    end
end  
)

 

Link to comment

Try this:

addCommandHandler("deposit",function(player,cmd,money)
   local money = tonumber(math.ceil(money)) -- line 14
    if (not money) or (type(money) ~= "number") then
        outputChatBox(syntax.." /"..cmd.." [Amount]",player,38,194,129,true)
    else
        if (money) <= 0 then
            outputChatBox(error.." Bigger hatn 0.",player,177,9,45,true)
        elseif exports["rc_core"]:getMoney(player) >= tonumber(money) then
            exports["rc_core"]:takeMoney(player,tonumber(money))
               giveBankMoney(player,money)
        else
        outputChatBox(error.." You cant afford that.",player,177,9,45,true)
        end
    end
end  
)

 

Link to comment
  • Administrators
addCommandHandler("deposit",function(player,cmd,money)
   local money = math.ceil(tonumber(money)) -- line 14
    if not money then
        outputChatBox(syntax.." /"..cmd.." [Amount]",player,38,194,129,true)
    else
        if (money) <= 0 then
            outputChatBox(error.." Bigger hatn 0.",player,177,9,45,true)
        elseif exports["rc_core"]:getMoney(player) >= tonumber(money) then
            exports["rc_core"]:takeMoney(player,tonumber(money))
               giveBankMoney(player,money)
        else
        outputChatBox(error.." You cant afford that.",player,177,9,45,true)
        end
    end
end  
)

 

Link to comment
addCommandHandler("deposit", function(player, command, money)
if player and command and tonumber(money) then
local amount = math.ceil(tonumber(money))
if tonumber(amount) > 0 then
exports["rc_core"]:getMoney(player) >= amount then
exports["rc_core"]:takeMoney(player, amount)
giveBankMoney(player, amount)
else
outputChatBox("Not enough money to make this transaction.", player, 177, 9, 45, false)
end
else
outputChatBox("Syntax: /deposit amount", player, 177, 9, 45, false)
end
end)


Enjoy.

Made few changes to the rest of the lines, personally, I like to be very organized whilst making scripts so I'll be able to read them very well.
I added on the line to check if the player, command and the 'value' for 'money' exists, to continue. The 'value' for 'money' must be a number or it won't continue, fixing your 'number expected, got string' problem. Now it'll expect a number all the times.

Edited by SARSRPG
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...