Skip to content

Commit

Permalink
Merge pull request #14 from Jordan2139/master
Browse files Browse the repository at this point in the history
v1.5.3 - Add ability to get postals server sided from vec3
  • Loading branch information
DevBlocky authored Feb 7, 2023
2 parents 0aa2e7d + e1919cb commit e536682
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
4 changes: 3 additions & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ lua54 "yes"

author 'DevBlocky'
description 'This script displays the nearest postal next to map, and allows you to navigate to specific postal codes'
version '1.5.2'
version '1.5.3'
url 'https://github.com/DevBlocky/nearest-postal'

client_scripts {
Expand All @@ -35,3 +35,5 @@ file(postalFile)
postal_file(postalFile)

file 'version.json'

server_export 'getPostalServer'
35 changes: 35 additions & 0 deletions sv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,38 @@ CHANGELOG: %s
end, 'GET')
end
end)

-- add functionality to get postals server side from a vec3

local postals = nil
Citizen.CreateThread(function()
postals = LoadResourceFile(GetCurrentResourceName(), GetResourceMetadata(GetCurrentResourceName(), 'postal_file'))
postals = json.decode(postals)
for i, postal in ipairs(postals) do
postals[i] = {vec(postal.x, postal.y), code = postal.code}
end
end)

local function getPostalServer(coords)
while postals == nil do
Wait(1)
end
local _total = #postals
local _nearestIndex, _nearestD
coords = vec(coords[1], coords[2])

for i = 1, _total do
local D = #(coords - postals[i][1])
if not _nearestD or D < _nearestD then
_nearestIndex = i
_nearestD = D
end
end
local _code = postals[_nearestIndex].code
local nearest = {code = _code, dist = _nearestD}
return nearest or nil
end

exports('getPostalServer', function(coords)
return getPostalServer(coords)
end)
4 changes: 2 additions & 2 deletions version.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version": "1.5.2",
"changelog": "Bugfixes and performance improvements"
"version": "1.5.3",
"changelog": "Add ability to get postals from vec3 server sided"
}

0 comments on commit e536682

Please sign in to comment.