Shared function
getElementHealth
This function returns the current health for the specified element. This can be a player, ped, vehicle, or object.
Syntax
float getElementHealth ( element theElement )
void ( )
Returns
Returns a float indicating the element's health, false otherwise.
- float health
Issues
- mtasa-blue #3791 : setPedArmor and setElementHealth synchronization problems from Client to Server
- mtasa-blue #2223 : setElementHealth in onClientPlayerDamage bug
- mtasa-blue #1423 : When you setElementHealth under onClientPlayerDamage, the local (hit) player rotates automatically
Examples
Example 1 (Client-side)
Example 2 (Client-side)
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);
This example heals the player to 100 HP using /healme command if he's at 50 HP or lower:
function healMePlease()
-- heal the player if health is 50 or lower
if(getElementHealth(localPlayer) <= 50) then
setElementHealth(localPlayer, 100);
outputChatBox("You got healed!");
end
end
addCommandHandler("healme", healMePlease);
