Squirrel/Server/Events/Player/onPlayerCommand

From Liberty Unleashed Wiki
(Difference between revisions)
Jump to: navigation, search
Line 1: Line 1:
__NOTOC__
+
{{Squirrel/Title|onPlayerCommand}}
This is called when a player uses a command.
+
This is called when a player types a command.
  
 
== Syntax ==
 
== Syntax ==
  
<code>function onPlayerCommand( player, command, parameters )</code>
+
<code>function onPlayerCommand( Player player, string command, string args )</code>
  
== Parameters ==
+
=== Arguments ===
  
 
* '''player''' - The pointer of the player
 
* '''player''' - The pointer of the player
* '''command''' - This is the command player used
+
* '''command''' - This is the typed command
* '''parameters''' - This is the list of the parameters as a string
+
* '''args''' - This is the list of parameters as a string
 +
 
 +
=== Returns ===
 +
 
 +
This event does not handle return values.
  
 
== Example ==
 
== Example ==
  
This example command slaps the user if they type '/c slap'.
+
This example command slaps the user if they type '/slap'.
  
 
<code lang="squirrel">
 
<code lang="squirrel">
Line 22: Line 26:
 
     {
 
     {
 
           local pos = player.Pos;
 
           local pos = player.Pos;
           pos.z += 5;
+
           pos.z += 5.0;
 
            
 
            
 
           player.Pos = pos;
 
           player.Pos = pos;
           MessagePlayer( "You slapped yourself! Now that wasn't very smart", player );
+
           MessagePlayer( "You slapped yourself! That wasn't very smart.", player );
 
     }
 
     }
 
      
 
      
Line 31: Line 35:
 
}
 
}
 
</code>
 
</code>
 +
 +
=== 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.
 +
 +
== Related Events ==
 +
 +
{{Squirrel/Server/Events/Player}}

Revision as of 18:52, 22 December 2010

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

This is called when a player types a command.

Syntax

  1. function onPlayerCommand( Player player, string command, string args )

Arguments

  • player - The pointer of the player
  • command - This is the typed command
  • args - This is the list of parameters as a string

Returns

This event does not handle return values.

Example

This example command slaps the user if they type '/slap'.

  1.  
  2. function onPlayerCommand( player, cmd, text )
  3. {
  4. if ( cmd == "slap" )
  5. {
  6. local pos = player.Pos;
  7. pos.z += 5.0;
  8. player.Pos = pos;
  9. MessagePlayer( "You slapped yourself! That wasn't very smart.", player );
  10. }
  11. return 1;
  12. }
  13.  

Notes

The functions 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.

Related Events

Personal tools
Namespaces

Variants
Actions
Navigation
scripting
Toolbox