Skip to content

Commit a816ba1

Browse files
refactor and add oop
1 parent 7de9ca5 commit a816ba1

File tree

4 files changed

+57
-20
lines changed

4 files changed

+57
-20
lines changed

Diff for: functions/Element/examples/getElementPosition.lua

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
1-
-- Find a player's position
2-
local x, y, z = getElementPosition(player)
1+
-- Create the elegy
2+
local myElegy = createVehicle(562, 1591.596680, -2495.323242, 18.098244)
3+
-- Get the vehicle's position
4+
local x, y, z = getElementPosition(myElegy)
5+
-- Create the samsite
6+
local samsite = createObject(3267, x, y, z + 3)
7+
-- Attach the samsite to the elegy
8+
attachElementToElement(samsite, myElegy, 0, 0, 0)

Diff for: functions/Element/examples/setElementPosition.lua

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
function randomPlayersToLocation(p)
2+
if not isPlayerStaff(p) then return end
3+
24
local playersOnline = getElementsByType("player")
35
local amount = #playersOnline
46

@@ -9,4 +11,24 @@ function randomPlayersToLocation(p)
911
setElementPosition(player, getElementPosition(p))
1012
end
1113
end
12-
addCommandHandler("tprandomplayers", randomPlayersToLocation)
14+
addCommandHandler("randomtp", randomPlayersToLocation)
15+
addCommandHandler("playershere", randomPlayersToLocation)
16+
17+
-- Utility function
18+
local staffACLs = {
19+
aclGetGroup("Admin"),
20+
aclGetGroup("Moderator")
21+
}
22+
23+
function isPlayerStaff(p)
24+
if isElement(p) and getElementType(p) == "player" and not isGuestAccount(getPlayerAccount(p)) then
25+
local object = getAccountName(getPlayerAccount(p))
26+
27+
for _, group in ipairs(staffACLs) do
28+
if isObjectInACLGroup("user." .. object, group) then
29+
return true
30+
end
31+
end
32+
end
33+
return false
34+
end

Diff for: functions/Element/getElementPosition.yaml

+20-13
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
shared:
1+
shared: &shared
22
name: 'getElementPosition'
3+
oop:
4+
entity: player
5+
method: getPosition
6+
variable: position
37
pair: 'setElementPosition'
48
description: |
59
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
10+
- [[player|Players]]
11+
- [[vehicle|Vehicles]]
12+
- [[object|Objects]]
13+
- [[pickup|Pickups]]
14+
- [[marker|Markers]]
15+
- [[collision shape|Collision shapes]]
16+
- [[blip|Blips]]
17+
- [[radar area|Radar areas]]
1518
returns:
1619
description: |
1720
Returns three floats indicating the position of the element, x, y and z respectively.
@@ -25,6 +28,10 @@ shared:
2528
examples:
2629
- path: 'examples/getElementPosition.lua'
2730
description: |
28-
This example shows how to obtain the position of a player.
29-
see_also:
30-
- 'category:Element functions'
31+
This example attaches a samsite on the player's vehicle.
32+
33+
server:
34+
<<: *shared
35+
36+
client:
37+
<<: *shared

Diff for: functions/Element/setElementPosition.yaml

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
shared:
22
name: 'setElementPosition'
3+
oop:
4+
entity: player
5+
method: setPosition
6+
variable: position
37
pair: 'getElementPosition'
48
description: |
59
This function sets the position of an element to the specified coordinates.
@@ -18,11 +22,9 @@ shared:
1822
examples:
1923
- path: 'examples/setElementPosition.lua'
2024
description: |
21-
This example lets you teleport 5 random players to yourself
25+
This example lets admins teleport 5 random players to themselves
2226
issues:
2327
- id: 539
2428
description: 'Changing player position when they have a jetpack will remove the jetpack and bug when skin is changed'
2529
- id: 529
26-
description: 'Player falls from bike when the bike is teleported using setElementPosition'
27-
see_also:
28-
- 'category:Element functions'
30+
description: 'Player falls from bike when the bike is teleported using setElementPosition'

0 commit comments

Comments
 (0)