#LAG READER
1 messages · Page 1 of 1 (latest)
// Lag Reader
let lastTickTime = Date.now();
function lagReaderServerMs() {
const currentTime = Date.now();
const tickDuration = currentTime - lastTickTime;
lastTickTime = currentTime;
const expectedTickDuration = 50; // 1 tick = 50 ms
const lag = tickDuration - expectedTickDuration;
return { lag }
}
let checkTime = Date.now();
let currentTicks = 0;
let tps = 0;
function lagReaderTps() {
currentTicks++;
const currentTime = Date.now();
if (currentTime - checkTime > 970) {
tps = currentTicks;
checkTime = currentTime;
currentTicks = 0;
}
return { tps }
}
system.runInterval(() => {
const lag = lagReaderServerMs().lag;
const tps = lagReaderTps().tps;
const color = ['§a', '§e', '§g', '§6', '§c', '§4'];
console.warn(`Server: ${Math.floor(lag / 10) >= color.length ? '§4' : color[Math.floor(lag / 10)]}${lag} ms §f| Ticks/s: §b${tps}`);
}, 1);
Is there any way to make this work for every individual player in the server and display it on their actionbar?
instead of console.warn you'd get all the players and use player.onScreenDisplay.setActionbar
Hmmm ok, but is this ping mutually exclusive to everyone? Like if 1 person is getting more lag than another then their action bar will show more ms than other people?
that has nothing to do with ping, this is a server lag reader basically it tells how the server is going not how your connection to the server is going, every player will see the same
Hey uh
I’m getting 240 ticks/s
// Lag Reader
let lastTickTime = Date.now();
function lagReaderServerMs() {
const currentTime = Date.now();
const tickDuration = currentTime - lastTickTime;
lastTickTime = currentTime;
const expectedTickDuration = 50; // 1 tick = 50 ms
const lag = tickDuration - expectedTickDuration;
return { lag }
}
let checkTime = Date.now();
let currentTicks = 0;
let tps = 0;
function lagReaderTps() {
currentTicks++;
const currentTime = Date.now();
if (currentTime - checkTime > 970) {
tps = currentTicks;
checkTime = currentTime;
currentTicks = 0;
}
return { tps }
}
system.runInterval(() => {
for (const player of world.getPlayers()) {
const lag = lagReaderServerMs().lag;
const tps = lagReaderTps().tps;
const color = ['a', 'e', 'g', '6', 'c', '4'];
const coins = world.scoreboard.getObjective("coins").getScore(player.scoreboardIdentity)
const kills = world.scoreboard.getObjective("kills").getScore(player.scoreboardIdentity)
const deaths = world.scoreboard.getObjective("deaths").getScore(player.scoreboardIdentity)
player.onScreenDisplay.setActionBar(`§eCoins: ${coins} \n§aKills: ${kills}\n§cDeaths: ${deaths}\n§${Math.floor(lag / 10) >= color.length ? color[Math.floor(lag / 10)] : '4'}${Math.abs(lag)} ms §f| Ticks/s: §b${tps}`);
}
});```
Why am i getting over 10 times the expected tick/s of 20
At some point I had 340 as well
Uh
UHHHH
IT MULTIPLIES FOR EVERY PLAYER IN MY WORLD
HOW DO I FIXXX
And my ms is dropping to 1-5 sometimes
From 50
bro you re doing it for each player
Can I divide by the total amount of players then
you should do world.getplayers()[0] not for (const player of world.getplayers())
But then the rest of the actionbar wont work properly.
for what?
The tick/s
It’s at 140 right now
160 now
Because someone just joined
then do 1 part that gets the lag then another part that shows it to all players
without getting the lag multiplied by the players
So both the ms and the tick/s aren’t mutually exclusive to each player?
By default i mean
no they have nothing to do with players
Oh wait I’m dumb
they re only about the server ms and tps not the players
I’ll only calculate the tps separately
what?
Now my system.runInterval looks like this system.runInterval(() => { const tps = lagReaderTps().tps; for (const player of world.getPlayers()) { const lag = lagReaderServerMs().lag; const color = ['a', 'e', 'g', '6', 'c', '4']; const coins = world.scoreboard.getObjective("coins").getScore(player.scoreboardIdentity) const kills = world.scoreboard.getObjective("kills").getScore(player.scoreboardIdentity) const deaths = world.scoreboard.getObjective("deaths").getScore(player.scoreboardIdentity) player.onScreenDisplay.setActionBar(`§eCoins: ${coins} \n§aKills: ${kills}\n§cDeaths: ${deaths}\n§${Math.floor(lag / 10) >= color.length ? color[Math.floor(lag / 10)] : '4'}${Math.abs(lag)} ms §f| Ticks/s: §b${tps}`); } });
The const tps is outside the for loop
Right?
runinerval {
get server tps
get server ms
for each player {
show tps && ms
}
}
lag and tps are outside the for const player
Also the code had an issue where the ms would show undefined-50 (where 50 was the ms) so I fixed it by switching the ? : logic
And the ms was negative so i had to do Math.abs on it
But now that you said that it doesn’t work for each player I think that those errors were MY fault
i think you messed up, math abs wont fix math issues
yeah i think that too
So, theoretically, this should work system.runInterval(() => { const lag = lagReaderServerMs().lag; const tps = lagReaderTps().tps; const color = ['a', 'e', 'g', '6', 'c', '4']; for (const player of world.getPlayers()) { const coins = world.scoreboard.getObjective("coins").getScore(player.scoreboardIdentity) const kills = world.scoreboard.getObjective("kills").getScore(player.scoreboardIdentity) const deaths = world.scoreboard.getObjective("deaths").getScore(player.scoreboardIdentity) player.onScreenDisplay.setActionBar(`§eCoins: ${coins} \n§aKills: ${kills}\n§cDeaths: ${deaths}\n§${Math.floor(lag / 10) >= color.length ? color[Math.floor(lag / 10)] : '4'}${Math.abs(lag)} ms §f| Ticks/s: §b${tps}`); } });
And then I’ll fix any issues with displaying it if they show up
Well I just did that and removed the abs and now my ms is having a seziure
And not changing colors
Can someone please tell me why my ms is doing this
const tps = lagReaderTps().tps;
const lag = lagReaderServerMs().lag;
const color = ['a', 'e', 'g', '6', 'c', '4'];
for (const player of world.getPlayers()) {
const coins = world.scoreboard.getObjective("coins").getScore(player.scoreboardIdentity)
const kills = world.scoreboard.getObjective("kills").getScore(player.scoreboardIdentity)
const deaths = world.scoreboard.getObjective("deaths").getScore(player.scoreboardIdentity)
player.onScreenDisplay.setActionBar(`§eCoins: ${coins} \n§aKills: ${kills}\n§cDeaths: ${deaths}\n§r${lag} ms §f| Ticks/s: §b${tps}`);
}
});
//§${Math.floor(lag / 10) >= color.length ? color[Math.floor(lag / 10)] : '4'}```
Now that I added a condition that makes it never go below 0 and the coloring back it just looks like I have extremely good connection 🤔