diff --git a/media/lua/client/Handlers/TOC_AmputationHandler.lua b/media/lua/client/Handlers/TOC_AmputationHandler.lua index 77bfdc0..08a1426 100644 --- a/media/lua/client/Handlers/TOC_AmputationHandler.lua +++ b/media/lua/client/Handlers/TOC_AmputationHandler.lua @@ -75,7 +75,7 @@ function AmputationHandler:execute() ModDataHandler.GetInstance():setCutLimb(self.limbName, false, false, false, surgeonFactor) -- Give the player the correct amputation item - self:deleteOldAmputationItem() + AmputationHandler.DeleteOldAmputationItem(self.patient, self.limbName) self:spawnAmputationItem() end @@ -92,16 +92,22 @@ end --* Amputation Items *-- ---Search and deletes an old amputation clothing item ----@private -function AmputationHandler:deleteOldAmputationItem() - local side = CommonMethods.GetSide(self.limbName) - +---@param player IsoPlayer +---@param limbName string +function AmputationHandler.DeleteOldAmputationItem(player, limbName) + local side = CommonMethods.GetSide(limbName) for partName, _ in pairs(StaticData.PARTS_STRINGS) do local othLimbName = partName .. "_" .. side local othClothingItemName = StaticData.AMPUTATION_CLOTHING_ITEM_BASE .. othLimbName - local othClothingItem = self.patient:getInventory():FindAndReturn(othClothingItemName) - if othClothingItem then - self.patient:getInventory():Remove(othClothingItem) -- It accepts it as an Item, not a string + + -- TODO FindAndReturn could return an ArrayList. We need to check for that + + local othClothingItem = player:getInventory():FindAndReturn(othClothingItemName) + + ---@cast othClothingItem InventoryItem + if othClothingItem and instanceof(othClothingItem, "InventoryItem") then + player:removeWornItem(othClothingItem) + player:getInventory():Remove(othClothingItem) -- Can be a InventoryItem too.. I guess? todo check it print("TOC: found and deleted " .. othClothingItemName) return end diff --git a/media/lua/client/Handlers/TOC_PlayerHandler.lua b/media/lua/client/Handlers/TOC_PlayerHandler.lua index 48ba547..abe585a 100644 --- a/media/lua/client/Handlers/TOC_PlayerHandler.lua +++ b/media/lua/client/Handlers/TOC_PlayerHandler.lua @@ -25,6 +25,10 @@ function PlayerHandler.InitializePlayer(_, playerObj, isForced) -- Since isForced is used to reset an existing player data, we're gonna clean their ISHealthPanel table too if isForced then ISHealthPanel.highestAmputations = {} + + -- TODO Hacky way to check both limbs + AmputationHandler.DeleteOldAmputationItem(playerObj, "Hand_L") + AmputationHandler.DeleteOldAmputationItem(playerObj, "Hand_R") end end