Scoreboard error checking

This commit is contained in:
Vortrex
2023-02-21 20:28:27 -06:00
parent 697ccd860f
commit e3a0b27c4e

View File

@@ -38,66 +38,84 @@ function initScoreBoardListFont() {
// =========================================================================== // ===========================================================================
function processScoreBoardRendering() { function processScoreBoardRendering() {
if (isAnyGUIActive()) { if (!renderScoreBoard) {
logToConsole(LOG_VERBOSE | LOG_ERROR, `[V.RP.ScoreBoard] Could not render scoreboard. Scoreboard rendering is disabled!`);
return false; return false;
} }
if (renderScoreBoard) { if (scoreBoardListFont == null) {
if (isKeyDown(scoreBoardKey)) { logToConsole(LOG_VERBOSE | LOG_ERROR, `[V.RP.ScoreBoard] Could not render scoreboard. List font is null!`);
if (scoreBoardListFont != null && scoreBoardTitleFont != null) { return false;
let scoreboardStart = (game.height / 2) - (Math.floor(getClients().length / 2) * 20); }
let titleSize = scoreBoardTitleFont.measure("PLAYERS", game.width, 0.0, 1.0, 10, false, false);
scoreBoardTitleFont.render("PLAYERS", [game.width / 2, scoreboardStart - 50], 0, 0.5, 0.0, scoreBoardTitleFont.size, COLOUR_WHITE, false, false, false, true);
titleSize = scoreBoardTitleFont.measure("____________________________", game.width, 0.0, 1.0, 10, false, false); if (scoreBoardTitleFont == null) {
scoreBoardTitleFont.render("____________________________", [game.width / 2, scoreboardStart - 35], 0, 0.5, 0.0, scoreBoardTitleFont.size, COLOUR_WHITE, false, false, false, true); logToConsole(LOG_VERBOSE | LOG_ERROR, `[V.RP.ScoreBoard] Could not render scoreboard. Title font is null!`);
return false;
}
let clients = getClients(); if (isAnyGUIActive()) {
for (let i in clients) { logToConsole(LOG_VERBOSE | LOG_ERROR, `[V.RP.ScoreBoard] Could not render scoreboard. A GUI window is active!`);
if (!clients[i].console) { return false;
let name = clients[i].name; }
let colour = COLOUR_WHITE;
let paused = false;
let ping = "-1";
if (typeof playerNames[clients[i].name] != "undefined") { if (scoreBoardKey == null) {
name = playerNames[clients[i].name]; return false;
} }
if (typeof playerPaused[clients[i].name] != "undefined") { if (!isKeyDown(scoreBoardKey)) {
paused = playerPaused[clients[i].name]; return false;
} }
if (typeof playerColours[clients[i].name] != "undefined") { let scoreboardStart = (game.height / 2) - (Math.floor(getClients().length / 2) * 20);
colour = playerColours[clients[i].name]; let titleSize = scoreBoardTitleFont.measure("PLAYERS", game.width, 0.0, 1.0, 10, false, false);
} scoreBoardTitleFont.render("PLAYERS", [game.width / 2, scoreboardStart - 50], 0, 0.5, 0.0, scoreBoardTitleFont.size, COLOUR_WHITE, false, false, false, true);
if (typeof playerPing[clients[i].name] != "undefined") { titleSize = scoreBoardTitleFont.measure("____________________________", game.width, 0.0, 1.0, 10, false, false);
ping = toString(playerPing[clients[i].name]); scoreBoardTitleFont.render("____________________________", [game.width / 2, scoreboardStart - 35], 0, 0.5, 0.0, scoreBoardTitleFont.size, COLOUR_WHITE, false, false, false, true);
}
// Player ID let clients = getClients();
let text = String(clients[i].index); for (let i in clients) {
let size = scoreBoardListFont.measure(text, 75, 0.0, 1.0, 10, false, false); if (!clients[i].console) {
scoreBoardListFont.render(text, [game.width / 2 - 100, scoreboardStart + (i * 20)], 0, 0.5, 0.0, scoreBoardListFont.size, COLOUR_WHITE, false, false, false, true); let name = clients[i].name;
let colour = COLOUR_WHITE;
let paused = false;
let ping = "-1";
// Player Name if (typeof playerNames[clients[i].name] != "undefined") {
text = name; name = playerNames[clients[i].name];
size = scoreBoardListFont.measure(text, 100, 0.0, 1.0, 10, false, false); }
scoreBoardListFont.render(text, [game.width / 2, scoreboardStart + (i * 20)], 0, 0.5, 0.0, scoreBoardListFont.size, colour, false, false, false, true);
// Ping if (typeof playerPaused[clients[i].name] != "undefined") {
text = ping; paused = playerPaused[clients[i].name];
size = scoreBoardListFont.measure(ping, 75, 0.0, 1.0, 10, false, false); }
scoreBoardListFont.render(ping, [game.width / 2 + 100, scoreboardStart + (i * 20)], 0, 0.5, 0.0, scoreBoardListFont.size, COLOUR_WHITE, false, false, false, true);
// PAUSED Status (depends on resource "afk") if (typeof playerColours[clients[i].name] != "undefined") {
if (paused == true) { colour = playerColours[clients[i].name];
size = scoreBoardListFont.measure("PAUSED", 100, 0.0, 1.0, 10, false, false); }
scoreBoardListFont.render("PAUSED", [game.width / 2 + 200, scoreboardStart + (i * 20)], 0, 0.5, 0.0, scoreBoardListFont.size, pausedColour, false, false, false, true);
} if (typeof playerPing[clients[i].name] != "undefined") {
} ping = toString(playerPing[clients[i].name]);
} }
// Player ID
let text = String(clients[i].index);
let size = scoreBoardListFont.measure(text, 75, 0.0, 1.0, 10, false, false);
scoreBoardListFont.render(text, [game.width / 2 - 100, scoreboardStart + (i * 20)], 0, 0.5, 0.0, scoreBoardListFont.size, COLOUR_WHITE, false, false, false, true);
// Player Name
text = name;
size = scoreBoardListFont.measure(text, 100, 0.0, 1.0, 10, false, false);
scoreBoardListFont.render(text, [game.width / 2, scoreboardStart + (i * 20)], 0, 0.5, 0.0, scoreBoardListFont.size, colour, false, false, false, true);
// Ping
text = ping;
size = scoreBoardListFont.measure(ping, 75, 0.0, 1.0, 10, false, false);
scoreBoardListFont.render(ping, [game.width / 2 + 100, scoreboardStart + (i * 20)], 0, 0.5, 0.0, scoreBoardListFont.size, COLOUR_WHITE, false, false, false, true);
// PAUSED Status (depends on resource "afk")
if (paused == true) {
size = scoreBoardListFont.measure("PAUSED", 100, 0.0, 1.0, 10, false, false);
scoreBoardListFont.render("PAUSED", [game.width / 2 + 200, scoreboardStart + (i * 20)], 0, 0.5, 0.0, scoreBoardListFont.size, pausedColour, false, false, false, true);
} }
} }
} }