UnbindKey: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
Removes an existing key bind from the specified player.
Removes an existing key bind from the specified player.
Note: will remove all the binds from the current key if no command is specified


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


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


===Optional Arguments===
===Optional Arguments===
*'''keyState:''' A string containing the word "up" or "down" determining which bind you wish to remove.
*'''keyState:''' A boolean value representing the "hit-state" of the key.
*'''command:''' The command 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.


==Example==   
==Example==   
This function will bind a player's 'F1' key-down to a command when they spawn, then remove it after it's been used once.
<syntaxhighlight lang="lua">
addEventHandler ( "onPlayerSpawn", getRootElement(), "playerSpawn" ) -- make the playerSpawn function be called when a player spawns
function playerSpawn ( )
  bindKey ( source, "F1", "down", "moo" ) -- bind the player's F1 key to the console function called 'moo'
end
addCommandHandler ( "moo", "consoleMoo" ) -- create a console function called moo that triggers the function 'consoleMoo'
function consoleMoo ( )
  outputChatBox ( getClientName ( source ).." says Mooooooo!" )
  unbindKey ( source, "F1", "down", "moo" ) -- 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 13:14, 10 October 2006

Removes an existing key bind from the specified player.

Syntax

unbindKey ( player thePlayer, string key, [ bool 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: A boolean value representing the "hit-state" of the key.
  • 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.

Example

See Also