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

Commit

Permalink
fix: load postals file with API < 4
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanctech committed Oct 30, 2024
1 parent e9a27d5 commit a0689d4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
33 changes: 17 additions & 16 deletions 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(), ('/plugins/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(), ('plugins/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 Down
2 changes: 1 addition & 1 deletion postals/version_postals.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.7.0",
"version": "1.7.1",
"check_url": "https://raw.githubusercontent.com/Sonoran-Software/sonoran_postals/master/postals/version_postals.json",
"download_url": "https://github.com/Sonoran-Software/sonoran_postals/",
"configVersion": "1.3.0",
Expand Down

0 comments on commit a0689d4

Please sign in to comment.