setElementHealth | Multi Theft Auto: Wiki Skip to content

setElementHealth

Client-side
Server-side
Shared

Pair: getElementHealth

This function sets the health of a player, ped, vehicle, or object element.

Note

In the case of the vehicle element, the health ranges from 0 to 1000.

  • 1000: no damage at all
  • 650: white steam 0%, black smoke 0%
  • 450: white steam 100%, black smoke 50%
  • 250: white steam 0%, black smoke 100%
  • 249: fire with big black smoke (blowing up)

OOP Syntax Help! I don't understand this!

  • Method: element:setHealth(...)
  • Variable: .health

Syntax

bool setElementHealth ( element theElement, float newHealth )
Required Arguments
  • theElement: The player, ped, vehicle, or object element whose health you want to set.
  • newHealth: A float indicating the new health to set for the element.

Returns

  • bool: result

Returns true if the new health was set successfully, false otherwise.

Code Examples

client

This example heals the player vehicle using the command /repairvehicle if it's below 1000 HP:

function repairMyVehicle()
-- check if we are in a vehicle
local uVehicle = getPedOccupiedVehicle(localPlayer);
if(uVehicle) then
-- does our vehicle need repair? remember, vehicle health ranges from 0 to 1000
if(getElementHealth(uVehicle) < 1000) then
-- note: setElementHealth does not repair the visual aspect of vehicles, use fixVehicle instead!
setElementHealth(uVehicle, 1000);
else
outputChatBox("Your vehicle is already at full health!", 255, 0, 0);
end
else
outputChatBox("You are not in a vehicle!", 255, 0, 0);
end
end
addCommandHandler("repairvehicle", repairMyVehicle);

Issues

ID Description
3807 hpbar on hud is not compatible visually with MAX_HEALTH stat
3791 setPedArmor and setElementHealth synchronization problems from Client to Server
2223 setElementHealth in onClientPlayerDamage bug
1423 When you setElementHealth under onClientPlayerDamage, the local (hit) player rotates automatically
448 Crash when plane explode

See Also

Element Functions