Hello,
Is there a possibility to detect by some hook that the event was removed/destroyed?
Version: 4.0.0-beta.13
I tried to achieve that using onChanges
method and !!this._destroy$['_closed']
param.
Snippet
hpRecoveryTimer: NodeJS.Timer | null = null;
onInit() {
this.enableRecovery();
}
onChanges(player: RpgPlayer) {
const isDestroyed = !!player._destroy$['_closed']
if (this.hpRecoveryTimer !== null && isDestroyed) {
clearInterval(this.hpRecoveryTimer);
this.hpRecoveryTimer = null;
}
}
enableRecovery() {
this.hpRecoveryTimer = setInterval(() => {
if (this.hp >= this.getParamValue(Presets.MAXHP)) {
return;
}
console.log('recovery', this.id);
this.recovery({ hp: (this.hp / this.getParamValue(Presets.MAXHP)) + 0.01 });
}, 1000);
}
but it does not work.
isDestroyed
is false even though event was removed by:
map.removeEvent(event.id)
Furthermore isDestroyed
returns true after about 1-2 minutes of running server for every RpgEvent 🙈
And one more weird thing is that onChanges is triggered even that event was removed long time ago. I detected by id
.
Why I need this: clearInterval to not try to recovery hp for died mob.