OnPlayerCommand: Difference between revisions

From Vice City Multiplayer
Jump to navigation Jump to search
Caution icon
This wiki is using an old backup from 2020
Some information may be old/missing
(Fixed arguments.)
No edit summary
Line 1: Line 1:
__NOTOC__
__NOTOC__
This is called when a player uses a command.
When a player changes his weapon to newone or oldone.


== Syntax ==
== Syntax ==


<pre>function onPlayerCommand( player, cmd, parameters )</pre>
<pre>function onPlayerWeaponChange( player, oldwep, newwep )</pre>


== Parameters ==
== Parameters ==


* [[Scripting/Squirrel/Functions#Player_Functions|''Player'']] '''player''' - The player that use command.
* [[Scripting/Squirrel/Functions#Player_Functions|''Player'']] '''player''' - The player who changes the weapon.
* ''string'' '''cmd''' - This is the command that player used.
* '''oldwep''' - Players old weapon
* ''string'' '''parameters''' - This is the list of the parameters as a string.
* '''newwep''' - Players new weapon


== Example ==
== Example ==


This example command heal the player if they type '''/heal'''.
If a player will try to change his weapon to "33" ( minigun ), this example will automatically set his weapons ammo to 0. and in result, he won't be able to use that weapon.


<source lang=squirrel>
<source lang=squirrel>
function onPlayerCommand( player, cmd, text )
function onPlayerWeaponChange( player, oldwep, newwep )
{
{
if ( cmd == "heal" )
    if ( newwep == 33 )
{
    {
  if ( player.Health == 100 ) PrivMessage( player, "You have the health to maximum.");
        PrivMessage( player, "it is a blocked weapon" );
  else
        player.SetWeapon( 33,0 ); //sets weapons ammo to 0.
  {
    }
  PrivMessage( player, "You healed successfully.");
return 1; //returns true for other weapons.
  player.Health = 100;
}
}
}
</source>
</source>
Line 32: Line 30:
=== Notes ===
=== Notes ===


The function [[PrivMessage]] and call [[onPlayerCommand]] were used in this example. More info about them in the corresponding pages.
Function [[Scripting/Squirrel/Functions/PrivMessage|''PrivMessage'']] and function [[Scripting/Squirrel/Functions/Player.SetWeapon|''SetWeapon'']] were used in this example.


== Related Events ==
== Related Events ==


{{Scripting/Squirrel/Events/Player_Events}}
{{Scripting/Squirrel/Events/Player_Events}}

Revision as of 16:45, 15 March 2016

When a player changes his weapon to newone or oldone.

Syntax

function onPlayerWeaponChange( player, oldwep, newwep )

Parameters

  • Player player - The player who changes the weapon.
  • oldwep - Players old weapon
  • newwep - Players new weapon

Example

If a player will try to change his weapon to "33" ( minigun ), this example will automatically set his weapons ammo to 0. and in result, he won't be able to use that weapon.

function onPlayerWeaponChange( player, oldwep, newwep )
{
    if ( newwep == 33 )
    {
        PrivMessage( player, "it is a blocked weapon" );
        player.SetWeapon( 33,0 ); //sets weapons ammo to 0.
    }
return 1; //returns true for other weapons.
}

Notes

Function PrivMessage and function SetWeapon were used in this example.

Related Events