getElementHealth | Multi Theft Auto: Wiki Skip to content

getElementHealth

Client-side
Server-side
Shared

Pair: setElementHealth

This page is incomplete! Help wanted!

Please finish this page using the corresponding Old Wiki article.
Go to Contribution guidelines for more information.


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

Syntax

getElementHealth ( )

Code Examples

server

This example outputs the health of the player who enters the command 'showhealth', and their vehicle's health.

function showLocalHealth()
-- get the player's health and output it
local playerHealth = getElementHealth ( localPlayer )
outputChatBox ( "Your health: " .. playerHealth )
-- get the player's vehicle: if he is in one, output its health as well
local playerVehicle = getPedOccupiedVehicle ( localPlayer )
if playerVehicle then
local vehicleHealth = getElementHealth ( playerVehicle ) / 10 -- Divide this by 10, as default the denominator is 1000
outputChatBox ( "Your vehicle's health: " .. vehicleHealth )
end
end
addCommandHandler ( "showhealth", showLocalHealth )

See Also

Element Functions