UnbindKey: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 21: Line 21:
Note: If you do not specify a ''keyState'' or ''handler'', any instances of ''key'' being bound will be unbound, whatever function they are bound to.
Note: If you do not specify a ''keyState'' or ''handler'', any instances of ''key'' being bound will be unbound, whatever function they are bound to.
</section>
</section>
<section name="Server" class="server" show="false">
<section name="Client" class="client" show="false">
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
unbindKey ( string key, [ string keyState, function handler ] )
unbindKey ( string key, [ string keyState, function handler ] )

Revision as of 19:36, 29 August 2007

Removes an existing key bind from the specified player.

Syntax

Click to collapse [-]
Server
unbindKey ( player thePlayer, string key, [ string keyState, function handler ] )

Required Arguments

  • thePlayer: The player you wish to unbind the key of.
  • key: The key you wish to unbind. See Key names for a list of valid key names.

Optional Arguments

  • keyState: Can be either:
    • "up": If the bound key triggered a function when the key was released
    • "down": If the bound key triggered a function when the key was pressed
    • "both": If the bound key triggered a function when the key was pressed and released
  • handler: The function you wish to unbind.

Note: If you do not specify a keyState or handler, any instances of key being bound will be unbound, whatever function they are bound to.

Click to expand [+]
Client

Example

Click to collapse [-]
Server

This function binds the player's F1 key to a function goMoo which outputs a chat message when pressed. The key is then unbound so that it can effectively only be used once per life.

-- define the function that will be called when F1 is pressed
function goMoo( source )
    outputChatBox ( getClientName ( source ) .. " says Mooooooo!" )
    unbindKey ( source, "F1", "down", goMoo )   -- this function will no longer be triggered by the player, after removing the bind.
end

function playerSpawn ( )
    bindKey ( source, "F1", "down", "Go moo", goMoo ) -- bind the player's F1 key to the 'goMoo' function defined above
end
addEventHandler ( "onPlayerSpawn", getRootElement(), playerSpawn ) -- make the playerSpawn function be called when a player spawns

See Also