Use tick count instead of Time()
This commit is contained in:
parent
4b877878f9
commit
057c60a76e
1 changed files with 18 additions and 13 deletions
31
timer.nut
31
timer.nut
|
@ -222,7 +222,7 @@ class ZoneBuilder
|
||||||
class PlayerState
|
class PlayerState
|
||||||
{
|
{
|
||||||
prev_zone_index = -1;
|
prev_zone_index = -1;
|
||||||
start_time = -1;
|
start_tick = -1;
|
||||||
|
|
||||||
constructor()
|
constructor()
|
||||||
{
|
{
|
||||||
|
@ -233,7 +233,8 @@ class PlayerState
|
||||||
class Timer
|
class Timer
|
||||||
{
|
{
|
||||||
zones = [];
|
zones = [];
|
||||||
players = {};
|
players = {};
|
||||||
|
tick_count = 0;
|
||||||
|
|
||||||
constructor()
|
constructor()
|
||||||
{
|
{
|
||||||
|
@ -282,6 +283,8 @@ class Timer
|
||||||
|
|
||||||
function Tick()
|
function Tick()
|
||||||
{
|
{
|
||||||
|
this.tick_count++;
|
||||||
|
|
||||||
local ply = null;
|
local ply = null;
|
||||||
while (ply = Entities.FindByClassname(ply, "player"))
|
while (ply = Entities.FindByClassname(ply, "player"))
|
||||||
{
|
{
|
||||||
|
@ -312,7 +315,7 @@ class Timer
|
||||||
}
|
}
|
||||||
|
|
||||||
local prev_zone_index = this.players[entindex].prev_zone_index;
|
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)
|
if (prev_zone_index < 0)
|
||||||
{
|
{
|
||||||
|
@ -324,12 +327,12 @@ class Timer
|
||||||
PrintToPlayer(ply, "Entered the start zone");
|
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.
|
// In start zone, check if leaving.
|
||||||
if (!this.zones[0].Clips(ply))
|
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");
|
Log("Left the start zone");
|
||||||
PrintToPlayer(ply, "Run started");
|
PrintToPlayer(ply, "Run started");
|
||||||
}
|
}
|
||||||
|
@ -342,7 +345,7 @@ class Timer
|
||||||
if (this.zones[0].Clips(ply))
|
if (this.zones[0].Clips(ply))
|
||||||
{
|
{
|
||||||
this.players[entindex].prev_zone_index = 0;
|
this.players[entindex].prev_zone_index = 0;
|
||||||
this.players[entindex].start_time = -1;
|
this.players[entindex].start_tick = -1;
|
||||||
Log("Entered the start zone");
|
Log("Entered the start zone");
|
||||||
PrintToPlayer(ply, "Entered the start zone");
|
PrintToPlayer(ply, "Entered the start zone");
|
||||||
continue;
|
continue;
|
||||||
|
@ -354,28 +357,30 @@ class Timer
|
||||||
{
|
{
|
||||||
if (this.zones[i].Clips(ply))
|
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)
|
if (i == this.zones.len() - 1)
|
||||||
{
|
{
|
||||||
// Entered the final zone.
|
// Entered the final zone.
|
||||||
this.players[entindex].prev_zone_index = -1;
|
this.players[entindex].prev_zone_index = -1;
|
||||||
this.players[entindex].start_time = -1;
|
this.players[entindex].start_tick = -1;
|
||||||
Log("Finished run in " + run_time + "s");
|
Log(format("Finished run in %.3fs (%d ticks)", run_time, run_ticks));
|
||||||
PrintToPlayer(
|
PrintToPlayer(
|
||||||
null,
|
null,
|
||||||
format(
|
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),
|
GetPlayerName(ply),
|
||||||
run_time
|
run_time,
|
||||||
|
run_ticks
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.players[entindex].prev_zone_index = i;
|
this.players[entindex].prev_zone_index = i;
|
||||||
Log("Entered zone " + i + " at " + run_time + "s");
|
Log(format("Entered zone %d at %.3fs (%d ticks)", i, run_time, run_ticks));
|
||||||
PrintToPlayer(ply, format("Entered zone \x03%d\x01 at \x04%f\x01s", i, run_time));
|
PrintToPlayer(ply, format("Entered zone \x03%d\x01 at \x04%.3f\x01s (%d ticks)", i, run_time, run_ticks));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue