#Refresh the modifier
1 messages · Page 1 of 1 (latest)
This is test ability
LinkLuaModifier("modifier_Old", "abilities/heroes/Sasan/Old", LUA_MODIFIER_MOTION_NONE)
Sasan_Old = class({})
function Sasan_Old:GetIntrinsicModifierName()
return "modifier_Old"
end
function Sasan_Old:OnCreated()
if not IsServer() then return end
self.modifier = self:GetCaster():AddNewModifier(self:GetCaster(), self, "modifier_Old", {})
self.attribute_loss1 = -self.parent:GetStrength() * ability:GetSpecialValueFor("attribute_loss")
if self.parent:GetPrimaryAttribute()==DOTA_ATTRIBUTE_STRENGTH then
self:GetParent():ModifyHealth( self:GetParent():GetHealth() + 20*self.stat_loss, self:GetAbility(), true, DOTA_DAMAGE_FLAG_NONE )
end
self:GetCaster():CalculateStatBonus(true)
self:GetParent():CalculateStatBonus(true)
end
modifier_Old = class({})
function modifier_Old:IsHidden()
return false
end
function modifier_Old:IsDebuff()
return true
end
function modifier_Old:IsStunDebuff()
return false
end
function modifier_Old:IsPurgable()
return false
end
function modifier_Old:RemoveOnDeath()
return false
end
function modifier_Old:GetAttributes()
return MODIFIER_ATTRIBUTE_MULTIPLE
end
function modifier_Old:OnCreated()
self.attribute_loss1 = -self:GetCaster():GetStrength() * self:GetAbility():GetSpecialValueFor("attribute_loss")
end
function modifier_Old:GetTexture()
return "Sasan/Old"
end
function modifier_Old:DeclareFunctions()
return {
MODIFIER_PROPERTY_STATS_STRENGTH_BONUS,
}
end
function modifier_Old:GetModifierBonusStats_Strength()
return self.attribute_loss1
end
When stats changed or level of ability is upgraded, -stats from ability doesn't change
So if char will upgrade this ability with 10 strength for example, His attributes will be
"10-5"
``` But if he will upgrade his level and get more strength, for example 100. Then his strength will be ```bash
"110-5"
In your modifier you are doing the math for your stat debuff once, in OnCreated, and then never again.
You should add a OnIntervalThink function that periodically recalculates the stats debuff.
Also, in your ability you have a OnCreated function but that doesnt exist for abilities. The ability equivalent would be Spawn which is called when the ability entity is created. Or OnAbilityUpgrade for when the ability is leveled up.
Or alternatively, just put the math in GetModifierBonusStats_Strength
OP, note that this is a design change: this will make the stats loss be dynamically adjusted based on the target's current strength.
Which, upon re-reading is what you wanted anyway.
Dota crashes)
Insta crash when modifier added on char
This method have 1 problem too. It recalculates stats every interval, so when stats go down, its recalculates them again and again. And every tick stats are different
Ok.
Its crashing because youre calling GetStrength in a function that is called by GetStrength, so its causing infinite recursion.
So you need to add a variable to tell the code when your ability is trying to get the str value, to prevent the infinite loop in stats calculation.
if not self.flag then
self.flag = true
self.myBonus = ...
end
self.flag = false
return self.myBonus
There is also this function, which should do what you want instead of calculating the value yourself.
GetModifierBonusStats_Strength_Percentage
But im not sure if it takes negative values, ive never tried.
GetModifierBonusStats_Strength_Percentage
Can't find it in dota lua API, so i don't know about it)
what is self flag doing?