Scripting/Squirrel/Functions/Player.Health: 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 "== Syntax == <pre>player.Health</pre> <source lang=squirrel> function onPlayerCommand( player, cmd, text ); if ( cmd == "heal" ) { local health = player.Health; if ( h...")
 
No edit summary
 
(4 intermediate revisions by 4 users not shown)
Line 1: Line 1:
This function will set or return a player's health value.
== Syntax ==
== Syntax ==


<pre>player.Health</pre>
<pre>1. player.Health (returns the health value of player)
2. player.Health = newHealth (sets the health value of player)</pre>
 
== Arguments ==
 
* ''float'' '''newHealth''' - the new health value


== Example 1 ==
The following example will set player's health to 100, for some cash.
<source lang=squirrel>
<source lang=squirrel>
function onPlayerCommand( player, cmd, text );
function onPlayerCommand( player, cmd, text );
Line 10: Line 19:
if ( health < 100 )
if ( health < 100 )
{
{
// calculate the cost based on their health
// calculate the cost depends on their health
local cost = ( ( 250 / 100 ) * ( 100 - health ) );
local cost = ( ( 250 / 100 ) * ( 100 - health ) );
if ( player.Cash >= cost )
if ( player.Cash >= cost )
Line 17: Line 26:
stats[ player.ID ].Cash -= cost;
stats[ player.ID ].Cash -= cost;
player.Health = 100;
player.Health = 100;
Message( "[#DC26FF] Player [#ffffff][ " + player.Name + " ] [#DC26FF] buy heal [#ffffff](Cost: $" + cost + ")" );
Message( "[#DC26FF] Player [#ffffff][ " + player.Name + " ] [#DC26FF] has bought heal [#ffffff](Cost: $" + cost + ")" );
}
}
else MessagePlayer( "[#ffffff]Your no money (Cost: $" + cost + ")", player );
else MessagePlayer( "[#ffffff]You dont have enough money (Cost: $" + cost + ")", player );
}
}
else MessagePlayer( "[#ffffff]You heve 100hp :)", player );
else MessagePlayer( "[#ffffff]You Already Having 100hp :)", player );
}
}
</source>
=== Notes ===
Call [[Scripting/Squirrel/Events/Player/onPlayerCommand|onPlayerCommand]] were used in this example. More info about them in the corresponding pages.


== Example 2 ==
The following example will stop a player, with lower hp than 30, that wants to be driver.
<source lang=squirrel>
function onPlayerEnteringVehicle( player, vehicle, door )
{
Message( ">> " + player.Name + " is entering in slot " + door + " of vehicle ID + " + vehicle.ID);
if( player.Health < 30.0 )
{
if( door == 0 )
{
MessagePlayer( " Are you insane ?? You can't drive with your poor hp !", player );
return 0;
}
}
return 1;
}
</source>
</source>


=== Notes ===
=== Notes ===
Call [[Scripting/Squirrel/Events/Player/onPlayerCommand|onPlayerCommand]] were used in this example. More info about them in the corresponding pages.
Call [[onPlayerEnteringVehicle]] were used in this example. More info about them in the corresponding pages.
 
== Related Functions ==
 
{{Scripting/Squirrel/Functions/Player_Functions}}
[[Category:Scripting/Squirrel/Functions/Player_Functions]]

Latest revision as of 18:49, 30 January 2017

This function will set or return a player's health value.

Syntax

1. player.Health (returns the health value of player)
2. player.Health = newHealth (sets the health value of player)

Arguments

  • float newHealth - the new health value

Example 1

The following example will set player's health to 100, for some cash.

function onPlayerCommand( player, cmd, text );
	if ( cmd == "heal" )
	{
		local health = player.Health;
		if ( health < 100 )
		{
			// calculate the cost depends on their health
			local cost = ( ( 250 / 100 ) * ( 100 - health ) );
			if ( player.Cash >= cost )
			{
				player.Cash -= cost;
				stats[ player.ID ].Cash -= cost;
				player.Health = 100;
				Message( "[#DC26FF] Player [#ffffff][ " + player.Name + " ] [#DC26FF] has bought heal [#ffffff](Cost: $" + cost + ")" );
			}
			else MessagePlayer( "[#ffffff]You dont have enough money (Cost: $" + cost + ")", player );
		}
		else MessagePlayer( "[#ffffff]You Already Having 100hp :)", player );
	}

Notes

Call onPlayerCommand were used in this example. More info about them in the corresponding pages.

Example 2

The following example will stop a player, with lower hp than 30, that wants to be driver.

function onPlayerEnteringVehicle( player, vehicle, door )
{
	Message( ">> " + player.Name + " is entering in slot " + door + " of vehicle ID + " + vehicle.ID);
	if( player.Health < 30.0 ) 
	{
		if( door == 0 )
		{
			MessagePlayer( " Are you insane ?? You can't drive with your poor hp !", player );
			return 0;
		}
	}
	return 1;
}

Notes

Call onPlayerEnteringVehicle were used in this example. More info about them in the corresponding pages.

Related Functions

Player Game Functions

These functions exist for compatibility with the R2 Squirrel server.