Scripting/Squirrel/Functions/Misc/BindKey

From VC-MP Wiki

Jump to: navigation, search

This binds a certain key to a function which is called when a player presses the key.

Syntax

bool BindKey( int key, bool pressedDown, string function, args... )

Syntax for the function to be called:

function CalledFunction( player playerObject, args... )

Arguments

  • key This is the ID of the key which will call the bound function
  • pressedDown A boolean which tells the script to call the function when the key is pressed down (true) or released (false)
  • function This is the function to be be called when the key is pressed down/released
  • args Any arguments you want to pass to the function when called

Example

This example will bind a function 'DontPressMe' to the fire key.

// This will bind the fire key to the function 'DontPressMe'
 
BindKey( KEY_ONFOOT_FIRE, true, "DontPressMe", "You pressed FIRE! You will now be brutally killed." );
 
 
// This is the function to be called
 
function DontPressMe( player, sometext )
{
     MessagePlayer( sometext, player );
     player.Health = 0;
}

Notes

The function MessagePlayer and method player.Health were used in in this example. More info about them in corresponding pages.

Related Functions

Personal tools
squirrel scripting