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
No edit summary
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
When a player changes his weapon to newone or oldone.
This is called when a player uses a command.


== Syntax ==
== Syntax ==


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


== Parameters ==
== Parameters ==


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


== Example ==
== 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.
This example command heal the player if they type '''/heal'''.


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


Function [[Scripting/Squirrel/Functions/PrivMessage|''PrivMessage'']] and function [[Scripting/Squirrel/Functions/Player.SetWeapon|''SetWeapon'']] were used in this example.
Call [[Scripting/Squirrel/Events/Player/onPlayerCommand|onPlayerCommand]] and functions [[Scripting/Squirrel/Functions/PrivMessage|PrivMessage]] + [[Scripting/Squirrel/Functions/Player.Health|player.Health]] were used in this example. More info about them in the corresponding pages.


== Related Events ==
== Related Functions ==


{{Scripting/Squirrel/Events/Player_Events}}
{{Scripting/Squirrel/Events/Player_Events}}
[[Category:Scripting/Squirrel/Events/Player_Events]]

Latest revision as of 19:28, 4 August 2017

This is called when a player uses a command.

Syntax

function onPlayerCommand( player, cmd, parameters )

Parameters

  • Player player - The player that used the command.
  • string cmd - The command that player used.
  • string text - List of command parameters as string.

Example

This example command heal the player if they type /heal.

function onPlayerCommand( player, cmd, text )
{
 if ( cmd == "heal" )
 {
  if ( player.Health == 100 ) PrivMessage( player, "You have the health to maximum.");
  else 
  {
   PrivMessage( player, "You healed successfully.");
   player.Health = 100;
 }
}

Notes

Call onPlayerCommand and functions PrivMessage + player.Health were used in this example. More info about them in the corresponding pages.

Related Functions