BindKey: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 3: | Line 3: | ||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua">bindKey ( player thePlayer, string key, | <syntaxhighlight lang="lua">bindKey ( player thePlayer, string key, bool keyState, string function, [ var aguments, ... ] ) </syntaxhighlight> | ||
===Required Arguments=== | ===Required Arguments=== | ||
*'''thePlayer:''' The player you wish to bind the key of. | *'''thePlayer:''' The player you wish to bind the key of. | ||
*'''key:''' The key or control you wish to bind to the command. See [[Key names]] for a list of possible keys and [[control names]] for a list of possible controls. | *'''key:''' The key or control you wish to bind to the command. See [[Key names]] for a list of possible keys and [[control names]] for a list of possible controls. | ||
*''' | *'''keyState:''' A boolean value representing the "hit-state" of the key (whether it will be trigged when pressed or released) | ||
*'''function:''' The function that will be triggered when the player's key is pressed. See [[Control names]] for a list of GTA keys that can be used. | |||
===Optional Arguments=== | ===Optional Arguments=== | ||
{{OptionalArg}} | |||
*''' | *'''arguments:''' Any arguments you may want to pass to the function when the key is pressed by the user. When this string is recieved by the server, it will be split up into seperate words (seperated by spaces) and passed to any attached command handlers. | ||
==Example== | ==Example== | ||
'''Example 1:''' This example will bind a player's 'F1' key to | '''Example 1:''' This example will bind a player's 'F1' key and 'fire' control to 1 input function. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
addCommandHandler ( "bindme", "bindthekeys" ) | addCommandHandler ( "bindme", "bindthekeys" ) | ||
function bindthekeys ( source ) | function bindthekeys ( source ) | ||
bindKey ( source, "F1", "down", " | bindKey ( source, "F1", true, "funcInput" ) -- bind the player's F1 down key | ||
bindKey ( source, " | bindKey ( source, "F1", false, "funcInput" ) -- bind the player's F1 up key | ||
bindKey ( source, "fire", true, "funcInput" ) -- bind the player's fire down control | |||
bindKey ( source, "fire", false, "funcInput" ) -- bind the player's fire up control | |||
end | end | ||
function funcInput ( source, key, hitState ) | |||
function | state = " let go of " | ||
if ( hitState ) then | |||
state = " pressed " | |||
end | |||
outputChatBox ( getClientName ( source ) .. state .. "the " .. key .. " key!" ) | |||
end | |||
end | end | ||
</syntaxhighlight> | </syntaxhighlight> |
Revision as of 13:10, 10 October 2006
Binds a player's key to a console command, which will be triggered when the key is pressed.
Syntax
bindKey ( player thePlayer, string key, bool keyState, string function, [ var aguments, ... ] )
Required Arguments
- thePlayer: The player you wish to bind the key of.
- key: The key or control you wish to bind to the command. See Key names for a list of possible keys and control names for a list of possible controls.
- keyState: A boolean value representing the "hit-state" of the key (whether it will be trigged when pressed or released)
- function: The function that will be triggered when the player's key is pressed. See Control names for a list of GTA keys that can be used.
Optional Arguments
NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use. For more information on optional arguments, see optional arguments.
- arguments: Any arguments you may want to pass to the function when the key is pressed by the user. When this string is recieved by the server, it will be split up into seperate words (seperated by spaces) and passed to any attached command handlers.
Example
Example 1: This example will bind a player's 'F1' key and 'fire' control to 1 input function.
addCommandHandler ( "bindme", "bindthekeys" ) function bindthekeys ( source ) bindKey ( source, "F1", true, "funcInput" ) -- bind the player's F1 down key bindKey ( source, "F1", false, "funcInput" ) -- bind the player's F1 up key bindKey ( source, "fire", true, "funcInput" ) -- bind the player's fire down control bindKey ( source, "fire", false, "funcInput" ) -- bind the player's fire up control end function funcInput ( source, key, hitState ) state = " let go of " if ( hitState ) then state = " pressed " end outputChatBox ( getClientName ( source ) .. state .. "the " .. key .. " key!" ) end
See Also
- addCommandHandler
- bindKey
- executeCommandHandler
- getCommandHandlers
- getFunctionsBoundToKey
- getKeyBoundToFunction
- isControlEnabled
- removeCommandHandler
- toggleAllControls
- toggleControl
- unbindKey