PocketPossum Posted September 6, 2025 Share Posted September 6, 2025 Hi! I'm trying to make a custom item for a custom player character, and I'm trying to figure out how to trigger an effect only if the player has a specific item equipped in their head slot. When the character gets hit, the enemy that hit them takes counter damage immediately. But I want to check if the player has a specific item equipped to their headslot when this happens, and if it is equipped, perform a different effect. The different effect being that it deals 99999999 damage to the attacker, and also the player character. So just the counter effect again, but much higher damage to kill both the player and attacker. I've got the normal counter damage setup perfectly, but not the "if this item is equipped, deal this damage instead and also damage the wearer". This is the counter effect that works perfectly for what I wanted. -- Counter effect. inst:ListenForEvent("attacked", function(inst, data) if data.attacker and data.attacker.components.health and data.attacker:HasTag("player") then data.attacker.components.health:DoDelta(math.random(-80, -80)) end if data.attacker and data.attacker.components.health and not data.attacker:HasTag("player") then data.attacker.components.health:DoDelta(math.random(-200, -200)) end end) This is the attempted code for what I'm trying to do if the player has an item equipped. -- Destiny Bond. inst:ListenForEvent("attacked", function(inst, data) if data.eslot == EQUIPSLOTS.HEAD and data.item.destiny_bond then if data.attacker and data.attacker.components.health and data.attacker:HasTag("player") then data.attacker.components.health:DoDelta(math.random(-9999999999999, -9999999999999)) data.inst.components.health:DoDelta(math.random(-9999999999999, -9999999999999)) end if data.eslot == EQUIPSLOTS.HEAD and data.item.destiny_bond then if data.attacker and data.attacker.components.health and not data.attacker:HasTag("player") then data.attacker.components.health:DoDelta(math.random(-9999999999999, -9999999999999)) data.inst.components.health:DoDelta(math.random(-9999999999999, -9999999999999)) end end end end) Any help is appreciated, I've tried a bunch of ways of coding this and haven't figured it out yet. Link to comment https://forums.kleientertainment.com/forums/topic/167858-check-if-player-has-an-item-equipped-then-do-an-effect/ Share on other sites More sharing options...
GameBoyAdv4002 Posted September 6, 2025 Share Posted September 6, 2025 Checkout sword_lunarplant.lua, I think it might be what you're looking for. if owner ~= nil then inst._onownerequip = function(owner, data) if data ~= nil then if data.item ~= nil and data.item.prefab == "lunarplanthat" then SetBuffEnabled(inst, true) elseif data.eslot == EQUIPSLOTS.HEAD then SetBuffEnabled(inst, false) end end end inst._onownerunequip = function(owner, data) if data ~= nil and data.eslot == EQUIPSLOTS.HEAD then SetBuffEnabled(inst, false) end end inst:ListenForEvent("equip", inst._onownerequip, owner) inst:ListenForEvent("unequip", inst._onownerunequip, owner) local hat = owner.components.inventory:GetEquippedItem(EQUIPSLOTS.HEAD) if hat ~= nil and hat.prefab == "lunarplanthat" then SetBuffEnabled(inst, true) end end Link to comment https://forums.kleientertainment.com/forums/topic/167858-check-if-player-has-an-item-equipped-then-do-an-effect/#findComment-1834644 Share on other sites More sharing options...
PocketPossum Posted September 6, 2025 Author Share Posted September 6, 2025 Thank you for pointing that out! I managed to take some bits from it and figure out how to do what I wanted. -- Destiny Bond. inst:ListenForEvent("attacked", function(inst, data) if data.attacker and data.attacker.components.health and data.attacker:HasTag("player") then local hat = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HEAD) if hat ~= nil and hat.prefab == "destiny_bond" then data.attacker.components.health:DoDelta(math.random(-999999, -999999)) inst.components.health:DoDelta(math.random(-999999, -999999)) end end if data.attacker and data.attacker.components.health and not data.attacker:HasTag("player") then local hat = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HEAD) if hat ~= nil and hat.prefab == "destiny_bond" then data.attacker.components.health:DoDelta(math.random(-999999, -999999)) inst.components.health:DoDelta(math.random(-999999, -999999)) end end end) And it works! If the enemy attacks you while you're wearing the Destiny Bond item, instantly kills you and the attacker. Thank you very much. Link to comment https://forums.kleientertainment.com/forums/topic/167858-check-if-player-has-an-item-equipped-then-do-an-effect/#findComment-1834692 Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now