Squirrel/Server/Events/Player/onPlayerWeaponChange

From Liberty Unleashed Wiki
(Difference between revisions)
Jump to: navigation, search
(Parameters)
Line 1: Line 1:
__NOTOC__
+
{{Squirrel/Title|onPlayerWeaponChange}}
 
This is called when a player switches their weapon.
 
This is called when a player switches their weapon.
  
Line 6: Line 6:
 
<code>function onPlayerWeaponChange( player, oldWeapon, newWeapon )</code>
 
<code>function onPlayerWeaponChange( player, oldWeapon, newWeapon )</code>
  
== Parameters ==
+
=== Arguments ===
  
 
* '''player''' - The player pointer
 
* '''player''' - The player pointer
* '''oldWeapon''' - ID of the weapon a player was wielding before the detected change
+
* '''oldWeapon''' - ID of the weapon the player was wielding before the detected change
* '''newWeapon''' - ID of the weapon a player is holding after the detected change
+
* '''newWeapon''' - ID of the weapon after the change
 +
 
 +
=== Returns ===
 +
 
 +
This event does not handle return values.
  
 
== Example ==
 
== Example ==
  
This example will block a player from firing their weapon if they switch to a minigun in a server without minigun pickups/commands
+
This example will reset the player's weapons if they switch to grenades.
  
 
<code lang="squirrel">
 
<code lang="squirrel">
 
function onPlayerWeaponChange( player, oldwep, newwep )
 
function onPlayerWeaponChange( player, oldwep, newwep )
 
{
 
{
     if ( newwep == 33 ) Message( "Weapon sync has been disabled for:[ " + player.Name + " ] Reason:[ Minigun Cheats ]") && player.IsWeaponSyncBlocked = false;
+
     if ( newwep == WEP_GRENADE )
 +
    {
 +
          MessagePlayer( "Grenades are not allowed!", player );
 +
         
 +
          player.ClearWeapons();
 +
    }
 +
   
 +
    return 1;
 
}
 
}
 
</code>
 
</code>
Line 25: Line 36:
 
=== Notes ===
 
=== Notes ===
  
The functions [[Squirrel/Server/Functions/Messages/Message|Message]] and [[Squirrel/Server/Functions/Players/Name|player.Name]] were used in in this example. More info about them can be found in the corresponding pages.
+
The functions [[Squirrel/Server/Functions/Messages/MessagePlayer|MessagePlayer]] and [[Squirrel/Server/Functions/Players/ClearWeapons|Player.ClearWeapons]] were used in this example. More info about them can be found in the corresponding pages.
  
 
== Related Events ==
 
== Related Events ==
  
 
{{Squirrel/Server/Events/Player}}
 
{{Squirrel/Server/Events/Player}}

Revision as of 18:29, 22 December 2010

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

This is called when a player switches their weapon.

Syntax

  1. function onPlayerWeaponChange( player, oldWeapon, newWeapon )

Arguments

  • player - The player pointer
  • oldWeapon - ID of the weapon the player was wielding before the detected change
  • newWeapon - ID of the weapon after the change

Returns

This event does not handle return values.

Example

This example will reset the player's weapons if they switch to grenades.

  1.  
  2. function onPlayerWeaponChange( player, oldwep, newwep )
  3. {
  4. if ( newwep == WEP_GRENADE )
  5. {
  6. MessagePlayer( "Grenades are not allowed!", player );
  7. player.ClearWeapons();
  8. }
  9. return 1;
  10. }
  11.  

Notes

The functions MessagePlayer and Player.ClearWeapons 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