OnPlayerActionChange: 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
(Created page with "__NOTOC__ This function is triggered when a player changes his action or we can say move!. ( not animation ). == Syntax == <pre>function onPlayerActionChange( player, oldAct...")
 
No edit summary
Line 14: Line 14:
== Example ==
== Example ==


In this example i have chosen action "crouch", when a player will crouch, his weapon will be automatically removed for temporary reason. ( the player won't be disarmed ), until he is crouching, he won't be able to use weapons. unless he changes his action. the player will also receive a message "you can't shoot while crouching".
In this example i have chosen action "Fire/Shoot", when a player will Fire/shoot, his weapon will be automatically removed for temporary reason. ( the player won't be disarmed ), until he is firing/shooting, he won't be able to use weapons. unless he changes his action. the player will also receive a message "you can't shoot in a RPG server.".


<source lang=squirrel>
<source lang=squirrel>
function onPlayerActionChange( player, oldAction, newAction )
function onPlayerActionChange( player, oldAction, newAction )
{
{
if ( newAction == 16 ) // 16 is the id of crouching action.
if ( newAction == 16 ) // 16 is the id of firing/shooting action.
{
{
player.SetWeapon( 0, 0 ); //sets weapon to 0. which is nothing.
player.SetWeapon( 0, 0 ); //sets weapon to 0. which is nothing.
         PrivMessage( player, "you can't shoot while crouching" );
         PrivMessage( player, "you can't shoot in a RPG server. );
}
}
}
}

Revision as of 22:50, 18 March 2016

This function is triggered when a player changes his action or we can say move!. ( not animation ).

Syntax

function onPlayerActionChange( player, oldAction, newAction )

Parameters

  • Player player - The player who changes the action.
  • oldAction - Players old Action.
  • newAction - Players new Action.

Example

In this example i have chosen action "Fire/Shoot", when a player will Fire/shoot, his weapon will be automatically removed for temporary reason. ( the player won't be disarmed ), until he is firing/shooting, he won't be able to use weapons. unless he changes his action. the player will also receive a message "you can't shoot in a RPG server.".

function onPlayerActionChange( player, oldAction, newAction )
{
	if ( newAction == 16 ) // 16 is the id of firing/shooting action.
	{
		player.SetWeapon( 0, 0 ); //sets weapon to 0. which is nothing.
        PrivMessage( player, "you can't shoot in a RPG server. );
	}
}

you must be wondering how to get actions id?. use this to get ids :)

function onPlayerActionChange( player, oldAction, newAction )
{
	if ( newAction ) // it will check if the player goes in new action.
	{
                PrivMessage( player, "your Current Actions ID: "+newAction ); // it will print the id of the action player is in.
	}
}

Notes

Function PrivMessage and function SetWeapon were used in this example.

Related Events