IsElementWithinColShape: Difference between revisions
(Add version notes) |
No edit summary |
||
(6 intermediate revisions by 5 users not shown) | |||
Line 2: | Line 2: | ||
__NOTOC__ | __NOTOC__ | ||
This function is used to determine if an element is within a collision shape. Please note that for legacy reasons, a colshape created on the client does not collide with elements already existing at that location until they first move. Please also note that before 1.0.3, this did not function correctly when moving a colshape. | This function is used to determine if an element is within a collision shape. Please note that for legacy reasons, a colshape created on the client does not collide with elements already existing at that location until they first move. Please also note that before 1.0.3, this did not function correctly when moving a colshape. | ||
Please note that this function doesn't verify whether element is in the same dimension and interior, additional checks could be implemented manually if they are needed. | |||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua">bool isElementWithinColShape ( element theElement, colshape theShape )</syntaxhighlight> | <syntaxhighlight lang="lua">bool isElementWithinColShape ( element theElement, colshape theShape )</syntaxhighlight> | ||
{{OOP||[[element]]:isWithinColShape}} | |||
===Required Arguments=== | ===Required Arguments=== | ||
Line 16: | Line 19: | ||
This small script is an example of detecting if a player is within a certain defined colshape. This could serve as a base to perform many functions, rather than just an output. | This small script is an example of detecting if a player is within a certain defined colshape. This could serve as a base to perform many functions, rather than just an output. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
local circlearea = createColCircle ( 0, 0, 10 ) | |||
function ColShapeHit ( thePlayer, matchingDimension ) | function ColShapeHit ( thePlayer, matchingDimension ) | ||
detection = isElementWithinColShape ( thePlayer, circlearea ) | local detection = isElementWithinColShape ( thePlayer, circlearea ) | ||
--A variable called 'detection' stores the result of asking if the player | --A variable called 'detection' stores the result of asking if the player | ||
--who entered a colshape is within the specific colshape called 'circlearea'. | --who entered a colshape is within the specific colshape called 'circlearea'. | ||
--The result is either true or false. | --The result is either true or false. | ||
detection = detection and getElementDimension( thePlayer ) == getElementDimension( circlearea ) | |||
outputChatBox ( " | --Let's additionally check element dimensions. | ||
if detection then | |||
outputChatBox ( getPlayerName(thePlayer).." is in the 'circle area' col shape" ) | |||
end | end | ||
--if detection was true then the player is in the col shape. Output a | --if detection was true then the player is in the col shape. Output a | ||
--message to confirm this | --message to confirm this | ||
end | end | ||
addEventHandler ( "onColShapeHit", | addEventHandler ( "onColShapeHit", root, ColShapeHit ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
==See Also== | ==See Also== | ||
{{element functions}} | {{element functions}} | ||
[[hu:isElementWithinColShape]] |
Latest revision as of 12:06, 10 October 2018
This function is used to determine if an element is within a collision shape. Please note that for legacy reasons, a colshape created on the client does not collide with elements already existing at that location until they first move. Please also note that before 1.0.3, this did not function correctly when moving a colshape.
Please note that this function doesn't verify whether element is in the same dimension and interior, additional checks could be implemented manually if they are needed.
Syntax
bool isElementWithinColShape ( element theElement, colshape theShape )
OOP Syntax Help! I don't understand this!
- Method: element:isWithinColShape(...)
Required Arguments
Returns
Returns true if the element is within the colshape, false otherwise
Example
This small script is an example of detecting if a player is within a certain defined colshape. This could serve as a base to perform many functions, rather than just an output.
local circlearea = createColCircle ( 0, 0, 10 ) function ColShapeHit ( thePlayer, matchingDimension ) local detection = isElementWithinColShape ( thePlayer, circlearea ) --A variable called 'detection' stores the result of asking if the player --who entered a colshape is within the specific colshape called 'circlearea'. --The result is either true or false. detection = detection and getElementDimension( thePlayer ) == getElementDimension( circlearea ) --Let's additionally check element dimensions. if detection then outputChatBox ( getPlayerName(thePlayer).." is in the 'circle area' col shape" ) end --if detection was true then the player is in the col shape. Output a --message to confirm this end addEventHandler ( "onColShapeHit", root, ColShapeHit )
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