Shared function
setElementPosition
This function sets the position of an element to the specified coordinates.
Syntax
bool setElementPosition ( element theElement, float x, float y, float y, bool warp )
- element theElement : A valid element to be moved.
- float x : The x coordinate of the destination.
- float y : The y coordinate of the destination.
- float y : The z coordinate of the destination.
- bool 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.
- bool result
Issues
- mtasa-blue #539 : Changing player position when they have a jetpack will remove the jetpack and bug when skin is changed
- mtasa-blue #529 : Player falls from bike when the bike is teleported using setElementPosition
Examples
Example 1 (Shared)
This 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
