Skip to content
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

gps: Added export functions for custom logic #517

Merged
merged 21 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
25d963b
playerblips: Fixed that the resource "playercolors" should be activat…
T-MaxWiese-T Apr 30, 2024
6d2f7fe
Merge branch 'multitheftauto:master' into master
T-MaxWiese-T May 10, 2024
fe7bbd2
Playercolors should only be recommended if a player uses a default na…
T-MaxWiese-T May 10, 2024
84c408e
Default playerblip color should be the default nametag color
T-MaxWiese-T May 10, 2024
a5aaee7
Removed unnecessary text
T-MaxWiese-T May 10, 2024
7f81980
Added debug message if use_team_colors and use_nametag_colors is false
T-MaxWiese-T May 10, 2024
8c330de
Improved text
T-MaxWiese-T May 10, 2024
dedeef6
Fixed debug message for when useTeams and useNametags is false was di…
T-MaxWiese-T May 10, 2024
7d41d5e
If query (useTeams or useNametags) logic restored
T-MaxWiese-T May 10, 2024
e0655df
If query adjusted if the first parameter is nil. Variable name adjust…
T-MaxWiese-T May 10, 2024
8708982
Resource name should only be queried if it is required
T-MaxWiese-T May 15, 2024
8bd5801
Merge branch 'master' into master
Dutchman101 May 23, 2024
cdbbd0b
Merge branch 'multitheftauto:master' into master
T-MaxWiese-T Jun 30, 2024
beed506
Merge branch 'multitheftauto:master' into master
T-MaxWiese-T Jul 11, 2024
1aa756a
Added description and new export functions
T-MaxWiese-T Jul 14, 2024
544de16
Check whether parameters can be converted to numbers and convert them
T-MaxWiese-T Jul 14, 2024
bf5c17d
Check whether parameters can be converted to numbers and convert them
T-MaxWiese-T Jul 14, 2024
79861c7
Added spacing in the text in some places
T-MaxWiese-T Jul 14, 2024
8f682df
Fixed warning that posX and posY was defined before
T-MaxWiese-T Jul 14, 2024
6321952
Fixed spacing
T-MaxWiese-T Jul 14, 2024
85c553f
Few text improvements in meta.xml
T-MaxWiese-T Jul 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions [gameplay]/gps/gps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,19 @@ local function calculatePath(db, nodeFrom, nodeTo)
end

function calculatePathByCoords(x1, y1, z1, x2, y2, z2)
return calculatePath(vehicleNodes, findNodeClosestToPoint(vehicleNodes, x1, y1, z1), findNodeClosestToPoint(vehicleNodes, x2, y2, z2))
if not tonumber(x1) or not tonumber(y1) or not tonumber(x2) or not tonumber(y2) then
return false
end
return calculatePath(vehicleNodes, findNodeClosestToPoint(vehicleNodes, tonumber(x1), tonumber(y1), tonumber(z1)),
findNodeClosestToPoint(vehicleNodes, tonumber(x2), tonumber(y2), tonumber(z2)))
end

function calculatePathByNodeIDs(node1, node2)
node1 = getNodeByID(vehicleNodes, node1)
node2 = getNodeByID(vehicleNodes, node2)
if not tonumber(node1) or not tonumber(node2) then
return false
end
node1 = getNodeByID(vehicleNodes, tonumber(node1))
node2 = getNodeByID(vehicleNodes, tonumber(node2))
if node1 and node2 then
return calculatePath(vehicleNodes, node1, node2)
else
Expand Down
11 changes: 7 additions & 4 deletions [gameplay]/gps/linedrawer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ function removeLinePoints ( )
end

function addLinePoint ( posX, posY )
if not tonumber(posX) and not tonumber(poxY) then
return false
end
-- Calculate the row and column of the radar tile we will be targeting
local row = 11 - math.floor ( ( posY + 3000 ) / 500 )
local col = math.floor ( ( posX + 3000 ) / 500 )
local row = 11 - math.floor ( ( tonumber(posY) + 3000 ) / 500 )
local col = math.floor ( ( tonumber(posX) + 3000 ) / 500 )

-- If it's off the map, don't bother
if row < 0 or row > 11 or col < 0 or col > 11 then
Expand All @@ -31,8 +34,8 @@ function addLinePoint ( posX, posY )
local startY = 3000 - row * 500

-- Now get the tile position (We don't want to calculate this for every point on render)
local tileX = ( posX - startX ) / 500 * OVERLAY_WIDTH
local tileY = ( startY - posY ) / 500 * OVERLAY_HEIGHT
local tileX = ( tonumber(posX) - startX ) / 500 * OVERLAY_WIDTH
local tileY = ( startY - tonumber(posY) ) / 500 * OVERLAY_HEIGHT

-- Now calulcate the ID and get the name of the tile
local id = col + row * 12
Expand Down
19 changes: 18 additions & 1 deletion [gameplay]/gps/meta.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<meta>
<info author="arc_" type="script" version="1.0.0"/>
<info author="arc_" type="script" version="1.1.0" description="Calculates and displays the quickest road path between two points/nodes on the map. Commands: /path node1 node2 /path2 x y [z]. Resource contains export functions for custom logic."/>

<script src="util.lua" type="client"/>
<script src="client.lua" type="client"/>
Expand All @@ -10,4 +10,21 @@
<script src="vehiclenodes.lua" type="server"/>
<script src="MinHeap.lua" type="server"/>
<script src="gps.lua" type="server"/>

<export function="calculatePathByCoords" type="server"/> <!--calculatePathByCoords(float x1, float y1, float [z1], float x2,
float y2, float [z2])
Function returns a table with the ID (int), neighbours (table), x (float), y (float), z (float) otherwise false. So the
original GTA vehicle node points in ascending order from point A to point B.-->
<export function="calculatePathByNodeIDs" type="server"/> <!--calculatePathByNodeIDs(int node1, int node2)
Function returns a table with the ID (int), neighbours (table), x (float), y (float), z (float) otherwise false. So the
original GTA vehicle node points in ascending order from node A to node B.-->
<export function="addLinePoint" type="client"/> <!--addLinePoint(float posX, float posY)
Function returns true if successful otherwise false.
Draws the path on the client HUD mini map in ascending order. For example, if you use the table returned by the calculatePathByCoords
or calculatePathByNodeIDs function.
If you add your own line points points they must be very close to each other, otherwise the path will not be drawn properly.-->
<export function="removeLinePoints" type="client"/> <!--removeLinePoints()
Function returns nil.
Removes the line points of the addLinePoint function respectively the drawn lines of the client HUD mini map.
This can be used, for example, when the target node point has been reached or a player gets out of the vehicle.-->
</meta>