items.lua issue and my resolution
In the current items.lua I was having issues with turning in stacks of items
I slightly modified this part and things started working as expected.
Hopefully someone will find this useful down the road.
(Nested while loop for multiple items worth different aa values was my project)
Changed if(inst.valid and trade_check[inst:GetID()] > 0)
TO if(inst.valid and trade_check[inst:GetID()] ~= nil)
-- trade_check contains item_id => qty mapping
-- for each item handed to us, check if it is in trade_check
for i = 1, 4 do
local inst = trade_return["item" .. i] -- get an item instance that was handed to us
if(inst.valid and trade_check[inst:GetID()] > 0) then -- we have a valid item and it's ID is in the trade_check map
if (inst:IsStackable()) then
while (trade_check[inst:GetID()] > 0 and inst:GetCharges() >= trade_check[inst:GetID()]) do
inst:SetCharges(inst:GetCharges() - 1) -- remove one item from the stack
trade_check[inst:GetID()] = trade_check[inst:GetID()] - 1 -- decrement the count of required items in trade_check
end
if (inst:GetCharges() > 0) then -- still have items in the stack, return the remainder
trade_return["item" .. i] = inst
else
trade_return["item" .. i] = ItemInst() -- stack empty, return nothing
end
else
trade_return["item" .. i] = ItemInst() -- remove this item from our return queue
trade_check[inst:GetID()] = trade_check[inst:GetID()] - 1 -- decrement the count of required items in trade_check
end
end
end
|