Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add set & get element position funcs #1

Merged
merged 4 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions functions/Element/examples/getElementPosition.lua
Fernando-A-Rocha marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Find a player's position
local x, y, z = getElementPosition(player)
12 changes: 12 additions & 0 deletions functions/Element/examples/setElementPosition.lua
Fernando-A-Rocha marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function randomPlayersToLocation(p)
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("tprandomplayers", randomPlayersToLocation)
30 changes: 30 additions & 0 deletions functions/Element/getElementPosition.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
shared:
Fernando-A-Rocha marked this conversation as resolved.
Show resolved Hide resolved
name: 'getElementPosition'
pair: 'setElementPosition'
description: |
This function allows you to retrieve the position coordinates of an element. This can be any real world element, including:
- Players
- Vehicles
- Objects
- Pickups
- Markers
- Collision shapes
- Blips
- Radar areas
Fernando-A-Rocha marked this conversation as resolved.
Show resolved Hide resolved
- Syntax
Fernando-A-Rocha marked this conversation as resolved.
Show resolved Hide resolved
returns:
description: |
Returns three floats indicating the position of the element, x, y and z respectively.
Fernando-A-Rocha marked this conversation as resolved.
Show resolved Hide resolved
values:
- type: 'float'
name: 'x'
- type: 'float'
name: 'y'
- type: 'float'
name: 'z'
examples:
- path: 'examples/getElementPosition.lua'
description: |
This example shows how to obtain the position of a player.
Fernando-A-Rocha marked this conversation as resolved.
Show resolved Hide resolved
see_also:
- 'category:Element functions'
Fernando-A-Rocha marked this conversation as resolved.
Show resolved Hide resolved
28 changes: 28 additions & 0 deletions functions/Element/setElementPosition.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
shared:
name: 'setElementPosition'
pair: 'getElementPosition'
description: |
This function sets the position of an element to the specified coordinates.
notes:
- |
Warning: Do not use this function to spawn a [[player]]. It will cause problems with other functions like [[warpPedIntoVehicle]]. Use [[spawnPlayer]] instead.
- |
If you want to put a vehicle or player out of the water or simulate the position-resetting behaviour if CJ goes below the ground too far, then you need to retrieve a recommended coordinate on ground to place the element at. Take a look at this MTA forums post for steps in the right direction.
https://forum.mtasa.com/topic/132891-important-helprespawn-vehicle/?do=findComment&comment=1003198
returns:
description: |
Returns *true* if the function was successful, *false* otherwise.
values:
- type: 'bool'
name: 'result'
examples:
- path: 'examples/setElementPosition.lua'
description: |
This example lets you teleport 5 random players to yourself
issues:
- id: 539
description: 'Changing player position when they have a jetpack will remove the jetpack and bug when skin is changed'
- id: 529
description: 'Player falls from bike when the bike is teleported using setElementPosition'
see_also:
- 'category:Element functions'