getElementHealth
Type: Shared
Pair: setElementHealth
This function returns the current health for the specified element. This can be a player, ped, vehicle, or object.
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);