IsElementCollidableWith: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
m (add space) |
||
(5 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
{{Client function}} | {{Client function}} | ||
__NOTOC__ | __NOTOC__ | ||
This function can be used to check whether specified element is collidable with another element.<br> | This function can be used to check whether specified element is collidable with another element.<br> | ||
'''Note:''' You can only use this function with the element types listed below. | '''Note:''' You can only use this function with the element types listed below. | ||
Line 9: | Line 7: | ||
*[[Vehicle]] | *[[Vehicle]] | ||
*[[Object]] | *[[Object]] | ||
{{Added feature/item|1.5.9|1.5.8|21348| | |||
* [[Element/Weapon|Weapon]] | |||
}} | |||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
bool isElementCollidableWith ( element theElement, element withElement ) | bool isElementCollidableWith ( element theElement, element withElement ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
{{New feature/item|3.0141|1.4.0|6987|{{OOP||[[element]]:isCollidableWith||setElementCollidableWith}}}} | |||
===Required Arguments=== | ===Required Arguments=== | ||
Line 20: | Line 22: | ||
===Returns=== | ===Returns=== | ||
Returns ''true'' if the elements collide with | Returns ''true'' if the elements collide with each other, ''false'' otherwise. | ||
==Example== | ==Example== | ||
This example adds the command ''togglecol'' which toggles the collision between the player and ped. | |||
<section name="Client" class="client" show="true"> | <section name="Client" class="client" show="true"> | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
-- | local tPed = {} | ||
addEventHandler( "onClientPlayerSpawn", localPlayer, | |||
function() | |||
local x, y, z = getElementPosition(source) | |||
if isElement(tPed["thePed"]) then | |||
destroyElement(tPed["thePed"]) | |||
end | |||
-- Creates a random ped near player | |||
tPed["thePed"] = createPed(math.random(209, 238), x+1, y+1, z) | |||
end | |||
) | |||
function toggleColisionFunc() | |||
if not isElement(tPed["thePed"]) then | |||
return | |||
end | |||
-- Is the local player collidable with the ped? | |||
local isCollidable = isElementCollidableWith( localPlayer, tPed["thePed"] ) | |||
-- Toggles the colision with the ped. | |||
setElementCollidableWith( localPlayer, tPed["thePed"], not isCollidable ) | |||
end | |||
-- Adds a command handler to enable/disable colisions with the ped | |||
addCommandHandler("togglecol", toggleColisionFunc) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
</section> | </section> | ||
Line 31: | Line 56: | ||
==See Also== | ==See Also== | ||
{{Client element functions}} | {{Client element functions}} | ||
Latest revision as of 16:06, 23 December 2023
This function can be used to check whether specified element is collidable with another element.
Note: You can only use this function with the element types listed below.
Syntax
bool isElementCollidableWith ( element theElement, element withElement )
OOP Syntax Help! I don't understand this!
- Method: element:isCollidableWith(...)
- Counterpart: setElementCollidableWith
Required Arguments
- theElement: The element which colliding you want to get
- withElement: The other element which colliding with the first entity you want to get
Returns
Returns true if the elements collide with each other, false otherwise.
Example
This example adds the command togglecol which toggles the collision between the player and ped.
Click to collapse [-]
Clientlocal tPed = {} addEventHandler( "onClientPlayerSpawn", localPlayer, function() local x, y, z = getElementPosition(source) if isElement(tPed["thePed"]) then destroyElement(tPed["thePed"]) end -- Creates a random ped near player tPed["thePed"] = createPed(math.random(209, 238), x+1, y+1, z) end ) function toggleColisionFunc() if not isElement(tPed["thePed"]) then return end -- Is the local player collidable with the ped? local isCollidable = isElementCollidableWith( localPlayer, tPed["thePed"] ) -- Toggles the colision with the ped. setElementCollidableWith( localPlayer, tPed["thePed"], not isCollidable ) end -- Adds a command handler to enable/disable colisions with the ped addCommandHandler("togglecol", toggleColisionFunc)
See Also
- getElementBoneMatrix
- getElementBonePosition
- getElementBoneRotation
- getElementBoundingBox
- getElementDistanceFromCentreOfMassToBaseOfModel
- getElementLighting
- getElementRadius
- isElementCollidableWith
- isElementLocal
- isElementOnScreen
- isElementStreamable
- isElementStreamedIn
- isElementSyncer
- isElementWaitingForGroundToLoad
- setElementBoneMatrix
- setElementBonePosition
- setElementBoneRotation
- setElementCollidableWith
- setElementStreamable
- updateElementRpHAnim
- Shared
- 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