SetElementHealth: Difference between revisions
Jump to navigation
Jump to search
Mack Varial (talk | contribs) (→Syntax) |
m (Issue fixed in 1.6) Tag: Manual revert |
||
(11 intermediate revisions by 9 users not shown) | |||
Line 1: | Line 1: | ||
{{Server client function}} | {{Server client function}} | ||
__NOTOC__ | __NOTOC__ | ||
This function sets the health for the specified [[element]]. This can be a [[ | This function sets the health for the specified [[element]]. This can be a [[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 | |||
}} | |||
==Syntax== | ==Syntax== | ||
Line 7: | Line 13: | ||
bool setElementHealth ( element theElement, float newHealth ) | bool setElementHealth ( element theElement, float newHealth ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
{{OOP||[[element]]:setHealth|health|getElementHealth}} | |||
===Required Arguments=== | ===Required Arguments=== | ||
*'''theElement:''' The [[ | *'''theElement:''' The [[ped]], [[vehicle]] or [[object]] whose health you want to set. | ||
*'''newHealth:''' A float indicating the new health to set for the element. | *'''newHealth:''' A float indicating the new health to set for the element. | ||
Line 40: | Line 47: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</section> | </section> | ||
<section name="Example 1" class="server" show="true"> | |||
This example setting health by a command. | |||
<syntaxhighlight lang="lua"> | |||
function Health(player, command, amount) | |||
setElementHealth(player, tonumber(amount)) | |||
end | |||
addCommandHandler("set", Health) | |||
</syntaxhighlight> | |||
</section> | |||
==Issues== | |||
{{Issues| | |||
{{Issue|414|Using setElementHealth on a dead ped makes it invincible}} | |||
}} | |||
==See Also== | ==See Also== | ||
{{Element functions}} | {{Element functions}} |
Latest revision as of 15:41, 24 July 2023
This function sets the health for the specified element. This can be a ped, object or a vehicle.
Syntax
bool setElementHealth ( element theElement, float newHealth )
OOP Syntax Help! I don't understand this!
- Method: element:setHealth(...)
- Variable: .health
- Counterpart: getElementHealth
Required Arguments
- theElement: The ped, vehicle or object whose health you want to set.
- newHealth: A float indicating the new health to set for the element.
Returns
Returns true if the new health was set successfully, or false if invalid arguments were passed.
Example
Click to collapse [-]
ServerThis 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 ) end end -- add our function as a handler for "hpslap" addCommandHandler ( "hpslap", hpSlap )
Click to collapse [-]
Example 1This example setting health by a command.
function Health(player, command, amount) setElementHealth(player, tonumber(amount)) end addCommandHandler("set", Health)
Issues
Issue ID | Description |
---|---|
#414 | Using setElementHealth on a dead ped makes it invincible |
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