ziomal432 Posted July 3, 2010 Share Posted July 3, 2010 How to do a loop for all command names? Something like this [example]: [100% will not work] function OnPlayerCommand(cmdname) for key, singleElement in pairs (Teleports) do if(tostring(cmdname) == Teleports[singleElements][1]) then setElementPos(source, Teleports[singleElements][2], Teleports[singleElements][3], Teleports[singleElements][4]) -- ...... end end end addEventHandler("onPlayerCommand", getRootElement(), OnPlayerCommand) Link to comment
dzek (varez) Posted July 3, 2010 Share Posted July 3, 2010 download my "tele" script from community.multitheftauto.com - my script is doing what you want i think, and you will see better way than looping through whole table (assigning string keys to tables) Link to comment
ziomal432 Posted July 3, 2010 Author Share Posted July 3, 2010 But is there any way to make it without /tele prefix? Link to comment
50p Posted July 3, 2010 Share Posted July 3, 2010 But is there any way to make it without /tele prefix? What do you want? There is no onPlayerCommand event to catch the command player typed in. You can only use addCommandHandler. You can make a table of commands and add their handlers, like so: teleCmds = { [ "abc" ] = { 123.2122, 123.3342, 124.3435 }, [ "def" ] = { 243.3432, 2345.234, 30.3452 }, [ "ghi" ] = { 2134.1234, 2452.0934, 22.23 }, } function addCommands( ) for cmd in ipairs( teleCmds ) do addCommandHandler( cmd, someFunc ) end end function someFunc( plr, cmd ) -- you can loop your table here again for tcmd in pairs( teleCmds ) do if tcmd == cmd then setElementPosition( plr, teleCmds[ tcmd ][ 1 ], teleCmds[ tcmd ][ 2 ], teleCmds[ tcmd ][ 3 ] ); end end end I may have made a mistake here but that's the idea you're looking for I think... Although, it's easier to make separate function for different teleport and even faster then a loop. Link to comment
ziomal432 Posted July 3, 2010 Author Share Posted July 3, 2010 I noticed this way little bit before your post, but the code didn't worked. Thanks for your example. Problem is solved. 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