yanecc Posted July 20, 2024 Share Posted July 20, 2024 The first method works well, but the durability is not consumed when the health is deducted due to eating. local function OnEquip(inst, owner) if inst.components.fueled then owner.AnimState:OverrideSymbol("swap_hat", "fhl_hsf", "swap_hat") owner.components.health.externalabsorbmodifiers:SetModifier(inst, 0.5) inst.consumefn = function(attacked, data) inst.components.fueled:DoDelta(-0.02 * inst.components.fueled.maxfuel) end inst:ListenForEvent("attacked", inst.consumefn, owner) inst.components.fueled:StartConsuming() end end So I modified it to get this, but it doesn't work as expected. local function OnEquip(inst, owner) if inst.components.fueled then owner.AnimState:OverrideSymbol("swap_hat", "fhl_hsf", "swap_hat") owner.components.health.externalabsorbmodifiers:SetModifier(inst, 0.5) inst.consumefn = function(inst, data) local amulet local hasAmulet = false for k, v in pairs(inst.components.inventory.equipslots) do if v and v:HasTag("hsf_protection") then hasAmulet = true amulet = v.prefab break end end if hasAmulet and data and data.oldpercent and data.newpercent then local health_loss = data.oldpercent - data.newpercent if health_loss > 0 then local durability_loss = 0.02 * amulet.components.fueled.maxfuel amulet.components.fueled:DoDelta(-durability_loss) end end end owner:ListenForEvent("healthdelta", inst.consumefn) inst:AddTag("hsf_protection") inst.components.fueled:StartConsuming() end end Link to comment https://forums.kleientertainment.com/forums/topic/158450-how-to-make-an-amulet-that-consumes-durability-when-it-halves-the-health-deduction/ Share on other sites More sharing options...
yanecc Posted July 20, 2024 Author Share Posted July 20, 2024 Ohh, I was completed muddled, it should work in this way. local function OnEquip(inst, owner) if inst.components.fueled then owner.AnimState:OverrideSymbol("swap_hat", "fhl_hsf", "swap_hat") owner.components.health.externalabsorbmodifiers:SetModifier(inst, 0.5) inst.consumefn = function(owner, data) local hasAmulet = false for k, v in pairs(owner.components.inventory.equipslots) do if v and v:HasTag("hsf_protection") then hasAmulet = true break end end if hasAmulet and data and data.oldpercent and data.newpercent then local health_loss = data.oldpercent - data.newpercent if health_loss > 0 then local durability_loss = 0.02 * inst.components.fueled.maxfuel inst.components.fueled:DoDelta(-durability_loss) end end end owner:ListenForEvent("healthdelta", inst.consumefn) inst:AddTag("hsf_protection") inst.components.fueled:StartConsuming() end end Link to comment https://forums.kleientertainment.com/forums/topic/158450-how-to-make-an-amulet-that-consumes-durability-when-it-halves-the-health-deduction/#findComment-1736856 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