ExecuteCommandHandler: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 9: Line 9:
==Required Arguments==
==Required Arguments==
*'''commandName:''' The name of the command you wish to execute. This is what must be typed into the console to trigger the function.
*'''commandName:''' The name of the command you wish to execute. This is what must be typed into the console to trigger the function.
*'''thePlayer:''' The player that will be presented as executer of the command to the handler function(s) of the command
*'''thePlayer:''' The player that will be presented as executer of the command to the handler function(s) of the command.


==Optional Arguments==
==Optional Arguments==
{{OptionalArg}}
{{OptionalArg}}
* '''args:''' Additional parameters that will be passed to the handler function(s) of the command that is called.
* '''args:''' Additional parameters that will be passed to the handler function(s) of the command that is called, separated by a space.
</section>
</section>
<section name="Client" class="client" show="true">
<section name="Client" class="client" show="true">
Line 23: Line 23:
==Optional Arguments==
==Optional Arguments==
{{OptionalArg}}
{{OptionalArg}}
* '''args:''' Additional parameters that will be passed to the handler function(s) of the command that is called.
* '''args:''' Additional parameters that will be passed to the handler function(s) of the command that is called, separated by a space.
</section>
</section>
===Returns===
===Returns===

Revision as of 16:16, 31 May 2010

This function will call all the attached functions of an existing console command, for a specified player.

Syntax

Click to collapse [-]
Server
bool executeCommandHandler ( string commandName, player thePlayer, [ string args ] )

Required Arguments

  • commandName: The name of the command you wish to execute. This is what must be typed into the console to trigger the function.
  • thePlayer: The player that will be presented as executer of the command to the handler function(s) of the command.

Optional Arguments

NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use. For more information on optional arguments, see optional arguments.

  • args: Additional parameters that will be passed to the handler function(s) of the command that is called, separated by a space.
Click to collapse [-]
Client
bool executeCommandHandler ( string commandName, [ string args ] )

Required Arguments

  • commandName: The name of the command you wish to execute. This is what must be typed into the console to trigger the function.

Optional Arguments

NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use. For more information on optional arguments, see optional arguments.

  • args: Additional parameters that will be passed to the handler function(s) of the command that is called, separated by a space.

Returns

Returns true if the command handler was called successfully, false otherwise.

Example

Click to collapse [-]
Server

This example defines a command handler for the command createmarker (which creates a red marker at the caller's position). It then creates a second command handler createmarker2 which will call the first one.

-- Define the function that will handle the 'createmarker' command
function consoleCreateMarker ( playerSource, commandName )
	-- If a player triggered it (rather than the admin) then
	if ( playerSource )
		-- Get that player's position
		x, y, z = getElementPosition ( playerSource )
		-- Create a marker at their position
		createMarker ( x, y, z, 0, "checkpoint", 255, 0, 0, 255 )
		-- Output it in the chat box
		outputChatBox ( "You got a red marker", playerSource )
	end
end
-- Add the function as a handler for the command
addCommandHandler ( "createmarker", consoleCreateMarker )

-- Define a second console command that will just call the first.
-- First define the function
function consoleCreateMarker2 ( playerSource, commandName )
	-- re-route back to the original
	executeCommandHandler ( "createmarker", playerSource )
end
-- Then add it as a handler for the new console command
addCommandHandler ( "createmarker2", consoleCreateMarker2 )

See Also