|
1 | 1 | -- version check |
2 | 2 | Citizen.CreateThread(function() |
3 | | - local vRaw = LoadResourceFile(GetCurrentResourceName(), 'version.json') |
4 | | - if vRaw and config.versionCheck then |
5 | | - local v = json.decode(vRaw) |
6 | | - local url = 'https://raw.githubusercontent.com/DevBlocky/nearest-postal/master/version.json' |
7 | | - PerformHttpRequest(url, function(code, res) |
8 | | - if code == 200 then |
9 | | - local rv = json.decode(res) |
10 | | - if rv.version ~= v.version then |
11 | | - print(([[ |
| 3 | + local vRaw = LoadResourceFile(GetCurrentResourceName(), 'version.json') |
| 4 | + if vRaw and config.versionCheck then |
| 5 | + local v = json.decode(vRaw) |
| 6 | + local url = 'https://raw.githubusercontent.com/DevBlocky/nearest-postal/master/version.json' |
| 7 | + PerformHttpRequest(url, function(code, res) |
| 8 | + if code == 200 then |
| 9 | + local rv = json.decode(res) |
| 10 | + if rv.version ~= v.version then |
| 11 | + print(([[ |
12 | 12 | ------------------------------------------------------- |
13 | 13 | nearest-postal |
14 | 14 | UPDATE: %s AVAILABLE |
15 | 15 | CHANGELOG: %s |
16 | 16 | ------------------------------------------------------- |
17 | 17 | ]]):format(rv.version, rv.changelog)) |
18 | | - end |
19 | | - else |
20 | | - print('nearest-postal was unable to check the version') |
21 | | - end |
22 | | - end, 'GET') |
23 | | - end |
| 18 | + end |
| 19 | + else |
| 20 | + print('nearest-postal was unable to check the version') |
| 21 | + end |
| 22 | + end, 'GET') |
| 23 | + end |
24 | 24 | end) |
25 | 25 |
|
26 | 26 | -- add functionality to get postals server side from a vec3 |
27 | 27 |
|
28 | 28 | local postals = nil |
29 | 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 |
| 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 | 35 | end) |
36 | 36 |
|
37 | 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]) |
| 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 | 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 |
| 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 | 55 | end |
56 | 56 |
|
57 | 57 | exports('getPostalServer', function(coords) |
58 | | - return getPostalServer(coords) |
| 58 | + return getPostalServer(coords) |
59 | 59 | end) |
0 commit comments