getElementHealth | Multi Theft Auto: Wiki Skip to content

getElementHealth

Client-side
Server-side
Shared

Pair: setElementHealth

This function returns the current health for the specified element. This can be a player, ped, vehicle, or object.

OOP Syntax Help! I don't understand this!

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

Syntax

float|false getElementHealth ( element theElement )
Required Arguments

Returns

  • float|false: health

Returns a float indicating the element's health, false otherwise.

Code Examples

client

This example outputs the player and vehicle health (if player is in a vehicle) to chatbox using /health command:

function getMyHealth()
-- output player ped health to chat
outputChatBox("My health is: "..getElementHealth(localPlayer));
-- check if we are in a vehicle
local uVehicle = getPedOccupiedVehicle(localPlayer);
-- if valid vehicle, output its health to chat
if(uVehicle) then
outputChatBox("My vehicle health is: "..getElementHealth(uVehicle));
end
end
addCommandHandler("health", getMyHealth);

Issues

ID Description
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

See Also

Element Functions