Scripting/Squirrel/Functions/Player.Health

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

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.