#For some reason GetModifierExtraHealthBonus() does not work

1 messages · Page 1 of 1 (latest)

ancient pewter
#

The modifier has stacks and also gives additional speed and additional health. Stacks are updated when leveling up, at which point an error occurs. For some reason, the extra health doesn't multiply by stacks and returns the same as before, but the extra speed multiplies by stacks and gives the updated value. And the funny thing is that when receiving 3 stacks, the unit is given additional health, but only it counts as 2 stacks. That is, for example, I have self.health_gain = 25 and self.speed_gain = 2, and when a unit has 3 stacks, then self.health_gain will be 50, and self.speed_gain will be 6.

modifier_gain_stats = class({})

modifier_gain_stats.previous_level = 0

function modifier_gain_stats:OnCreated()
    if not IsServer() then return end
    local parent = self:GetParent()
    self.previous_level = parent.lvl
    self:SetStackCount(parent.lvl)
    self.speed_gain = parent:GetSpeedGain()
    self.health_gain = parent:GetHealthGain()
    self:SetHasCustomTransmitterData(true)
    self:StartIntervalThink(0.1)
end

function modifier_gain_stats:AddCustomTransmitterData()
    return {
        speed_gain = self.speed_gain,
        health_gain = self.health_gain,
    }
end

function modifier_gain_stats:HandleCustomTransmitterData(data)
    self.speed_gain = data.speed_gain
    self.health_gain = data.health_gain
end

function modifier_gain_stats:OnIntervalThink()
    local parent = self:GetParent()
    if self.previous_level < parent.lvl then
        self.previous_level = parent.lvl
        self:SetStackCount(parent.lvl)
    end
end

function modifier_gain_stats:DeclareFunctions()
    return {
        MODIFIER_PROPERTY_MOVESPEED_BONUS_CONSTANT,
        MODIFIER_PROPERTY_EXTRA_HEALTH_BONUS,
    }
end

function modifier_gain_stats:GetModifierExtraHealthBonus()
    return self.health_gain * self:GetStackCount()
end

function modifier_gain_stats:GetModifierMoveSpeedBonus_Constant()
    return self.speed_gain * self:GetStackCount() 
end
fiery moss
#

at which point an error occurs

Usually it's helpful to say what the error says.

#

Two issues I can see here.

First, doing an interval think every 0.1 seconds is kind of pointless, in most of its iterations nothing will happen. Why not set up a level up event instead that refreshes the modifier?

Second, as far as I'm aware, health bonuses are only applied when a modifier is created. You'll probably have to refresh, or destroy and recreate the modifier for the HP values to update.

ancient pewter
fiery moss
#

Another option is to try CalculateStatBonuses() or CalculateGenericBonuses() when leveling up and see if that helps

ancient pewter
fiery moss
#

I totally missed that stack count thing. Sounds like you should be printing and checking what are the actual values set in those variables and returned.

ancient pewter
#

Okay, I love this game))))))))) I really should have added CalculateGenericBonuses() after everything. Thank you so much for your help!

slow olive
#

most bonuses are calculated on modifier application, any changes you do afterwards have to be told to the engine

#

i think damage bonuses are the only exception to this

fiery moss
slow olive
#

attributes do not, or at least their bonuses don't

#

ive had it happen plenty of times where strength updates, but its bonuses dont

fiery moss
#

I remember implementing Marksmanship which dynamically changes the agility of the caster (based on whether enemy hero is in range) and damage adjusted accordingly in the UI