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
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)); endendaddCommandHandler("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!"); endendaddCommandHandler("healme", healMePlease);
See Also
Element Functions
- getElementPosition
- setElementPosition
- getElementHealth
- setElementHealth