From 44658dc370300b7aafb3111c6881fd13d297118d Mon Sep 17 00:00:00 2001 From: Fernando-A-Rocha Date: Thu, 10 Oct 2024 00:47:20 +0100 Subject: [PATCH 1/3] test add set & get element position funcs --- .../Element/examples/getElementPosition.lua | 2 ++ .../Element/examples/setElementPosition.lua | 12 ++++++++ functions/Element/getElementPosition.yaml | 30 +++++++++++++++++++ functions/Element/setElementPosition.yaml | 23 ++++++++++++++ 4 files changed, 67 insertions(+) create mode 100644 functions/Element/examples/getElementPosition.lua create mode 100644 functions/Element/examples/setElementPosition.lua create mode 100644 functions/Element/getElementPosition.yaml create mode 100644 functions/Element/setElementPosition.yaml diff --git a/functions/Element/examples/getElementPosition.lua b/functions/Element/examples/getElementPosition.lua new file mode 100644 index 0000000..ba2f64a --- /dev/null +++ b/functions/Element/examples/getElementPosition.lua @@ -0,0 +1,2 @@ +-- Find a player's position +local x, y, z = getElementPosition(player) diff --git a/functions/Element/examples/setElementPosition.lua b/functions/Element/examples/setElementPosition.lua new file mode 100644 index 0000000..b8eaaaa --- /dev/null +++ b/functions/Element/examples/setElementPosition.lua @@ -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) diff --git a/functions/Element/getElementPosition.yaml b/functions/Element/getElementPosition.yaml new file mode 100644 index 0000000..cc71750 --- /dev/null +++ b/functions/Element/getElementPosition.yaml @@ -0,0 +1,30 @@ +shared: + 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 + - Syntax + returns: + description: | + Returns three floats indicating the position of the element, x, y and z respectively. + 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. + see_also: + - 'category:Element functions' diff --git a/functions/Element/setElementPosition.yaml b/functions/Element/setElementPosition.yaml new file mode 100644 index 0000000..4537af0 --- /dev/null +++ b/functions/Element/setElementPosition.yaml @@ -0,0 +1,23 @@ +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 + see_also: + - 'category:Element functions' From 4d3a8f889422de8e0048fef6ebb316a5f7ef4ae0 Mon Sep 17 00:00:00 2001 From: Fernando-A-Rocha Date: Thu, 10 Oct 2024 00:50:08 +0100 Subject: [PATCH 2/3] add issues to setElementPosition --- functions/Element/setElementPosition.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/functions/Element/setElementPosition.yaml b/functions/Element/setElementPosition.yaml index 4537af0..cd4ef2c 100644 --- a/functions/Element/setElementPosition.yaml +++ b/functions/Element/setElementPosition.yaml @@ -19,5 +19,10 @@ shared: - 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' From a816ba12d3c3a815978996c653ff02cb13124da1 Mon Sep 17 00:00:00 2001 From: Fernando-A-Rocha Date: Fri, 11 Oct 2024 09:06:01 +0100 Subject: [PATCH 3/3] 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