Skip to content

Commit

Permalink
refactor(server/items): remove non-string specialAmmo from weapons
Browse files Browse the repository at this point in the history
  • Loading branch information
thelindat committed Apr 8, 2023
1 parent 1d438a3 commit da67cbc
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions modules/items/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ if not lib then return end
local Items = {}
local ItemList = require 'modules.items.shared' --[[@as { [string]: OxServerItem }]]
local Utils = require 'modules.utils.server'

TriggerEvent('ox_inventory:itemList', ItemList)

Items.containers = require 'modules.items.containers'
Expand Down Expand Up @@ -361,30 +361,36 @@ function Items.CheckMetadata(metadata, item, name, ostime)
metadata = setItemDurability(item, metadata)
end

if metadata.components then
if table.type(metadata.components) == 'array' then
for i = #metadata.components, 1, -1 do
if not ItemList[metadata.components[i]] then
table.remove(metadata.components, i)
if item.weapon then
if metadata.components then
if table.type(metadata.components) == 'array' then
for i = #metadata.components, 1, -1 do
if not ItemList[metadata.components[i]] then
table.remove(metadata.components, i)
end
end
end
else
local components = {}
local size = 0
else
local components = {}
local size = 0

for _, component in pairs(metadata.components) do
if component and ItemList[component] then
size += 1
components[size] = component
for _, component in pairs(metadata.components) do
if component and ItemList[component] then
size += 1
components[size] = component
end
end

metadata.components = components
end
end

metadata.components = components
if metadata.serial and item.throwable then
metadata.serial = nil
end
end

if metadata.serial and item.weapon and not item.ammoname then
metadata.serial = nil
if item.metadata.specialAmmo and type(item.metadata.specialAmmo) ~= 'string' then
item.metadata.specialAmmo = nil
end
end

return metadata
Expand Down

0 comments on commit da67cbc

Please sign in to comment.