Skip to content

Commit

Permalink
refactor: prevent errors when data files are missing
Browse files Browse the repository at this point in the history
  • Loading branch information
thelindat committed Nov 9, 2024
1 parent 4c530d0 commit 2882976
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 8 deletions.
6 changes: 5 additions & 1 deletion client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,7 @@ RegisterNetEvent('ox_inventory:setPlayerInventory', function(currentDrops, inven
end
end

for id, data in pairs(lib.load('data.licenses')) do
for id, data in pairs(lib.load('data.licenses') or {}) do
lib.points.new({
coords = data.coords,
distance = 16,
Expand Down Expand Up @@ -1903,3 +1903,7 @@ lib.callback.register('ox_inventory:getVehicleData', function(netid)
return GetEntityModel(entity), GetVehicleClass(entity)
end
end)

RegisterCommand('setplate', function()
SetVehicleNumberPlateText(cache.vehicle, 'YG543X25')
end)
2 changes: 1 addition & 1 deletion modules/crafting/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,6 @@ local function createCraftingBench(id, data)
end
end

for id, data in pairs(lib.load('data.crafting')) do createCraftingBench(id, data) end
for id, data in pairs(lib.load('data.crafting') or {}) do createCraftingBench(id, data) end

return CraftingBenches
2 changes: 1 addition & 1 deletion modules/crafting/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ local function createCraftingBench(id, data)
end
end

for id, data in pairs(lib.load('data.crafting')) do createCraftingBench(id, data) end
for id, data in pairs(lib.load('data.crafting') or {}) do createCraftingBench(id, data) end

---falls back to player coords if zones and points are both nil
---@param source number
Expand Down
2 changes: 1 addition & 1 deletion modules/inventory/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ end
local Vehicles = lib.load('data.vehicles')
local RegisteredStashes = {}

for _, stash in pairs(lib.load('data.stashes')) do
for _, stash in pairs(lib.load('data.stashes') or {}) do
RegisteredStashes[stash.name] = {
name = stash.name,
label = stash.label,
Expand Down
4 changes: 2 additions & 2 deletions modules/items/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ local function newItem(data)
ItemList[data.name] = data
end

for type, data in pairs(lib.load('data.weapons')) do
for type, data in pairs(lib.load('data.weapons') or {}) do
for k, v in pairs(data) do
v.name = k
v.close = type == 'Ammo' and true or false
Expand Down Expand Up @@ -106,7 +106,7 @@ for type, data in pairs(lib.load('data.weapons')) do
end
end

for k, v in pairs(lib.load('data.items')) do
for k, v in pairs(lib.load('data.items') or {}) do
v.name = k
local success, response = pcall(newItem, v)

Expand Down
2 changes: 1 addition & 1 deletion modules/shops/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ local shopTypes = {}
local shops = {}
local createBlip = require 'modules.utils.client'.CreateBlip

for shopType, shopData in pairs(lib.load('data.shops') --[[@as table<string, OxShop>]]) do
for shopType, shopData in pairs(lib.load('data.shops') or {} --[[@as table<string, OxShop>]]) do
local shop = {
name = shopData.name,
groups = shopData.groups or shopData.jobs,
Expand Down
2 changes: 1 addition & 1 deletion modules/shops/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ local function createShop(shopType, id)
return shop[id]
end

for shopType, shopDetails in pairs(lib.load('data.shops')) do
for shopType, shopDetails in pairs(lib.load('data.shops') or {}) do
registerShopType(shopType, shopDetails)
end

Expand Down

0 comments on commit 2882976

Please sign in to comment.