IsElementAttached: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
(6 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
__NOTOC__ | {{Server client function}} | ||
__NOTOC__ | |||
<!-- Describe in plain english what this function does. Don't go into details, just give an overview --> | <!-- Describe in plain english what this function does. Don't go into details, just give an overview --> | ||
This functions checks whether or not an element is attached to another element. | This functions checks whether or not an element is attached to another element. | ||
Line 6: | Line 7: | ||
<!-- NOTE: don't use 'special' names for variable names, e.g. you shouldn't be writing things like 'player player, vehicle vehicle', instead write something like 'player thePlayer, vehicle vehicleToGetInto'. This is less confusing and prevents the syntax highlighting being odd --> | <!-- NOTE: don't use 'special' names for variable names, e.g. you shouldn't be writing things like 'player player, vehicle vehicle', instead write something like 'player thePlayer, vehicle vehicleToGetInto'. This is less confusing and prevents the syntax highlighting being odd --> | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
bool isElementAttached ( theElement ) | bool isElementAttached ( element theElement ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
{{OOP||[[element]]:isAttached|attached|}} | |||
===Required Arguments=== | ===Required Arguments=== | ||
Line 15: | Line 17: | ||
===Returns=== | ===Returns=== | ||
<!-- Make this descriptive. Explain what cases will return false. If you're unsure, add a tag to it so we can check --> | <!-- Make this descriptive. Explain what cases will return false. If you're unsure, add a tag to it so we can check --> | ||
Returns ''true'' if the specified element is attached to another element, ''false'' if it is not attached or if an improper argument | Returns ''true'' if the specified element is attached to another element, ''false'' if it is not attached or ''nil'' if an improper argument was passed. | ||
==Example== | ==Example== | ||
Line 23: | Line 25: | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
-- add a command handler for 'amiattached' to call the function 'consoleIsPlayerAttached': | -- add a command handler for 'amiattached' to call the function 'consoleIsPlayerAttached': | ||
function consoleIsPlayerAttached ( thePlayer, command ) | |||
function consoleIsPlayerAttached ( | if ( thePlayer ) then -- if a player triggered this command | ||
if ( | local status = isElementAttached ( thePlayer ) -- call the function and store it's result in the 'status' variable | ||
local status = isElementAttached ( | |||
if ( status ) then -- if the function returned true, tell the player he is attached to something | if ( status ) then -- if the function returned true, tell the player he is attached to something | ||
outputConsole ( "You are attached to an element!", | outputConsole ( "You are attached to an element!", thePlayer ) | ||
else -- if the function returned false, tell the player he is not attached to anything | else -- if the function returned false, tell the player he is not attached to anything | ||
outputConsole ( "You are not attached to an element.", | outputConsole ( "You are not attached to an element.", thePlayer ) | ||
end | end | ||
end | end | ||
end | end | ||
addCommandHandler ( "amiattached", consoleIsPlayerAttached ) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
==See Also== | ==See Also== | ||
{{Element_functions}} | {{Element_functions}} | ||
Latest revision as of 23:10, 27 September 2018
This functions checks whether or not an element is attached to another element.
Syntax
bool isElementAttached ( element theElement )
OOP Syntax Help! I don't understand this!
- Method: element:isAttached(...)
- Variable: .attached
Required Arguments
- theElement: The element to check for attachment.
Returns
Returns true if the specified element is attached to another element, false if it is not attached or nil if an improper argument was passed.
Example
This examples checks if a player is attached to anything when they enter a console command:
-- add a command handler for 'amiattached' to call the function 'consoleIsPlayerAttached': function consoleIsPlayerAttached ( thePlayer, command ) if ( thePlayer ) then -- if a player triggered this command local status = isElementAttached ( thePlayer ) -- call the function and store it's result in the 'status' variable if ( status ) then -- if the function returned true, tell the player he is attached to something outputConsole ( "You are attached to an element!", thePlayer ) else -- if the function returned false, tell the player he is not attached to anything outputConsole ( "You are not attached to an element.", thePlayer ) end end end addCommandHandler ( "amiattached", consoleIsPlayerAttached )
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