thanks for your help ~ I am making my own attribute system, and I want every one strength give 20 max health. modifier code like below. However, when i press T to change the strength (implement in another file), the health leaves unchange ( the GetModifierHealthBonus function only called once). Is there a way to calculate the health bonus dynamically?
@registerModifier()
export class modifier_custom_attack_damage extends BaseModifier {
IsHidden(): boolean {
return false;
}
// Not a debuff
IsDebuff(): boolean {
return false;
}
// Cannot be purged
IsPurgable(): boolean {
return false;
}
// Declare functions to listen to
DeclareFunctions(): ModifierFunction[] {
return [
ModifierFunction.ON_ATTACK_LANDED,
ModifierFunction.HEALTH_BONUS
];
}
// Calculate health bonus based on custom strength
GetModifierHealthBonus(): number {
if (!IsServer()) return 0;
const parent = this.GetParent();
if (!parent.IsHero()) return 0;
const playerID = parent.GetPlayerOwnerID();
const customStrength = safeAttributeManager.getStrength(playerID);
// Each point of strength increases health by 20 (adjustable as needed)
const healthPerStrength = 20;
const bonusHealth = customStrength * healthPerStrength;
print(`[CustomAttributes] Strength: ${customStrength}, Health bonus: ${bonusHealth}`);
return bonusHealth;
}
OnAttackLanded(event: ModifierAttackEvent): void {
......
}
OnCreated(): void {
if (IsServer()) {
// Check for attribute changes every half second
this.StartIntervalThink(0.5);
}
}
OnIntervalThink(): void {
if (IsServer()) {
const parent = this.GetParent();
parent.CalculateGenericBonuses();
}
}
}```