ExecuteCommandHandler: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
No edit summary |
||
Line 21: | Line 21: | ||
This example defines a command handler for the command ''createmarker'' (This will create a red marker at the player who uses it's position). It then creates a second command handler ''createmarker2'' which will call the first one. | This example defines a command handler for the command ''createmarker'' (This will create a red marker at the player who uses it's position). It then creates a second command handler ''createmarker2'' which will call the first one. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
-- | -- Define the function that will handle the 'createmarker' command | ||
function consoleCreateMarker ( playerSource, commandName ) | function consoleCreateMarker ( playerSource, commandName ) | ||
-- If a player triggered it (rather than the admin) then | -- If a player triggered it (rather than the admin) then | ||
if ( playerSource ) | if ( playerSource ) | ||
-- Get that player's position | -- Get that player's position | ||
x, y, z = | x, y, z = getElementPosition ( playerSource ) | ||
-- Create a marker at their position | -- Create a marker at their position | ||
createMarker ( x, y, z, 0, "checkpoint", 255, 0, 0, 255 ) | createMarker ( x, y, z, 0, "checkpoint", 255, 0, 0, 255 ) | ||
Line 35: | Line 33: | ||
end | end | ||
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 ) | function consoleCreateMarker2 ( playerSource, commandName ) | ||
-- re-route back to the original | |||
executeCommandHandler ( "createmarker", playerSource ) | |||
end | end | ||
-- Then add it as a handler for the new console command | |||
addCommandHandler ( "createmarker2", consoleCreateMarker2 ) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
==See Also== | ==See Also== | ||
{{Server functions}} | {{Server functions}} |
Revision as of 12:24, 21 August 2007
This function will call all the attached functions of an existing console command, for a specified player.
Syntax
bool executeCommandHandler ( string commandName, player thePlayer, [ string args ] )
Required Arguments
- commandName: This is the name of the command you wish to execute. This is what must be typed into the console to trigger the function.
- thePlayer: This is the player that will be passed to the attached functions of the console command.
Optional Arguments
- args: Each word after command name in the original command is passed here in seperate variables. If there is no value for an argument, the variable will contain nil.
Returns
Returns true if the command handler was called successfully, false otherwise.
Example
This example defines a command handler for the command createmarker (This will create a red marker at the player who uses it'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
- getMaxPlayers
- getServerConfigSetting
- getServerHttpPort
- getServerName
- getServerPassword
- getServerPort
- isGlitchEnabled
- setGlitchEnabled
- setMaxPlayers
- setServerConfigSetting
- setServerPassword
- shutdown