UnbindKey: Difference between revisions

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


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


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


===Optional Arguments===
===Optional Arguments===
*'''keyState:''' A string containing the word "up" or "down" determining which bind you wish to remove.
*'''command:''' The command you wish to unbind.
*'''command:''' The command you wish to unbind.


==Example==   
==Example==   
This function will bind a player's 'F1' key to a command, then remove it after it's been used.
This function will bind a player's 'F1' key-down to a command, then remove it after it's been used.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
addCommandHandler ( "bindmekeysplz", "bindtehkeys" )
addCommandHandler ( "bindmekeysplz", "bindtehkeys" )
function bindtehkeys ( )
function bindtehkeys ( )
   bindKey ( source, "F1", "moo" ) -- bind the player's F1 key
   bindKey ( source, "F1", "down", "moo" ) -- bind the player's F1 key
end
end


Line 24: Line 25:
function moo ( )
function moo ( )
   outputChatBox ( getClientName ( source ).." says Mooooooo!" )
   outputChatBox ( getClientName ( source ).." says Mooooooo!" )
   unbindKey ( source, "F1", "moo" ) -- this function will no longer be triggered by the player, after removing the bind.
   unbindKey ( source, "F1", "down", "moo" ) -- this function will no longer be triggered by the player, after removing the bind.
end
end
</syntaxhighlight>
</syntaxhighlight>

Revision as of 21:54, 27 June 2006

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

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

Required Arguments

  • thePlayer: The player you wish to unbind the key of.
  • key: The key you wish to unbind.

Optional Arguments

  • keyState: A string containing the word "up" or "down" determining which bind you wish to remove.
  • command: The command you wish to unbind.

Example

This function will bind a player's 'F1' key-down to a command, then remove it after it's been used.

addCommandHandler ( "bindmekeysplz", "bindtehkeys" )
function bindtehkeys ( )
  bindKey ( source, "F1", "down", "moo" ) -- bind the player's F1 key
end

addCommandHandler ( "moo", "moo" )
function moo ( )
  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

See Also