diff --git a/eid_api.lua b/eid_api.lua index 1e25ce5b..3cded775 100644 --- a/eid_api.lua +++ b/eid_api.lua @@ -1674,14 +1674,8 @@ EID.PlayerItemInteractions = {} EID.RecentlyTouchedItems = {} local hadQueuedItem = {} function EID:evaluateQueuedItems() - --initialize the interactions table for all players if it isn't already - for i = 0, game:GetNumPlayers() - 1 do - if not EID.PlayerItemInteractions[i] then - EID.PlayerItemInteractions[i] = {LastTouch = 0, actives = {}, pills = {}, altActives = {}, altPills = {}, pickupHistory = {}, altPickupHistory = {}} - end - EID.RecentlyTouchedItems[i] = EID.RecentlyTouchedItems[i] or {} - end for i = 0, game:GetNumPlayers() - 1 do + EID:InitItemInteractionIfAbsent(i) local player = Isaac.GetPlayer(i) if player.QueuedItem then -- Refresh our descriptions upon a queued passive item being added to a player @@ -1703,7 +1697,6 @@ function EID:evaluateQueuedItems() -- A new active item was touched; initiate its touch count to 0 for all players -- (Fixes co-op bugs, compared to only initiating it for the toucher) for j = 0, game:GetNumPlayers() - 1 do - local player = Isaac.GetPlayer(j) EID.PlayerItemInteractions[j].actives[itemID] = EID.PlayerItemInteractions[j].actives[itemID] or 0 EID.PlayerItemInteractions[j].altActives[itemID] = EID.PlayerItemInteractions[j].altActives[itemID] or 0 end @@ -1724,6 +1717,15 @@ function EID:evaluateQueuedItems() end end +-- if the player ItemInteraction table doesnt exist, create it with its init values +function EID:InitItemInteractionIfAbsent(playerID) + if not EID.PlayerItemInteractions[playerID] then + EID.PlayerItemInteractions[playerID] = { LastTouch = 0, actives = {}, pills = {}, altActives = {}, altPills = {}, + pickupHistory = {}, altPickupHistory = {} } + end + EID.RecentlyTouchedItems[playerID] = EID.RecentlyTouchedItems[playerID] or {} +end + -- Returns the quality of the described entity function EID:getObjectQuality(descObj) @@ -1770,10 +1772,8 @@ end function EID:AddPickupToHistory(pickupType, effectID, player, useFlags) if REPENTANCE and useFlags & UseFlag.USE_MIMIC == UseFlag.USE_MIMIC then return end -- dont add mimic pills to history local playerID = EID:getPlayerID(player) - if not EID.PlayerItemInteractions[playerID].pickupHistory then - EID.PlayerItemInteractions[playerID].pickupHistory = {} - EID.PlayerItemInteractions[playerID].altPickupHistory = {} - end + EID:InitItemInteractionIfAbsent(playerID) + local historyTable = EID.PlayerItemInteractions[playerID].pickupHistory -- Dead Tainted Lazarus exception if player:GetPlayerType() == 38 then diff --git a/main.lua b/main.lua index 87455277..cae22ef2 100644 --- a/main.lua +++ b/main.lua @@ -1522,9 +1522,7 @@ EID:AddCallback(ModCallbacks.MC_POST_RENDER, onRender) local function AddActiveItemProgress(player, isD4) EID.ForceRefreshCache = true local playerID = EID:getPlayerID(player) - if not EID.PlayerItemInteractions[playerID] then - EID.PlayerItemInteractions[playerID] = {LastTouch = 0, actives = {}, pills = {}, altActives = {}, altPills = {}, pickupHistory = {}, altPickupHistory = {}} - end + EID:InitItemInteractionIfAbsent(playerID) -- Dead Tainted Lazarus exceptions local activesTable = EID.PlayerItemInteractions[playerID].actives if player:GetPlayerType() == 38 then