Jump to content

How to give damage vulnerability to characters?


Recommended Posts

I was creating a mod to edit character resistances.

In this case, I wanted to give damage vulnerabilities in a percentage, using the game's own code.

Any idea how I could do this?

 

--Exemple:

local armorset = (-0.5) -- 50% Vulnerable

inst.components.health:SetAbsorptionAmount(armorset)

-- This code doesn't work

 

Link to comment
Share on other sites

@decduck3

I think it would work, but I made the example this way so that I don't need to change much in the game's code and make it simpler, since in the game's code, the calculation for the damage is:
 

Spoiler

function Health:DoDelta(amount, overtime, cause, ignore_invincible, afflicter, ignore_absorb)
    if self.redirect ~= nil and self.redirect(self.inst, amount, overtime, cause, ignore_invincible, afflicter, ignore_absorb) then
        return 0
    elseif not ignore_invincible and (self:IsInvincible() or self.inst.is_teleporting) then
        return 0
    elseif amount < 0 and not ignore_absorb then
        amount = amount * math.clamp(1 - (self.playerabsorb ~= 0 and afflicter ~= nil and afflicter:HasTag("player") and self.playerabsorb + self.absorb or self.absorb), 0, 1) * math.clamp(1 - self.externalabsorbmodifiers:Get(), 0, 1)
    end

    local old_percent = self:GetPercent()
    self:SetVal(self.currenthealth + amount, cause, afflicter)
    local new_percent = self:GetPercent()

    self.inst:PushEvent("healthdelta", { oldpercent = old_percent, newpercent = self:GetPercent(), overtime = overtime, cause = cause, afflicter = afflicter, amount = amount })

    if self.ondelta ~= nil then
        self.ondelta(self.inst, old_percent, self:GetPercent(), overtime, cause, afflicter, amount)
    end
    return amount
end

return Health

 


Note: I'm making the vulnerability variable to be chosen by the player, so it will have other values besides 50% vulnerability

Is there any way to put the "DoDelta" in the "function master_postinit(inst)" of a character?

Edited by Bassani
Link to comment
Share on other sites

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
 Share

×
  • Create New...