Jump to content

Recommended Posts

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 by Sacco
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!

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.

  • Health 1
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 by Sacco
  • Like 1
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.

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!.

  • Health 1

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...