Game Timer
-
Timer that keeps track of total play time along with current round time and previous round time

Lines 26-28 allow you to change where its displayed
#include maps\mp_utility;
#include common_scripts\utility;
#include maps\mp\gametypes_zm_hud_util;init()
{
level thread onPlayerConnect();
}onPlayerConnect()
{
for(;;)
{
level waittill("connected", player);
player thread playerGameTimers();
}
}playerGameTimers()
{
self endon("disconnect");
level endon("end_game");flag_wait("initial_blackscreen_passed"); self.gameTimerHud = self createTimerHud("Game:", 400, 120); self.roundTimerHud = self createTimerHud("Round:", 400, 145); self.lastRoundTimerHud = self createTimerHud("Last:", 395, 170); gameSeconds = 0; roundSeconds = 0; lastRoundSeconds = 0; currentRound = getCurrentRound(); for(;;) { newRound = getCurrentRound(); if(newRound != currentRound) { lastRoundSeconds = roundSeconds; roundSeconds = 0; currentRound = newRound; } self.gameTimerHud setText("Game: " + formatTimer(gameSeconds)); self.roundTimerHud setText("Round: " + formatTimer(roundSeconds)); self.lastRoundTimerHud setText("Last: " + formatTimer(lastRoundSeconds)); wait 1; gameSeconds++; roundSeconds++; }}
createTimerHud(label, x, y)
{
hud = createFontString("small", 1.35);
hud setpoint("RIGHT", "TOP", x, y);
hud.alpha = 1;
hud.sort = 20;
hud.color = (1, 1, 1);
hud setText(label + " 00:00");
return hud;
}getCurrentRound()
{
if(isDefined(level.round_number))
return level.round_number;if(isDefined(level.round)) return level.round; if(isDefined(level.zombie_round)) return level.zombie_round; return 1;}
formatTimer(totalSeconds)
{
hours = 0;
minutes = 0;
seconds = totalSeconds;while(seconds >= 3600) { hours++; seconds -= 3600; } while(seconds >= 60) { minutes++; seconds -= 60; } if(hours > 0) return hours + ":" + twoDigits(minutes) + ":" + twoDigits(seconds); return minutes + ":" + twoDigits(seconds);}
twoDigits(value)
{
if(value < 10)
return "0" + value;return "" + value;}
-
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login