itHyperoX Posted July 5, 2017 Share Posted July 5, 2017 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
koragg Posted July 5, 2017 Share Posted July 5, 2017 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
itHyperoX Posted July 5, 2017 Author Share Posted July 5, 2017 bad argument #1 to "ceil" (number expected, got string) Link to comment
Administrators Lpsd Posted July 5, 2017 Administrators Share Posted July 5, 2017 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
Infinity# Posted July 5, 2017 Share Posted July 5, 2017 (edited) 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 July 5, 2017 by SARSRPG Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now