fairyoggy Posted June 14, 2021 Posted June 14, 2021 (edited) -- var 1 function paymoney(player,cmd, ...) for i, v in ipairs(getElementsByType("player")) do if #({...}) == 0 then outputChatBox ("Empty Message",v,255,255,255,false) else --if amount == nil then --outputChatBox ("Type Amount",v,255,255,255,false) --else -- --end end end end addCommandHandler("pay",paymoney) -- var 2 function paymoney(player,cmd, amount) for i, v in ipairs(getElementsByType("player")) do if amount == nil then outputChatBox ("Type Amount",v,255,255,255,false) else -- end end end addCommandHandler("pay",paymoney) In the first option, a check is made for an empty message, Example: player type in chat /pay and appears error message "empy message" but if player type /pay 1 it's fine In the second option, a check is made for an empty amount, example: /pay and appears error message "type amount" but if player type /pay 1 it's fine So... How to combine this into one function? I mean if the player type in chat /pay 1 1 it's ok but if player type /pay - error message "empy message" , if player type /pay 1 - error message "type amount" , if player type /pay 1 1 it's fine I am having difficulty with the string: function paymoney(player,cmd, ...) Need something like this: function paymoney(player,cmd, ... , amount) but i cant use code like this: Error: Loading script, ")" expected near ',' Edited June 14, 2021 by oggygod
Bonsai Posted June 14, 2021 Posted June 14, 2021 I think the "..." is already a table containing all the arguments seperated by space. So you don't need an addional parameter for the amount.
SpecT Posted June 14, 2021 Posted June 14, 2021 I don't think you need the "..." since you will have only 2 arguments. You will need the "..." in case you are sending a message (i.e. PMs). Also why would you send the error message to all the players in the server ? Isn't it supposed to be only for the player who used the command ? I don't get exactly what your idea is tho but this might be useful to you: function paymoney(player,cmd, arg1, arg2) if not arg1 and not arg2 then outputChatBox ("Wrong command syntax. Example: /pay 1 1",player,255,255,255,false) return end if not arg2 then outputChatBox ("No ammount specified. Example: /pay 1 1",player,255,255,255,false) return end -- your stuff here end addCommandHandler("pay",paymoney) 1
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