GetElementHealth: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
m (Added RU page) |
||
(9 intermediate revisions by 8 users not shown) | |||
Line 1: | Line 1: | ||
{{Server client function}} | {{Server client function}} | ||
__NOTOC__ | __NOTOC__ | ||
This function returns the current health for the specified [[element]]. This can be a [[player]] , a [[ped]] , | This function returns the current health for the specified [[element]]. This can be a [[player]], a [[ped]], a [[vehicle]], or an [[object]]. | ||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
float getElementHealth ( element theElement ) | float getElementHealth ( element theElement ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
{{OOP||[[element]]:getHealth|health|setElementHealth}} | |||
===Required Arguments=== | ===Required Arguments=== | ||
Line 14: | Line 14: | ||
===Returns=== | ===Returns=== | ||
Returns a float indicating the element's health, or ''false'' if invalid arguments were passed. | Returns a float indicating the element's health, or ''false'' if invalid arguments were passed. | ||
==Example== | ==Example== | ||
Line 22: | Line 21: | ||
function showLocalHealth() | function showLocalHealth() | ||
-- get the player's health and output it | -- get the player's health and output it | ||
local playerHealth = getElementHealth ( | local playerHealth = getElementHealth ( localPlayer ) | ||
outputChatBox ( "Your health: " .. playerHealth ) | outputChatBox ( "Your health: " .. playerHealth ) | ||
-- get the player's vehicle: if he is in one, output its health as well | -- get the player's vehicle: if he is in one, output its health as well | ||
local playerVehicle = | local playerVehicle = getPedOccupiedVehicle ( localPlayer ) | ||
if playerVehicle then | if playerVehicle then | ||
local vehicleHealth = getElementHealth ( playerVehicle ) | local vehicleHealth = getElementHealth ( playerVehicle ) / 10 -- Divide this by 10, as default the denominator is 1000 | ||
outputChatBox ( "Your vehicle's health: " .. vehicleHealth ) | outputChatBox ( "Your vehicle's health: " .. vehicleHealth ) | ||
end | end | ||
Line 35: | Line 34: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</section> | </section> | ||
==See Also== | ==See Also== | ||
{{Element functions}} | {{Element functions}} | ||
[[RU:getElementHealth]] |
Latest revision as of 20:16, 11 August 2018
This function returns the current health for the specified element. This can be a player, a ped, a vehicle, or an object.
Syntax
float getElementHealth ( element theElement )
OOP Syntax Help! I don't understand this!
- Method: element:getHealth(...)
- Variable: .health
- Counterpart: setElementHealth
Required Arguments
Returns
Returns a float indicating the element's health, or false if invalid arguments were passed.
Example
Click to collapse [-]
Clientside exampleThis 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
- attachElements
- createElement
- destroyElement
- detachElements
- getAttachedElements
- getElementAlpha
- getElementAttachedOffsets
- getElementAttachedTo
- getElementByIndex
- getElementByID
- getElementChild
- getElementChildren
- getElementChildrenCount
- getElementCollisionsEnabled
- getElementColShape
- getElementData
- getAllElementData
- hasElementData
- getElementDimension
- getElementHealth
- getElementID
- getElementInterior
- getElementMatrix
- getElementModel
- getElementParent
- getElementPosition
- getElementRotation
- getElementsByType
- getElementsWithinColShape
- getElementsWithinRange
- getElementType
- getElementVelocity
- getLowLODElement
- getRootElement
- isElement
- isElementAttached
- isElementCallPropagationEnabled
- isElementDoubleSided
- isElementFrozen
- isElementInWater
- isElementLowLOD
- isElementWithinColShape
- isElementWithinMarker
- setElementAlpha
- setElementAngularVelocity
- getElementAngularVelocity
- setElementAttachedOffsets
- setElementCallPropagationEnabled
- setElementCollisionsEnabled
- setElementData
- setElementDimension
- setElementDoubleSided
- setElementFrozen
- setElementHealth
- setElementID
- setElementInterior
- setElementModel
- setElementParent
- setElementPosition
- setElementRotation
- setElementVelocity
- setLowLODElement
- getPedContactElement
- getResourceDynamicElementRoot
- getResourceRootElement