setElementHealth
Client-side
Server-side
Shared
Pair: getElementHealth
This function sets the health for the specified element. This can be a player/ped, object or a vehicle.
Note
In the case of the vehicle element, the following effects appear, depending on the health value:
- 650: white steam 0%, black smoke 0%
- 450: white steam 100%, black smoke 50%
- 250: white steam 0%, black smoke 100%
- 249: fire with big black smoke
OOP Syntax Help! I don't understand this!
- Method:element:setHealth(...)
- Variable: .health
Syntax
bool setElementHealth ( element theElement, float newHealth )Required Arguments
- theElement: The element whose health you want to set.
- newHealth: A float indicating the new health to set for the element.
Returns
- bool: result
Returns true if the new health was set successfully, or false if invalid arguments were passed.
Code Examples
server
This example adds a hpslap console command that lets players "slap" others (doing 20 damage).
function hpSlap(sourcePlayer, command, targetPlayerName) -- check if the user has access to it first if not hasObjectPermissionTo(sourcePlayer, "command.slap", false) then outputChatBox("You cannot use this command.", sourcePlayer) return false end -- look up the player to be slapped local targetPlayer = getPlayerFromName(targetPlayerName) -- if there's a player with such name, if targetPlayer then -- subtract 20 from his health setElementHealth(targetPlayer, getElementHealth(targetPlayer) - 20) else -- otherwise, output an error message outputChatBox("There is no player named " .. targetPlayerName .. "!", sourcePlayer) endend-- add our function as a handler for "hpslap"addCommandHandler("hpslap", hpSlap)Issues
| ID | Description |
|---|---|
| 414 | Using setElementHealth on a dead ped makes it invincible. |
See Also
Element Functions
- addElementDataSubscriber
- attachElements
- clearElementVisibleTo
- cloneElement
- createElement
- destroyElement
- detachElements
- getAllElementDataUpdated
- getAttachedElements
- getElementAlpha
- getElementAngularVelocity
- getElementAttachedOffsets
- getElementAttachedTo
- getElementBonePosition
- getElementBoneQuaternionNew
- getElementBoneRotation
- getElementBoundingBox
- getElementByID
- getElementByIndex
- getElementChild
- getElementChildren
- getElementChildrenCount
- getElementCollisionsEnabled
- getElementColShape
- getElementData
- getElementDimension
- getElementDistanceFromCentreOfMassToBaseOfModel
- getElementHealth
- getElementID
- getElementInterior
- getElementLighting
- getElementMatrix
- getElementModel
- getElementParent
- getElementPosition
- getElementRadius
- getElementRotation
- getElementsByType
- getElementsWithinColShape
- getElementsWithinRange
- getElementSyncer
- getElementType
- getElementVelocity
- getElementZoneName
- getLowLODElement
- getRootElement
- hasElementData
- hasElementDataSubscriber
- isElement
- isElementAttached
- isElementCallPropagationEnabled
- isElementCollidableWith
- isElementDoubleSided
- isElementFrozen
- isElementInWater
- isElementLocal
- isElementLowLOD
- isElementOnFireNew
- isElementOnScreen
- isElementStreamable
- isElementStreamedIn
- isElementSyncer
- isElementVisibleTo
- isElementWaitingForGroundToLoad
- isElementWithinColShape
- isElementWithinMarker
- removeElementData
- removeElementDataSubscriber
- setElementAlpha
- setElementAngularVelocity
- setElementAttachedOffsets
- setElementBonePosition
- setElementBoneQuaternionNew
- setElementBoneRotation
- setElementCallPropagationEnabled
- setElementCollidableWith
- setElementCollisionsEnabled
- setElementDataUpdated
- setElementDimension
- setElementDoubleSided
- setElementFrozen
- setElementHealth
- setElementID
- setElementInterior
- setElementLightingNew
- setElementMatrix
- setElementModel
- setElementOnFireNew
- setElementParent
- setElementPosition
- setElementRotation
- setElementStreamable
- setElementSyncer
- setElementVelocity
- setElementVisibleTo
- setLowLODElement
- updateElementRpHAnim
Element Events
- onClientElementColShapeHit
- onClientElementColShapeLeave
- onClientElementDataChange
- onClientElementDestroy
- onClientElementDimensionChange
- onClientElementInteriorChange
- onClientElementModelChange
- onClientElementStreamIn
- onClientElementStreamOut
- onElementClicked
- onElementColShapeHit
- onElementColShapeLeave
- onElementDataChange
- onElementDestroy
- onElementDimensionChange
- onElementInteriorChange
- onElementModelChange
- onElementStartSync
- onElementStopSync