Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Commit

Permalink
tweak: Update sv_postals in occordance to newest HF
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan2139 committed Nov 5, 2024
1 parent 90e5612 commit df92606
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions sonorancad/submodules/postals/sv_postals.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ CreateThread(function()
errorLog(('[postals] The configured postals resource (%s) is in a bad state (%s). Please check it.'):format(pluginConfig.nearestPostalResourceName, state))
shouldStop = true
end
else
postalFile = LoadResourceFile(pluginConfig.nearestPostalResourceName, GetResourceMetadata(pluginConfig.nearestPostalResourceName, 'postal_file'))
end
elseif pluginConfig.mode and pluginConfig.mode == 'file' then
local postalFile = LoadResourceFile(GetCurrentResourceName(), ('/submodules/postals/%s'):format(pluginConfig.customPostalCodesFile))
Expand All @@ -35,13 +37,22 @@ CreateThread(function()
shouldStop = true
end
end
if postalFile == nil then
errorLog('Failed to open postals file for reading.')
shouldStop = true
end
if shouldStop then
pluginConfig.enabled = false
pluginConfig.disableReason = 'postal resource incorrect'
errorLog('Force disabling plugin to prevent client errors.')
return
end

postals = json.decode(postalFile)
for i, postal in ipairs(postals) do
postals[i] = {vec(postal.x, postal.y), code = postal.code}
end

PostalsCache = {}

RegisterNetEvent('getShouldSendPostal')
Expand All @@ -67,30 +78,20 @@ CreateThread(function()
registerApiType('SET_POSTALS', 'general')

CreateThread(function()
while Config.apiVersion == -1 do
while Config.apiVersion == -1 or postals == nil do
Wait(1000)
end
if Config.apiVersion < 4 or not Config.apiSendEnabled then
return
end
if pluginConfig.customPostalCodesFile ~= '' and pluginConfig.customPostalCodesFile ~= nil then
postalFile = LoadResourceFile(GetCurrentResourceName(), ('submodules/postals/%s'):format(pluginConfig.customPostalCodesFile))
else
postalFile = LoadResourceFile(pluginConfig.nearestPostalResourceName, GetResourceMetadata(pluginConfig.nearestPostalResourceName, 'postal_file'))
end
if postalFile == nil then
errorLog('Failed to open postals file for reading.')
else
performApiRequest(postalFile, 'SET_POSTALS', function()
end)
postals = json.decode(postalFile)
for i, postal in ipairs(postals) do
postals[i] = {vec(postal.x, postal.y), code = postal.code}
end
end
performApiRequest(postalFile, 'SET_POSTALS', function()
end)
end)

function getPostalFromVector3(coords)
if not coords or postals == nil then
return nil
end
local _total = #postals
local _nearestIndex, _nearestD
coords = vector2(coords.x, coords.y)
Expand All @@ -113,4 +114,4 @@ CreateThread(function()
end

end)
end)
end)

0 comments on commit df92606

Please sign in to comment.