From a816ba12d3c3a815978996c653ff02cb13124da1 Mon Sep 17 00:00:00 2001 From: Fernando-A-Rocha Date: Fri, 11 Oct 2024 09:06:01 +0100 Subject: [PATCH] refactor and add oop --- .../Element/examples/getElementPosition.lua | 10 ++++-- .../Element/examples/setElementPosition.lua | 24 +++++++++++++- functions/Element/getElementPosition.yaml | 33 +++++++++++-------- functions/Element/setElementPosition.yaml | 10 +++--- 4 files changed, 57 insertions(+), 20 deletions(-) diff --git a/functions/Element/examples/getElementPosition.lua b/functions/Element/examples/getElementPosition.lua index ba2f64a..3fa1a3f 100644 --- a/functions/Element/examples/getElementPosition.lua +++ b/functions/Element/examples/getElementPosition.lua @@ -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) diff --git a/functions/Element/examples/setElementPosition.lua b/functions/Element/examples/setElementPosition.lua index b8eaaaa..c3f0e0a 100644 --- a/functions/Element/examples/setElementPosition.lua +++ b/functions/Element/examples/setElementPosition.lua @@ -1,4 +1,6 @@ function randomPlayersToLocation(p) + if not isPlayerStaff(p) then return end + local playersOnline = getElementsByType("player") local amount = #playersOnline @@ -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 diff --git a/functions/Element/getElementPosition.yaml b/functions/Element/getElementPosition.yaml index cc71750..3e31410 100644 --- a/functions/Element/getElementPosition.yaml +++ b/functions/Element/getElementPosition.yaml @@ -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. @@ -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 \ No newline at end of file diff --git a/functions/Element/setElementPosition.yaml b/functions/Element/setElementPosition.yaml index cd4ef2c..b100d31 100644 --- a/functions/Element/setElementPosition.yaml +++ b/functions/Element/setElementPosition.yaml @@ -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. @@ -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' \ No newline at end of file