Sacco Posted January 6, 2025 Share Posted January 6, 2025 (edited) Hi, i've made a new mechanic related to shadow creatures. When they hit you you lose health over time, but i'd like to add a way to make it reduce YOUR damage output for a bit of time too. I've tried to add something, but the problem was that due to how i wrote the code every character under the effect would deal 0.9x of the DEFAULT damage and the damage didn't even come back to normal after the intended time. Thanks in advance!!!! Here's the code local Curse = Class(function(self, inst) self.inst = inst self.remaining_time = 0 self.task = nil end) function Curse:ApplyCurse(time) self.inst.components.talker:Say(GetString(self.inst, "ANNOUNCE_I_GOT_CURSED")) if self.task ~= nil then self.task:Cancel() end self.remaining_time = time > self.remaining_time and time or self.remaining_time self.task = self.inst:DoPeriodicTask(1, function(_) if self.remaining_time == 0 then self.task:Cancel() return end self.inst.components.health:DoDelta(-2) self.remaining_time = self.remaining_time - 1 end) end return Curse Here's some other lines of code which set the exact amount of time every single shadow creature (in this case terrorbeak) deal of curse. local function OnAttackOther(inst, data) if data.target ~= nil and data.target.components.curse ~= nil then data.target.components.curse:ApplyCurse(3) end end AddPrefabPostInit("terrorbeak", function(inst) if not GLOBAL.TheWorld.ismastersim then return end inst:ListenForEvent("onattackother", OnAttackOther) end) Edited January 6, 2025 by Sacco Link to comment https://forums.kleientertainment.com/forums/topic/163001-how-do-i-add-a-temporary-damage-reduction-to-this-mechanic/ Share on other sites More sharing options...
Baguettes Posted January 10, 2025 Share Posted January 10, 2025 Have you tried combat component’s external damage multipliers SetModifier? I wonder if you were using the character damage mult for it. Also I don’t know why your damage doesn’t return to 1x yet. Link to comment https://forums.kleientertainment.com/forums/topic/163001-how-do-i-add-a-temporary-damage-reduction-to-this-mechanic/#findComment-1784921 Share on other sites More sharing options...
Sacco Posted January 10, 2025 Author Share Posted January 10, 2025 7 hours ago, Baguettes said: Have you tried combat component’s external damage multipliers SetModifier? I wonder if you were using the character damage mult for it. Also I don’t know why your damage doesn’t return to 1x yet. when i tried it the damage of all characters was set to 0.9 of the weapon's base damage. Can you tell me the exact line of code you think might work? Thank you! Link to comment https://forums.kleientertainment.com/forums/topic/163001-how-do-i-add-a-temporary-damage-reduction-to-this-mechanic/#findComment-1784952 Share on other sites More sharing options...
Baguettes Posted January 11, 2025 Share Posted January 11, 2025 Hmm. Maybe… combat.externaldamagemultipliers:SetModifier(source, m, key) source could be the person who got cursed, m is the amount in multiplier, key is optional. Then do RemoveModifier(source, key) for when timer is up. 1 Link to comment https://forums.kleientertainment.com/forums/topic/163001-how-do-i-add-a-temporary-damage-reduction-to-this-mechanic/#findComment-1785158 Share on other sites More sharing options...
Sacco Posted January 11, 2025 Author Share Posted January 11, 2025 (edited) 4 hours ago, Baguettes said: Hmm. Maybe… combat.externaldamagemultipliers:SetModifier(source, m, key) source could be the person who got cursed, m is the amount in multiplier, key is optional. Then do RemoveModifier(source, key) for when timer is up. I just don't understand one thing. What should i write in "source", because if i leave it as it is the game crashes when i get hit by a shadow creatures because "source is not declared". TY Edit: i somehow made it work! Thanks for everything Edited January 11, 2025 by Sacco 1 Link to comment https://forums.kleientertainment.com/forums/topic/163001-how-do-i-add-a-temporary-damage-reduction-to-this-mechanic/#findComment-1785172 Share on other sites More sharing options...
Baguettes Posted January 11, 2025 Share Posted January 11, 2025 3 hours ago, Sacco said: I just don't understand one thing. What should i write in "source", because if i leave it as it is the game crashes when i get hit by a shadow creatures because "source is not declared". TY Edit: i somehow made it work! Thanks for everything Ah, to clarify the source is an instance of a mob. In this case, you can pass the Curse component owner as the source, self.inst should work. FYI, the key, while optional, can be useful to avoid mod conflicts. You can pass a string into key, like “yourmod_curse” or whatever you like, then use RemoveModifier again with your key passed in to avoid removing other modifiers other mods may have added to your source, since not passing a key will remove all modifiers from the source. Link to comment https://forums.kleientertainment.com/forums/topic/163001-how-do-i-add-a-temporary-damage-reduction-to-this-mechanic/#findComment-1785187 Share on other sites More sharing options...
Sacco Posted January 12, 2025 Author Share Posted January 12, 2025 7 hours ago, Baguettes said: Ah, to clarify the source is an instance of a mob. In this case, you can pass the Curse component owner as the source, self.inst should work. FYI, the key, while optional, can be useful to avoid mod conflicts. You can pass a string into key, like “yourmod_curse” or whatever you like, then use RemoveModifier again with your key passed in to avoid removing other modifiers other mods may have added to your source, since not passing a key will remove all modifiers from the source. Yea, with "source" i did as you said, but with "key" i just removed it. Thanks for your help!. 1 Link to comment https://forums.kleientertainment.com/forums/topic/163001-how-do-i-add-a-temporary-damage-reduction-to-this-mechanic/#findComment-1785244 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