Jump to content

onPlayerCommand event?


Recommended Posts

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
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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...