UnbindKey: Difference between revisions

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


==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">unbindKey ( player thePlayer, string key, [ bool keyState, string function ] ) </syntaxhighlight>  
<syntaxhighlight lang="lua">unbindKey ( player thePlayer, string key, [ string keyState, string function ] ) </syntaxhighlight>  


===Required Arguments===  
===Required Arguments===  
Line 10: Line 10:


===Optional Arguments===
===Optional Arguments===
*'''keyState:''' A boolean value representing the "hit-state" of the key.
*'''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
*'''function:''' The function you wish to unbind.
*'''function:''' The function you wish to unbind.
Note: The function will only compare values specified, eg: you could bind 1 key to 2 functions and remove them both by not specifying a function.
Note: If you do not specify a ''keyState'' or ''function'', any instances of ''key'' being bound will be unbound, whatever function they are bound to.


==Example==   
==Example==   
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.
<syntaxhighlight lang="lua">
addEventHandler ( "onPlayerSpawn", getRootElement(), "playerSpawn" ) -- make the playerSpawn function be called when a player spawns
function playerSpawn ( )
  bindKey ( source, "F1", "down", "goMoo" ) -- bind the player's F1 key to the function below called 'goMoo'
end
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
</syntaxhighlight>


==See Also==
==See Also==
{{Input functions}}
{{Input functions}}

Revision as of 14:27, 10 October 2006

Removes an existing key bind from the specified player.

Syntax

unbindKey ( player thePlayer, string key, [ string keyState, string function ] ) 

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
  • function: The function you wish to unbind.

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

Example

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.

addEventHandler ( "onPlayerSpawn", getRootElement(), "playerSpawn" ) -- make the playerSpawn function be called when a player spawns
function playerSpawn ( )
  bindKey ( source, "F1", "down", "goMoo" ) -- bind the player's F1 key to the function below called 'goMoo'
end
 
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

See Also