The args parameter in your function is a userdata that contains of everything written after the initial command.
So if someone writes "/cmd hello world this is domestos" the command is /cmd and args contains "hello world this is domestos" where every word is a different element is the userdata.
So the first element is args[0] which would be "hello", the second element is args[1] which would be "world" and so on.
And because in c# the index is starting with 0 and not 1 the total number of elements is length - 1.
Solved Using console args and commands? (Lua)
Discussion in 'Rust Development' started by LaserHydra, Mar 24, 2015.
-
kk
[DOUBLEPOST=1427658673,1427643756][/DOUBLEPOST]I think I just got it right, but well it seems like I dont.
There is the problem that whatever I am writing im always getting the Syntax Error.
I tried it with an example of message sending with a custom prefix and message.
Code:function PLUGIN:cmdMessage(player, cmd, args) if args.Lenght == -1 then -- or do I need "if args.Lenght == 1 then"? idk... I think my error is here... local Prefix = tostring(args[0]) local Message = tostring(args[1]) if player.net.connection.authLevel < self.Config.Authlevel then rust.SendChatMessage(player, "Messages", self.Config.NoPermission) else rust.BroadcastChat(Prefix, Message) end else rust.SendChatMessage(player, "Messages", "Syntax: /msg [Prefix] [Message]") end end
Just wanna know what I didn't understand yet... -
if args.Length == 2 then
................................ rest of your code -
Your mistake is in the line you think it is.
What do you wanna check to get into the if? -
well I didn't see that I failed at typing ^^
Ok now I think im sure with this case of args using...
Thanks again and sorry for my many questions :v