SetElementPosition: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
Dutchman101 (talk | contribs) (improve examples (includes removing a bloated one)) |
||
Line 22: | Line 22: | ||
Returns ''true'' if the function was successful, ''false'' otherwise. | Returns ''true'' if the function was successful, ''false'' otherwise. | ||
==Example== | ==Example== | ||
<section name=" | <section name="Server" class="server" show="true"> | ||
This example | This example lets admins teleport 5 random players to themselves | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function | function randomPlayersToLocation(p) | ||
if not isPlayerStaff(p) then return end | |||
local playersOnline = getElementsByType("player") | |||
local amount = #playersOnline | |||
if amount == 0 then return end | |||
for index = 1,(amount > 5 and 5 or amount) do | |||
local player = playersOnline[index] | |||
setElementPosition(player, getElementPosition(p)) | |||
end | |||
end | end | ||
addCommandHandler ( " | addCommandHandler("randomtp", randomPlayersToLocation) | ||
addCommandHandler("playershere", randomPlayersToLocation) | |||
-- Utility function | |||
local staffACLs = { | |||
aclGetGroup("Admin"), | |||
function | aclGetGroup("Moderator") | ||
} | |||
function isPlayerStaff(p) | |||
if isElement(p) and getElementType(p) == "player" and not isGuestAccount(getPlayerAccount(p)) then | |||
local object = getAccountName(getPlayerAccount(p)) | |||
for _, group in ipairs(staffACLs) do | |||
if isObjectInACLGroup("user." .. object, group) then | |||
function | return true | ||
if ( | |||
if | |||
end | end | ||
end | end | ||
end | end | ||
return false | |||
end | end | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</section> | </section> |
Revision as of 04:37, 30 October 2021
This function sets the position of an element to the specified coordinates.
Syntax
bool setElementPosition ( element theElement, float x, float y, float z [, bool warp = true ] )
OOP Syntax Help! I don't understand this!
- Method: element:setPosition(...)
- Variable: .position
- Counterpart: getElementPosition
Required Arguments
- theElement: A valid element to be moved.
- x: The x coordinate of the destination.
- y: The y coordinate of the destination.
- z: The z coordinate of the destination.
Optional Arguments
- warp: teleports players, resetting any animations they were doing. Setting this to false preserves the current animation.
Returns
Returns true if the function was successful, false otherwise.
Example
Click to collapse [-]
ServerThis example lets admins teleport 5 random players to themselves
function randomPlayersToLocation(p) if not isPlayerStaff(p) then return end local playersOnline = getElementsByType("player") local amount = #playersOnline if amount == 0 then return end for index = 1,(amount > 5 and 5 or amount) do local player = playersOnline[index] setElementPosition(player, getElementPosition(p)) end end addCommandHandler("randomtp", randomPlayersToLocation) addCommandHandler("playershere", randomPlayersToLocation) -- Utility function local staffACLs = { aclGetGroup("Admin"), aclGetGroup("Moderator") } function isPlayerStaff(p) if isElement(p) and getElementType(p) == "player" and not isGuestAccount(getPlayerAccount(p)) then local object = getAccountName(getPlayerAccount(p)) for _, group in ipairs(staffACLs) do if isObjectInACLGroup("user." .. object, group) then return true end end end return false end
Issues
Issue ID | Description |
---|---|
#9522 | Setting a ped's or player's position whilst occupying a jetpack will remove their jetpack, but not the jetpack sound |
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