[General] Use inventoryHelper.addItem() whenever possible
This fixes a significant bug where every custom potion created through regular gameplay was placed in its own slot in the player's inventory table, which – combined with the record removal logic in BasePlayer:SaveInventory() – made links to custom potions get removed prematurely. Additionally, add debug information for every item change in BasePlayer:SaveInventory()
This commit is contained in:
@@ -131,7 +131,8 @@ eventHandler.OnGUIAction = function(pid, idGui, data)
|
||||
|
||||
if item ~= nil then
|
||||
|
||||
table.insert(Players[pid].data.inventory, item)
|
||||
inventoryHelper.addItem(Players[pid].data.inventory, item.refId, item.count, item.charge,
|
||||
item.enchantmentCharge, item.soul)
|
||||
Players[pid]:LoadItemChanges({item}, enumerations.inventory.ADD)
|
||||
|
||||
-- If the item is equipped by the target, unequip it first
|
||||
@@ -1284,8 +1285,10 @@ eventHandler.OnRecordDynamic = function(pid)
|
||||
local itemArray = {}
|
||||
|
||||
for _, recordAddition in pairs(recordAdditions) do
|
||||
local item = { refId = recordAddition.id, count = 1, charge = -1, enchantmentCharge = -1 }
|
||||
table.insert(Players[pid].data.inventory, item)
|
||||
|
||||
local item = { refId = recordAddition.id, count = 1, charge = -1, enchantmentCharge = -1, soul = "" }
|
||||
inventoryHelper.addItem(Players[pid].data.inventory, item.refId, item.count, item.charge,
|
||||
item.enchantmentCharge, item.soul)
|
||||
table.insert(itemArray, item)
|
||||
|
||||
Players[pid]:AddLinkToRecord(storeType, recordAddition.id)
|
||||
|
||||
+11
-2
@@ -304,8 +304,10 @@ function BasePlayer:EndCharGen()
|
||||
|
||||
if config.shareJournal == true and WorldInstance.data.customVariables ~= nil then
|
||||
if WorldInstance.data.customVariables.deliveredCaiusPackage ~= true then
|
||||
local item = { refId = "bk_a1_1_caiuspackage", count = 1, charge = -1 }
|
||||
table.insert(self.data.inventory, item)
|
||||
local item = { refId = "bk_a1_1_caiuspackage", count = 1, charge = -1,
|
||||
enchantmentCharge = -1, soul = "" }
|
||||
inventoryHelper.addItem(self.data.inventory, item.refId, item.count, item.charge,
|
||||
item.enchantmentCharge, item.soul)
|
||||
self:LoadItemChanges({item}, enumerations.inventory.ADD)
|
||||
tes3mp.MessageBox(self.pid, -1, "Multiplayer skips over the original character generation." ..
|
||||
"\n\nAs a result, you start out with Caius Cosades' package.")
|
||||
@@ -670,6 +672,7 @@ function BasePlayer:SaveStatsDynamic()
|
||||
end
|
||||
|
||||
function BasePlayer:LoadAttributes()
|
||||
|
||||
for name, value in pairs(self.data.attributes) do
|
||||
tes3mp.SetAttributeBase(self.pid, tes3mp.GetAttributeId(name), value)
|
||||
end
|
||||
@@ -682,6 +685,7 @@ function BasePlayer:LoadAttributes()
|
||||
end
|
||||
|
||||
function BasePlayer:SaveAttributes()
|
||||
|
||||
for name in pairs(self.data.attributes) do
|
||||
|
||||
local attributeId = tes3mp.GetAttributeId(name)
|
||||
@@ -1008,6 +1012,10 @@ function BasePlayer:SaveInventory()
|
||||
soul = tes3mp.GetInventoryItemSoul(self.pid, index)
|
||||
}
|
||||
|
||||
tes3mp.LogAppend(enumerations.log.INFO, "- id: " .. item.refId .. ", count: " .. item.count ..
|
||||
", charge: " .. item.charge .. ", enchantmentCharge: " .. item.enchantmentCharge ..
|
||||
", soul: " .. item.soul)
|
||||
|
||||
if action == enumerations.inventory.SET or action == enumerations.inventory.ADD then
|
||||
|
||||
inventoryHelper.addItem(self.data.inventory, item.refId, item.count, item.charge,
|
||||
@@ -1027,6 +1035,7 @@ function BasePlayer:SaveInventory()
|
||||
item.charge, item.enchantmentCharge, item.soul)
|
||||
|
||||
if remainingItem == nil and logicHandler.IsGeneratedRecord(item.refId) then
|
||||
|
||||
local recordStore = logicHandler.GetRecordStoreByRecordId(item.refId)
|
||||
|
||||
if recordStore ~= nil then
|
||||
|
||||
Reference in New Issue
Block a user