File tree Expand file tree Collapse file tree 3 files changed +40
-3
lines changed
Expand file tree Collapse file tree 3 files changed +40
-3
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ lua54 "yes"
1212
1313author ' DevBlocky'
1414description ' This script displays the nearest postal next to map, and allows you to navigate to specific postal codes'
15- version ' 1.5.2 '
15+ version ' 1.5.3 '
1616url ' https://github.com/DevBlocky/nearest-postal'
1717
1818client_scripts {
@@ -35,3 +35,5 @@ file(postalFile)
3535postal_file (postalFile )
3636
3737file ' version.json'
38+
39+ server_export ' getPostalServer'
Original file line number Diff line number Diff line change @@ -22,3 +22,38 @@ CHANGELOG: %s
2222 end , ' GET' )
2323 end
2424end )
25+
26+ -- add functionality to get postals server side from a vec3
27+
28+ local postals = nil
29+ Citizen .CreateThread (function ()
30+ postals = LoadResourceFile (GetCurrentResourceName (), GetResourceMetadata (GetCurrentResourceName (), ' postal_file' ))
31+ postals = json .decode (postals )
32+ for i , postal in ipairs (postals ) do
33+ postals [i ] = {vec (postal .x , postal .y ), code = postal .code }
34+ end
35+ end )
36+
37+ local function getPostalServer (coords )
38+ while postals == nil do
39+ Wait (1 )
40+ end
41+ local _total = # postals
42+ local _nearestIndex , _nearestD
43+ coords = vec (coords [1 ], coords [2 ])
44+
45+ for i = 1 , _total do
46+ local D = # (coords - postals [i ][1 ])
47+ if not _nearestD or D < _nearestD then
48+ _nearestIndex = i
49+ _nearestD = D
50+ end
51+ end
52+ local _code = postals [_nearestIndex ].code
53+ local nearest = {code = _code , dist = _nearestD }
54+ return nearest or nil
55+ end
56+
57+ exports (' getPostalServer' , function (coords )
58+ return getPostalServer (coords )
59+ end )
Original file line number Diff line number Diff line change 11{
2- "version" : " 1.5.2 " ,
3- "changelog" : " Bugfixes and performance improvements "
2+ "version" : " 1.5.3 " ,
3+ "changelog" : " Add ability to get postals from vec3 server sided "
44}
You can’t perform that action at this time.
0 commit comments