-
Notifications
You must be signed in to change notification settings - Fork 8
Description
I have 3 areas (limbo, mapped and myarea) in my ranvier starter kit.
The manifest settings are:
title: "Limbo"
behaviors:
progressive-respawn:
interval: 10
title: "Map test"
behaviors:
progressive-respawn:
interval: 15
title: "My Area"
behaviors:
progressive-respawn:
interval: 20
And I noticed only limbo will trigger the event correctly.
I insert some code try to find out why.
return function (config) {
// setup respawnTick to only happen every [interval] seconds
const respawnInterval = config.interval || 30;
const sinceLastTick = Date.now() - lastRespawnTick;
console.log(this.name + " " + sinceLastTick);
if (sinceLastTick >= respawnInterval * 1000) {
console.log(this.name + " is respawning" + "\n");
lastRespawnTick = Date.now();
for (const [id, room] of this.rooms) {
room.emit('respawnTick', state);
}
}
};
And here is the console log.
limbo 10044
mapped 10044
myarea 10044
limbo is respawning
limbo 109
mapped 110
myarea 110
As you can see, limbo trigger the event and update the lastRespawnTick variable same time.
Means other areas will never respawn and makes this bundle unusable.
So I change the logic.
No count in millisecond anymore, it should be counted in ticks = Config.get(entityTickFrequency)
Since entityTickFrequency is hardcoded in main process, so I just use magic number 100 & 10 here.
updateTick: state => {
let serverStartTime = Math.trunc(Date.now() / 100);
return function (config) {
const respawnInterval = config.interval || 30;
const upTime = Math.trunc(Date.now() / 100 - serverStartTime);
if (upTime % (respawnInterval * 10) == 0) {
console.log(this.name + " is respawning" + "\n");
for (const [id, room] of this.rooms) {
room.emit('respawnTick', state);
}
}
};
},
First time using github and English is not my native language(JavaScript neither).
Hope this post will not offend anybody.
At last, thanks you guys making this awesome software, have a nice day!