Scripting/Squirrel/Functions/Player.Health: Difference between revisions
Jump to navigation
Jump to search
This wiki is using an old backup from 2020
Some information may be old/missing
No edit summary |
|||
(One intermediate revision by one other user 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) | ||
== Example == | 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 25: | Line 32: | ||
else MessagePlayer( "[#ffffff]You Already Having 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 [[ | 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
- BanPlayer
- FindPlayer
- GetPlayerIDFromName
- IsWorldCompatibleWithPlayer
- KickPlayer
- PlaySoundForPlayer
- Player.Action
- Player.AddSpeed
- Player.Admin
- Player.AimDir
- Player.AimPos
- Player.Alpha
- Player.Ammo
- Player.Angle
- Player.Armour
- Player.Away
- Player.Ban
- Player.CameraLocked
- Player.CanAttack
- Player.CanDriveby
- Player.Cash
- Player.Class
- Player.Colour
- Player.Disarm
- Player.Eject
- Player.FPS
- Player.Frozen
- Player.GameKeys
- Player.GetAmmoAtSlot
- Player.GetWeaponAtSlot
- Player.GiveMoney
- Player.GiveWeapon
- Player.GreenScanlines
- Player.HasChatTags
- Player.HasMarker
- Player.Health
- Player.ID
- Player.Immunity
- Player.IP
- Player.IsCrouching
- Player.IsDrunk
- Player.IsOnFire
- Player.IsOnRadar
- Player.IsSpawned
- Player.Key
- Player.Kick
- Player.Name
- Player.Ping
- Player.PlaySound
- Player.Pos
- Player.Redirect
- Player.RestoreCamera
- Player.RemoveMarker
- Player.RemoveWeapon
- Player.Score
- Player.SecWorld
- Player.Select()
- Player.SetAlpha
- Player.SetAnim
- Player.SetDrunkLevel
- Player.SetCameraPos
- Player.SetInterior
- Player.SetMarker - bugged
- Player.SetWantedLevel
- Player.SetWeapon
- Player.ShowMarkers
- Player.Slot
- Player.Skin
- Player.Spawn
- Player.SpectateTarget
- Player.Speed
- Player.StandingOnObject
- Player.StandingOnVehicle
- Player.State
- Player.StreamedToPlayer
- Player.Typing
- Player.Team
- Player.UniqueID
- Player.UniqueID2
- Player.UniqueWorld
- Player.Vehicle
- Player.VehicleSlot
- Player.VehicleStatus
- Player.WantedLevel
- Player.Weapon
- Player.WhiteScanlines
- Player.Widescreen
- Player.World
- Player.PutInVehicleSlot
Player Game Functions
These functions exist for compatibility with the R2 Squirrel server.