Jump to content

onPlayerCommand event?


Recommended Posts

Posted

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)

Posted

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)

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

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

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