Skip to content

Commit

Permalink
fix(server/inventory): remove invalid durability during Inventory.Load
Browse files Browse the repository at this point in the history
Some people have random durability on items when converting from linden_inventory; remove invalid data.
  • Loading branch information
thelindat committed Jan 13, 2022
1 parent b872afa commit cc1d7fc
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions modules/inventory/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,12 @@ function Inventory.Load(id, invType, owner)
for _, v in pairs(result) do
local item = Items(v.name)
if item then

-- Remove invalid durability
if v.metadata.durability and not item.durability and not item.degrade and not v.name:find('WEAPON_') then
v.metadata.durability = nil
end

local slotWeight = Inventory.SlotWeight(item, v)
weight += slotWeight
returnData[v.slot] = {name = item.name, label = item.label, weight = slotWeight, slot = v.slot, count = v.count, description = item.description, metadata = v.metadata or {}, stack = item.stack, close = item.close}
Expand Down

1 comment on commit cc1d7fc

@xrtw
Copy link
Contributor

@xrtw xrtw commented on cc1d7fc Jan 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

attempt to index a nil value (field 'metadata') 297 line
when opening trunk

[{"name":"WEAPON_COMBATPISTOL","slot":1,"count":1,"metadata":{"durability":99.8,"ammo":8,"components":[],"serial":"733343IIN466016"}},{"name":"WEAPON_PISTOL","slot":2,"count":1,"metadata":{"durability":100,"ammo":0,"components":[],"serial":"395040MOV905568"}},{"name":"ammo-9","count":33,"slot":3},{"name":"carokit","count":3,"slot":9},{"name":"radio","count":1,"slot":7},{"name":"blowpipe","count":1,"slot":6},{"name":"repairkit","count":2,"slot":12}]

Please sign in to comment.