RemoveCommandHandler: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 11: Line 11:


===Required Arguments===  
===Required Arguments===  
*'''commandName:''' The string of the command you wish to remove
*'''commandName:''' The string of the command you wish to remove.


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


==Example==  
==Example==  
This example prevents using a 'nitro' command if you are in a caddy, otherwise it adds the command to allow you to use the nitro command.
This example adds a command handler that briefly shows the position of 'huntedPlayer', and removes the command handler when 'huntedPlayer' dies:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
addEventHandler ( "onPlayerEnterVehicle", root, "onPlayerEnterVehicle" )
-- add a command that allows players to see the position of the 'huntedPlayer' for 5 seconds:
function onPlayerEnterVehicle ( vehicle, seat, jacked )
addCommandHandler ( "showhuntedblip", "consoleShowHuntedBlip" )
    if vehicle == 457 then
function consoleShowHuntedBlip ( player, commandName )
        removeCommandHandler ( "nitro" )
  if ( player ) then
    else
      local x, y, z = getElementPosition ( huntedPlayer )
        addCommandHandler ( "nitro", "givenitro" )
      local blip = createBlip ( x, y, z, 0, 2, 255, 0, 0, 255, player )
    end
      setTimer ( "destroyElement", 5000, 1, blip )
  end
end
 
-- remove the command once the hunter player dies:
addEventHandler ( "onPlayerWasted", huntedPlayer, "onHuntedPlayerWasted" )
function onHuntedPlayerWasted ( ammo, killer, killerweapon, bodypart )
  removeCommandHandler ( "showhuntedblip" )
end
end
</syntaxhighlight>
</syntaxhighlight>

Revision as of 20:40, 8 October 2006

Dialog-information.png This article needs checking.

Reason(s): Problems in example. Erorr404
Dialog-information.png This article needs checking.

Reason(s): Well, I fixed the syntax issues, but its a bad example (why remove the command for everyone?). Can't think of another one though... eAi


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:
addCommandHandler ( "showhuntedblip", "consoleShowHuntedBlip" )
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

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

See Also