SetElementHealth: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
Line 21: | Line 21: | ||
function hpSlap ( sourcePlayer, command, targetPlayerName ) | function hpSlap ( sourcePlayer, command, targetPlayerName ) | ||
-- check if the user has access to it first | -- check if the user has access to it first | ||
if not | if not hasObjectPermissionTo(sourcePlayer, "command.slap", false) then | ||
outputChatBox ( "You cannot use this command.", sourcePlayer ) | outputChatBox ( "You cannot use this command.", sourcePlayer ) | ||
return false | return false |
Revision as of 23:24, 23 December 2011
This function sets the health for the specified element. This can be a player or a vehicle.
Syntax
bool setElementHealth ( element theElement, float newHealth )
Required Arguments
- theElement: The player or vehicle 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 = getPlayerFromNick ( 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 )
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