Use tick count instead of Time()

This commit is contained in:
Lauri Räsänen 2025-03-17 01:09:05 +02:00
parent 4b877878f9
commit 057c60a76e

View file

@ -222,7 +222,7 @@ class ZoneBuilder
class PlayerState
{
prev_zone_index = -1;
start_time = -1;
start_tick = -1;
constructor()
{
@ -234,6 +234,7 @@ class Timer
{
zones = [];
players = {};
tick_count = 0;
constructor()
{
@ -282,6 +283,8 @@ class Timer
function Tick()
{
this.tick_count++;
local ply = null;
while (ply = Entities.FindByClassname(ply, "player"))
{
@ -312,7 +315,7 @@ class Timer
}
local prev_zone_index = this.players[entindex].prev_zone_index;
local start_time = this.players[entindex].start_time;
local start_tick = this.players[entindex].start_tick;
if (prev_zone_index < 0)
{
@ -324,12 +327,12 @@ class Timer
PrintToPlayer(ply, "Entered the start zone");
}
}
else if (prev_zone_index == 0 && start_time < 0)
else if (prev_zone_index == 0 && start_tick < 0)
{
// In start zone, check if leaving.
if (!this.zones[0].Clips(ply))
{
this.players[entindex].start_time = Time();
this.players[entindex].start_tick = this.tick_count;
Log("Left the start zone");
PrintToPlayer(ply, "Run started");
}
@ -342,7 +345,7 @@ class Timer
if (this.zones[0].Clips(ply))
{
this.players[entindex].prev_zone_index = 0;
this.players[entindex].start_time = -1;
this.players[entindex].start_tick = -1;
Log("Entered the start zone");
PrintToPlayer(ply, "Entered the start zone");
continue;
@ -354,28 +357,30 @@ class Timer
{
if (this.zones[i].Clips(ply))
{
local run_time = Time() - start_time;
local run_ticks = this.tick_count - start_tick;
local run_time = run_ticks / 66.0;
if (i == this.zones.len() - 1)
{
// Entered the final zone.
this.players[entindex].prev_zone_index = -1;
this.players[entindex].start_time = -1;
Log("Finished run in " + run_time + "s");
this.players[entindex].start_tick = -1;
Log(format("Finished run in %.3fs (%d ticks)", run_time, run_ticks));
PrintToPlayer(
null,
format(
"\x03%s\x01 finished a run in \x04%f\x01s",
"\x03%s\x01 finished a run in \x04%.3f\x01s (%d ticks)",
GetPlayerName(ply),
run_time
run_time,
run_ticks
)
);
}
else
{
this.players[entindex].prev_zone_index = i;
Log("Entered zone " + i + " at " + run_time + "s");
PrintToPlayer(ply, format("Entered zone \x03%d\x01 at \x04%f\x01s", i, run_time));
Log(format("Entered zone %d at %.3fs (%d ticks)", i, run_time, run_ticks));
PrintToPlayer(ply, format("Entered zone \x03%d\x01 at \x04%.3f\x01s (%d ticks)", i, run_time, run_ticks));
}
break;
}