UnbindKey: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
Line 15: | Line 15: | ||
==Example== | ==Example== | ||
This function will bind a player's 'F1' key-down to a command, then remove it after it's been used. | 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"> | <syntaxhighlight lang="lua"> | ||
addEventHandler ( "onPlayerSpawn", getRootElement(), "playerSpawn" ) -- make the playerSpawn function be called when a player spawns | |||
function | function playerSpawn ( ) | ||
bindKey ( source, "F1", "down", "moo" ) -- bind the player's F1 key | bindKey ( source, "F1", "down", "moo" ) -- bind the player's F1 key to the console function called 'moo' | ||
end | end | ||
addCommandHandler ( "moo", " | addCommandHandler ( "moo", "consoleMoo" ) -- create a console function called moo that triggers the function 'consoleMoo' | ||
function | function consoleMoo ( ) | ||
outputChatBox ( getClientName ( source ).." says Mooooooo!" ) | outputChatBox ( getClientName ( source ).." says Mooooooo!" ) | ||
unbindKey ( source, "F1", "down", "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. |
Revision as of 18:18, 8 July 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 when they spawn, then remove it after it's been used once.
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
See Also
- addCommandHandler
- bindKey
- executeCommandHandler
- getCommandHandlers
- getFunctionsBoundToKey
- getKeyBoundToFunction
- isControlEnabled
- removeCommandHandler
- toggleAllControls
- toggleControl
- unbindKey