BindKey: Difference between revisions

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


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


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


===Optional Arguments===
===Optional Arguments===
*'''keyState:''' A string containing the word "up" or "down" determining when the binded command will be called.
*'''arguments:''' Any arguments you may want to pass to the command handler.
*'''arguments:''' Any arguments you may want to pass to the command handler.


Line 18: Line 19:
addCommandHandler ( "bindmekeysplz", "bindtehkeys" )
addCommandHandler ( "bindmekeysplz", "bindtehkeys" )
function bindtehkeys ( )
function bindtehkeys ( )
   bindKey ( source, "F1", "moo" ) -- bind the player's F1 key
   bindKey ( source, "F1", "down", "keydown" ) -- bind the player's F1 down key
  bindKey ( source, "F1", "up", "keyup" ) -- bind the player's F1 up key
end
end


addCommandHandler ( "moo", "moo" )
addCommandHandler ( "keydown", "keydown" )
function moo ( )
function keydown ( )
   outputChatBox ( getClientName ( source ).." says Mooooooo!" )
   outputChatBox ( getClientName ( source ).." pressed the F1 key" )
end
 
addCommandHandler ( "keyup", "keyup" )
function keyup ( )
  outputChatBox ( getClientName ( source ).." let go of the F1 key" )
end
end
</syntaxhighlight>
</syntaxhighlight>

Revision as of 21:52, 27 June 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, [ string keyState ], string command, [string arguments] ) 

Required Arguments

  • thePlayer: The player you wish to bind the key of.
  • key: The key you wish to bind to the command.
  • command: The command that will be triggered when the player's key is pressed.

Optional Arguments

  • keyState: A string containing the word "up" or "down" determining when the binded command will be called.
  • arguments: Any arguments you may want to pass to the command handler.

Example

This function will bind a player's 'F1' key to a command.

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

addCommandHandler ( "keydown", "keydown" )
function keydown ( )
  outputChatBox ( getClientName ( source ).." pressed the F1 key" )
end

addCommandHandler ( "keyup", "keyup" )
function keyup ( )
  outputChatBox ( getClientName ( source ).." let go of the F1 key" )
end

See Also