Skip to content

Commit

Permalink
refactor and add oop
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando-A-Rocha committed Oct 11, 2024
1 parent 7de9ca5 commit a816ba1
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 20 deletions.
10 changes: 8 additions & 2 deletions functions/Element/examples/getElementPosition.lua
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
-- Find a player's position
local x, y, z = getElementPosition(player)
-- Create the elegy
local myElegy = createVehicle(562, 1591.596680, -2495.323242, 18.098244)
-- Get the vehicle's position
local x, y, z = getElementPosition(myElegy)
-- Create the samsite
local samsite = createObject(3267, x, y, z + 3)
-- Attach the samsite to the elegy
attachElementToElement(samsite, myElegy, 0, 0, 0)
24 changes: 23 additions & 1 deletion functions/Element/examples/setElementPosition.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
function randomPlayersToLocation(p)
if not isPlayerStaff(p) then return end

local playersOnline = getElementsByType("player")
local amount = #playersOnline

Expand All @@ -9,4 +11,24 @@ function randomPlayersToLocation(p)
setElementPosition(player, getElementPosition(p))
end
end
addCommandHandler("tprandomplayers", randomPlayersToLocation)
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
33 changes: 20 additions & 13 deletions functions/Element/getElementPosition.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
shared:
shared: &shared
name: 'getElementPosition'
oop:
entity: player
method: getPosition
variable: position
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
- Syntax
- [[player|Players]]
- [[vehicle|Vehicles]]
- [[object|Objects]]
- [[pickup|Pickups]]
- [[marker|Markers]]
- [[collision shape|Collision shapes]]
- [[blip|Blips]]
- [[radar area|Radar areas]]
returns:
description: |
Returns three floats indicating the position of the element, x, y and z respectively.
Expand All @@ -25,6 +28,10 @@ shared:
examples:
- path: 'examples/getElementPosition.lua'
description: |
This example shows how to obtain the position of a player.
see_also:
- 'category:Element functions'
This example attaches a samsite on the player's vehicle.
server:
<<: *shared

client:
<<: *shared
10 changes: 6 additions & 4 deletions functions/Element/setElementPosition.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
shared:
name: 'setElementPosition'
oop:
entity: player
method: setPosition
variable: position
pair: 'getElementPosition'
description: |
This function sets the position of an element to the specified coordinates.
Expand All @@ -18,11 +22,9 @@ shared:
examples:
- path: 'examples/setElementPosition.lua'
description: |
This example lets you teleport 5 random players to yourself
This example lets admins teleport 5 random players to themselves
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'
description: 'Player falls from bike when the bike is teleported using setElementPosition'

0 comments on commit a816ba1

Please sign in to comment.