RemoveCommandHandler

From Multi Theft Auto: Wiki
Revision as of 16:58, 16 August 2007 by Arc (talk | contribs)
Jump to navigation Jump to search

This function removes a command handler, that is one that has been added using addCommandHandler. This function can only remove command handlers that were added by the virtual machine that it is called in.

Syntax

bool removeCommandHandler ( string commandName )              

Required Arguments

  • commandName: The string of the command you wish to remove.

Returns

Returns true if the command handler was removed successfully, false if the command doesn't exist.

Example

This example adds a command handler that briefly shows the position of 'huntedPlayer', and removes the command handler when 'huntedPlayer' dies:

-- add a command that allows players to see the position of the 'huntedPlayer' for 5 seconds:
function consoleShowHuntedBlip ( player, commandName )
    if ( player ) then
        local x, y, z = getElementPosition ( huntedPlayer )
        local blip = createBlip ( x, y, z, 0, 2, 255, 0, 0, 255, player )
        setTimer ( "destroyElement", 5000, 1, blip )
    end 
end
addCommandHandler ( "showhuntedblip", consoleShowHuntedBlip )

-- remove the command once the hunter player dies:
function onHuntedPlayerWasted ( ammo, killer, killerweapon, bodypart )
    removeCommandHandler ( "showhuntedblip" )
end
addEventHandler ( "onPlayerWasted", huntedPlayer, onHuntedPlayerWasted )

See Also