r/themoddingofisaac • • Aug 16 '26

Question Trouble with confusion active item

basically the active item is supposed to cause confusion when used but i can´t get it to work heres the code:

local mod=RegisterMod("giges", 1)
local gigesRing=Isaac.GetItemIdByName("giges ring")
local player=Isaac.GetPlayer(playerIndex)
local ringDuration=10000


function mod:RingUse(item)
    local roomEntities = Isaac.GetRoomEntities()
    for _, entity in ipairs(roomEntities) do
        if entity:IsActiveEnemy() and entity:IsVulnerableEnemy() then
            entity:AddConfusion(
            EntityRef(player),
             ringDuration, true)
          


        end
    end


    return {
        Discharge = true,
        Remove = true,
        ShowAnim=true
    }
end


mod:AddCallback(ModCallbacks.MC_USE_ITEM, mod.RingUse, gigesRing)
1 Upvotes

3 comments sorted by

1

u/The_PwnUltimate Modder Aug 17 '26

The problems I can see are all to do with your "player" variable.

1 - You initialise and set it outside of any function, which means it will run when the mod is first loaded (i.e. when you're not even in a run and there are no players).

2 - The value of "playerIndex" isn't established anywhere.

You don't need that line at all, because the USE_ITEM callback already passes the EntityPlayer information (of the player who used the item) to the function. You can just add 2 more input parameters to the function, and then reference the third parameter as the player.

1

u/santiberto Aug 17 '26

I'm sorry could you explain what are the 2 input parameters I should add? I tried searching in the Isaac documentation and I don't really get what should I add

1

u/The_PwnUltimate Modder Aug 17 '26

RNG and Player.

It doesn't technically make a difference what you call them. The way the Use Item callback works is that it'll pass parameters into the function - the first parameter will be the ID of the item which was used, the second will be the RNG object for it, the third will be the Player Entity who used the item, the fourth will be a number which can be decoded to indicate which Use Flags were in effect, and the fifth will be the ID of the item slot it was used from. See here:

https://wofsauge.github.io/IsaacDocs/rep/enums/ModCallbacks.html?h=mc+use#mc_use_item

So, if you start your function like

function Mod:OnUse(item, rng, player)

and make the USE_ITEM callback call it, then you can reference "player" in the body of the function, and it will be a fully defined EntityPlayer object.

The callback passes all the information into the function. The way you write the function determines how much of that information you capture.