RemoveCommandHandler: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (VM -> resource)
No edit summary
Line 15: Line 15:


==Example==  
==Example==  
<section name="Server" class="server" show="true">
This example adds a command handler that briefly shows the position of 'huntedPlayer', and removes the command handler when 'huntedPlayer' dies:
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">
-- add a command that allows players to see the position of the 'huntedPlayer' for 5 seconds:
-- add a command that allows players to see the position of the 'huntedPlayer' for 5 seconds:
function consoleShowHuntedBlip ( thePlayer, commandName )
function consoleShowHuntedBlip ( thePlayer, commandName )
     if ( thePlayer ) then
     local x, y, z = getElementPosition ( huntedPlayer )
        local x, y, z = getElementPosition ( huntedPlayer )
    local huntedblip = createBlip ( x, y, z, 0, 2, 255, 0, 0, 255, thePlayer )
        local huntedblip = createBlip ( x, y, z, 0, 2, 255, 0, 0, 255, thePlayer )
    setTimer ( "destroyElement", 5000, 1, huntedblip )
        setTimer ( "destroyElement", 5000, 1, huntedblip )
    end
end
end
addCommandHandler ( "showhuntedblip", consoleShowHuntedBlip )
addCommandHandler ( "showhuntedblip", consoleShowHuntedBlip )
Line 33: Line 32:
addEventHandler ( "onPlayerWasted", huntedPlayer, onHuntedPlayerWasted )
addEventHandler ( "onPlayerWasted", huntedPlayer, onHuntedPlayerWasted )
</syntaxhighlight>
</syntaxhighlight>
</section>
<section name="Client" class="client" show="false">
This example adds a command handler that briefly shows the position of 'huntedPlayer', and removes the command handler when 'huntedPlayer' dies:
<syntaxhighlight lang="lua">
-- add a command that allows players to see the position of the 'huntedPlayer' for 5 seconds:
function consoleShowHuntedBlip ( commandName )
    local x, y, z = getElementPosition ( huntedPlayer )
    local huntedblip = createBlip ( x, y, z, 0, 2, 255, 0, 0, 255, thePlayer )
    setTimer ( "destroyElement", 5000, 1, huntedblip )
end
addCommandHandler ( "showhuntedblip", consoleShowHuntedBlip )


-- remove the command once the hunter player dies:
function onHuntedPlayerWasted ( killer, killerweapon, bodypart )
    removeCommandHandler ( "showhuntedblip" )
end
addEventHandler ( "onClientPlayerWasted", huntedPlayer, onHuntedPlayerWasted )
</syntaxhighlight>
</section>
==See Also==
==See Also==
{{Server_functions}}
{{Server_functions}}

Revision as of 15:39, 30 August 2007

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

Click to collapse [-]
Server

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 ( thePlayer, commandName )
    local x, y, z = getElementPosition ( huntedPlayer )
    local huntedblip = createBlip ( x, y, z, 0, 2, 255, 0, 0, 255, thePlayer )
    setTimer ( "destroyElement", 5000, 1, huntedblip )
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 )
Click to expand [+]
Client

See Also