Martyz Posted January 1, 2011 Posted January 1, 2011 Hi, i want to make a lotto command for ex.: /roll And how can I get is entered text in command is numbers or letters?
Aibo Posted January 1, 2011 Posted January 1, 2011 amount = tonumber(amount) if amount then -- ok else -- not ok end
Martyz Posted January 1, 2011 Author Posted January 1, 2011 (edited) Sorry for double posting. I've got this error: [2011-01-01 22:35:27] start: Requested by Console [2011-01-01 22:35:27] Starting race_martyz [2011-01-01 22:35:27] SCRIPT ERROR: race_martyz\commands.lua:37: 'end' expected (to close 'function' at line near 'else' [2011-01-01 22:35:27] WARNING: Loading script failed: race_martyz\commands.lua:37: 'end' expected (to close 'function' at line near 'else' [2011-01-01 22:35:27] start: Resource 'race_martyz' started code: function lotto_roll(player, amount) if tonumber(amount) then if(amount < 100) then outputChatBox("Minimum roll amount is 100$!", player, 255, 100, 0, false) return end if(amount > 1000) then outputChatBox("Maximum roll amount is 1000$!", player, 255, 100, 0, false) return end if(amount > getPlayerMoney(player)) then outputChatBox("You have less money than you entered!", player, 255, 100, 0, false) return end local rroll = math.random(0, 2) if(rroll == 0) then outputChatBox("You've spinned for " ..amount.. "$ and lost!", 255, 255, 0, false) takePlayerMoney(player, amount) end if(rroll == 0) then outputChatBox("You've spinned for " ..amount.. "$ and lost!", 255, 255, 0, false) takePlayerMoney(player, amount) end if(rroll == 1) then outputChatBox("You've spinned for " ..amount.. "$ and WON!", 255, 255, 0, false) givePlayerMoney(player, amount) end end else outputChatBox("It must be number!", player, 255, 100, 0, false) end end addCommandHandler("roll", lotto_roll) Edited January 1, 2011 by Guest
Aibo Posted January 1, 2011 Posted January 1, 2011 i've added indentation to your code, try to find your mistake yourself.
Martyz Posted January 1, 2011 Author Posted January 1, 2011 dude, I am scripting lua 3 days so no idea where is the problem and i can't see any indentation O_o
Martyz Posted January 1, 2011 Author Posted January 1, 2011 Now, whatever I am writing in /roll, it says "It must be number!"...
Aibo Posted January 1, 2011 Posted January 1, 2011 because 2nd argument in (server) command handler function is command name, which is a string. third (and the rest) are arguments. function lotto_roll(player, command, amount)
Martyz Posted January 1, 2011 Author Posted January 1, 2011 now if i write /roll , its okay, it shows "It must be number!", but when i type /roll , just no effect
Aibo Posted January 1, 2011 Posted January 1, 2011 maybe you have something missing, for example: a check if rroll is 2. and read about if/elseif in lua wiki, you dont have to «if then return» every time.
Martyz Posted January 2, 2011 Author Posted January 2, 2011 I know how to use else if from PAWN, just didn't think about it in lua ^^ I will try changing something to elseif and will write what's the result. EDIT: Problem were not in elseif, but I fixed it by my own, anyway thank you very much for helping.
Callum Posted January 2, 2011 Posted January 2, 2011 amount = tonumber(amount) if amount and type(amount) == "number" then -- ok else -- not ok end
Aibo Posted January 2, 2011 Posted January 2, 2011 amount = tonumber(amount) if amount and type(amount) == "number" then -- ok else -- not ok end tonumber() returns either number or nil, so i dont think type(amount) == "number" is necessary. unless i'm wrong ofc :3
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