SkrillexX Posted May 26, 2013 Share Posted May 26, 2013 Hi all. I am new on scripting but here's my question. the lua sytnax of "addCommandHandler" is : addCommandHandler ("CommandName", CommandFunction ) in this case the player will type /commandName but i'd like to make a command where the player must do for exemple /spectate playerName i mean the command will have two parts . i'd like to know how i do that. Link to comment
denny199 Posted May 26, 2013 Share Posted May 26, 2013 (edited) As you can see on the wiki under "Handler function parameters" : player playerSource, string commandName, [string arg1, string arg2, ...] So: addCommandHandler ( "spectate", function (player, cmd, playername ) -- your code end) So you can excecute "playername" as the text what you have typed in game like: "/spectate [DenR]Danny" So now 'playername' will return "[DenR]Danny" if the argument isn't specifided it will return "nil" So you actually need to chek that argument: addCommandHandler ( "spectate", function (player, cmd, playername ) if ( playername ) then outputChatBox ( playername ) end end) edit: You want to spectate the player I guess, then these functions might help you: setCameraTarget getPlayerFromName Maybe some usefull functions that might help you to improve your code: https://wiki.multitheftauto.com/wiki/Get ... omNamePart Edited May 26, 2013 by Guest Link to comment
SkrillexX Posted May 26, 2013 Author Share Posted May 26, 2013 I didn't really get it but thanks anyways. Link to comment
denny199 Posted May 26, 2013 Share Posted May 26, 2013 Well, I'll explain it better: function specPlayer( player, cmd, typedArgument ) --player = the player who typed the command --cmd = the command name --typedArgument is a argument what you can pass with commandHandler end -- adding a end to close the function addCommandHandler ( "spectate", specPlayer ) When the player now typs: "/spectate danny" it will returnt typedArgument, because see here: https://wiki.multitheftauto.com/wiki/AddCommandHandler scroll down to "Handler function parameters" Link to comment
SkrillexX Posted May 26, 2013 Author Share Posted May 26, 2013 Thanks . it really helped. 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