Skip to content

Commit 44658dc

Browse files
test add set & get element position funcs
1 parent 1a9f868 commit 44658dc

File tree

4 files changed

+67
-0
lines changed

4 files changed

+67
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- Find a player's position
2+
local x, y, z = getElementPosition(player)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function randomPlayersToLocation(p)
2+
local playersOnline = getElementsByType("player")
3+
local amount = #playersOnline
4+
5+
if amount == 0 then return end
6+
7+
for index = 1,(amount > 5 and 5 or amount) do
8+
local player = playersOnline[index]
9+
setElementPosition(player, getElementPosition(p))
10+
end
11+
end
12+
addCommandHandler("tprandomplayers", randomPlayersToLocation)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
shared:
2+
name: 'getElementPosition'
3+
pair: 'setElementPosition'
4+
description: |
5+
This function allows you to retrieve the position coordinates of an element. This can be any real world element, including:
6+
- Players
7+
- Vehicles
8+
- Objects
9+
- Pickups
10+
- Markers
11+
- Collision shapes
12+
- Blips
13+
- Radar areas
14+
- Syntax
15+
returns:
16+
description: |
17+
Returns three floats indicating the position of the element, x, y and z respectively.
18+
values:
19+
- type: 'float'
20+
name: 'x'
21+
- type: 'float'
22+
name: 'y'
23+
- type: 'float'
24+
name: 'z'
25+
examples:
26+
- path: 'examples/getElementPosition.lua'
27+
description: |
28+
This example shows how to obtain the position of a player.
29+
see_also:
30+
- 'category:Element functions'
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
shared:
2+
name: 'setElementPosition'
3+
pair: 'getElementPosition'
4+
description: |
5+
This function sets the position of an element to the specified coordinates.
6+
notes:
7+
- |
8+
Warning: Do not use this function to spawn a [[player]]. It will cause problems with other functions like [[warpPedIntoVehicle]]. Use [[spawnPlayer]] instead.
9+
- |
10+
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.
11+
https://forum.mtasa.com/topic/132891-important-helprespawn-vehicle/?do=findComment&comment=1003198
12+
returns:
13+
description: |
14+
Returns *true* if the function was successful, *false* otherwise.
15+
values:
16+
- type: 'bool'
17+
name: 'result'
18+
examples:
19+
- path: 'examples/setElementPosition.lua'
20+
description: |
21+
This example lets you teleport 5 random players to yourself
22+
see_also:
23+
- 'category:Element functions'

0 commit comments

Comments
 (0)