Squirrel/Server/Events/Player/onPlayerKeyStateChange

From Liberty Unleashed Wiki
(Difference between revisions)
Jump to: navigation, search
 
(3 intermediate revisions by one user not shown)
Line 1: Line 1:
{{Squirrel/Title|onPlayerCommand}}
+
{{Squirrel/Title|onPlayerKeyStateChange}}
This is called when a player press a GTA's control keys.
+
 
 +
This is called when a player presses or stops pressing a certain key.
  
 
== Syntax ==
 
== Syntax ==
  
<code>function onPlayerKeyStateChange ( Player player, OldKeys, NewKeys )</code>
+
<code>function onPlayerKeyStateChange ( player, key, pressedDown )</code>
  
=== Arguments ===
+
== Arguments ==
  
 
* '''player''' - The pointer of the player
 
* '''player''' - The pointer of the player
* '''OldKeys''' - The last known keys pressed by the player
+
* '''key''' - [[Squirrel/Server/Constants#GTA_Keys|The ID of the key]] in question
* '''NewKeys''' - The new key states
+
* '''pressedDown''' - A boolean representing whether the key was just pressed down or released
  
 
=== Returns ===
 
=== Returns ===
Line 18: Line 19:
 
== Example ==
 
== Example ==
  
This example detects whether the fire key was pressed
+
The following example will annoy the player by noticing them every time they press the 'fire' key.
  
 
<code lang="squirrel">
 
<code lang="squirrel">
function onPlayerKeyStateChange ( pPlayer, oldkeys, newkeys ) {
+
function onPlayerKeyStateChange ( pPlayer, key, down ) {
  
if ( ( oldkeys & KEY_ONFOOT_FIRE == 0 ) && ( newkeys & KEY_ONFOOT_FIRE != 0 ) )
+
    if ( ( key == KEY_ONFOOT_FIRE ) && ( down ) ) MessagePlayer ( "You just pressed <FIRE>.", pPlayer );
{
+
MessagePlayer ( "Fire key pressed", pPlayer );
+
}
+
  
return;
+
    return;
 
}
 
}
 
</code>
 
</code>
Line 34: Line 32:
 
=== Notes ===
 
=== Notes ===
  
The functions [[Squirrel/Server/Functions/Messages/MessagePlayer|MessagePlayer]] and [[Squirrel/Server/Functions/Players/Pos|Player.Pos]] were used in this example. More info about them can be found in the corresponding pages.
+
The function [[Squirrel/Server/Functions/Messages/MessagePlayer|MessagePlayer]] was used in in this example. More info about it in the corresponding page.
  
 
== Related Events ==
 
== Related Events ==
  
 
{{Squirrel/Server/Events/Player}}
 
{{Squirrel/Server/Events/Player}}

Latest revision as of 17:55, 10 November 2013

Home   |   Squirrel Scripting   |   Server Functions   |   Server Events   |   Client Functions   |   Client Events


This is called when a player presses or stops pressing a certain key.

[edit] Syntax

  1. function onPlayerKeyStateChange ( player, key, pressedDown )

[edit] Arguments

  • player - The pointer of the player
  • key - The ID of the key in question
  • pressedDown - A boolean representing whether the key was just pressed down or released

[edit] Returns

This event does not handle return values.

[edit] Example

The following example will annoy the player by noticing them every time they press the 'fire' key.

  1.  
  2. function onPlayerKeyStateChange ( pPlayer, key, down ) {
  3.  
  4. if ( ( key == KEY_ONFOOT_FIRE ) && ( down ) ) MessagePlayer ( "You just pressed <FIRE>.", pPlayer );
  5.  
  6. return;
  7. }
  8.  

[edit] Notes

The function MessagePlayer was used in in this example. More info about it in the corresponding page.

[edit] Related Events

Personal tools
Namespaces

Variants
Actions
Navigation
scripting
Toolbox