Skip to content

Commit 537d92d

Browse files
authored
gps: Added export functions for custom logic (#517)
1 parent 3e0166d commit 537d92d

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

[gameplay]/gps/gps.lua

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,19 @@ local function calculatePath(db, nodeFrom, nodeTo)
9494
end
9595

9696
function calculatePathByCoords(x1, y1, z1, x2, y2, z2)
97-
return calculatePath(vehicleNodes, findNodeClosestToPoint(vehicleNodes, x1, y1, z1), findNodeClosestToPoint(vehicleNodes, x2, y2, z2))
97+
if not tonumber(x1) or not tonumber(y1) or not tonumber(x2) or not tonumber(y2) then
98+
return false
99+
end
100+
return calculatePath(vehicleNodes, findNodeClosestToPoint(vehicleNodes, tonumber(x1), tonumber(y1), tonumber(z1)),
101+
findNodeClosestToPoint(vehicleNodes, tonumber(x2), tonumber(y2), tonumber(z2)))
98102
end
99103

100104
function calculatePathByNodeIDs(node1, node2)
101-
node1 = getNodeByID(vehicleNodes, node1)
102-
node2 = getNodeByID(vehicleNodes, node2)
105+
if not tonumber(node1) or not tonumber(node2) then
106+
return false
107+
end
108+
node1 = getNodeByID(vehicleNodes, tonumber(node1))
109+
node2 = getNodeByID(vehicleNodes, tonumber(node2))
103110
if node1 and node2 then
104111
return calculatePath(vehicleNodes, node1, node2)
105112
else

[gameplay]/gps/linedrawer.lua

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ function removeLinePoints ( )
1717
end
1818

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

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

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

3740
-- Now calulcate the ID and get the name of the tile
3841
local id = col + row * 12

[gameplay]/gps/meta.xml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<meta>
2-
<info author="arc_" type="script" version="1.0.0"/>
2+
<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."/>
33

44
<script src="util.lua" type="client"/>
55
<script src="client.lua" type="client"/>
@@ -10,4 +10,21 @@
1010
<script src="vehiclenodes.lua" type="server"/>
1111
<script src="MinHeap.lua" type="server"/>
1212
<script src="gps.lua" type="server"/>
13+
14+
<export function="calculatePathByCoords" type="server"/> <!--calculatePathByCoords(float x1, float y1, float [z1], float x2,
15+
float y2, float [z2])
16+
Function returns a table with the ID (int), neighbours (table), x (float), y (float), z (float) otherwise false. So the
17+
original GTA vehicle node points in ascending order from point A to point B.-->
18+
<export function="calculatePathByNodeIDs" type="server"/> <!--calculatePathByNodeIDs(int node1, int node2)
19+
Function returns a table with the ID (int), neighbours (table), x (float), y (float), z (float) otherwise false. So the
20+
original GTA vehicle node points in ascending order from node A to node B.-->
21+
<export function="addLinePoint" type="client"/> <!--addLinePoint(float posX, float posY)
22+
Function returns true if successful otherwise false.
23+
Draws the path on the client HUD mini map in ascending order. For example, if you use the table returned by the calculatePathByCoords
24+
or calculatePathByNodeIDs function.
25+
If you add your own line points points they must be very close to each other, otherwise the path will not be drawn properly.-->
26+
<export function="removeLinePoints" type="client"/> <!--removeLinePoints()
27+
Function returns nil.
28+
Removes the line points of the addLinePoint function respectively the drawn lines of the client HUD mini map.
29+
This can be used, for example, when the target node point has been reached or a player gets out of the vehicle.-->
1330
</meta>

0 commit comments

Comments
 (0)