Skip to content

Commit e536682

Browse files
authored
Merge pull request #14 from Jordan2139/master
v1.5.3 - Add ability to get postals server sided from vec3
2 parents 0aa2e7d + e1919cb commit e536682

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

fxmanifest.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ lua54 "yes"
1212

1313
author 'DevBlocky'
1414
description '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'
1616
url 'https://github.com/DevBlocky/nearest-postal'
1717

1818
client_scripts {
@@ -35,3 +35,5 @@ file(postalFile)
3535
postal_file(postalFile)
3636

3737
file 'version.json'
38+
39+
server_export 'getPostalServer'

sv.lua

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,38 @@ CHANGELOG: %s
2222
end, 'GET')
2323
end
2424
end)
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)

version.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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
}

0 commit comments

Comments
 (0)