-
Notifications
You must be signed in to change notification settings - Fork 10
Add set & get element position funcs #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
44658dc
test add set & get element position funcs
Fernando-A-Rocha 4d3a8f8
add issues to setElementPosition
Fernando-A-Rocha 7de9ca5
Merge remote-tracking branch 'upstream/main' into test-funcs1
Fernando-A-Rocha a816ba1
refactor and add oop
Fernando-A-Rocha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
-- 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
function randomPlayersToLocation(p) | ||
if not isPlayerStaff(p) then return end | ||
|
||
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("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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
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: | ||
- [[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. | ||
values: | ||
- type: 'float' | ||
name: 'x' | ||
- type: 'float' | ||
name: 'y' | ||
- type: 'float' | ||
name: 'z' | ||
examples: | ||
- path: 'examples/getElementPosition.lua' | ||
description: | | ||
This example attaches a samsite on the player's vehicle. | ||
|
||
server: | ||
<<: *shared | ||
|
||
client: | ||
<<: *shared |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
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. | ||
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 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' |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.