Skip to content
View in the app

A better way to browse. Learn more.

Learn more

round-start-score-display/addons/amxmodx/scripting/olds_rscore.sma

olds_rscore.sma
180 lines · 5.7 KB · Pawn (AMX Mod X)
Raw
/*
 * Round Start Score Display (olds.ro workshop card LIB-2147)
 *
 * At the start of every round each player sees the team score and which
 * side leads, as a short HUD line such as "T 4 : 6 CT  CT leads" (or
 * "Tied" when the scores are equal). say /score shows the line again.
 *
 *   - The score is read from the game rules (m_iNumTerroristWins and
 *     m_iNumCTWins) right after the round restarts, so after sv_restart or
 *     mp_restartgame it reads 0 : 0.
 *   - The line is drawn in the colour of the leading team; a tie uses the
 *     mix of both colours.
 *   - With olds_rscore_winlimit 1 and mp_winlimit above 0 the line also
 *     says how many round wins end the map ("first to 10").
 *
 * Cvars (configs/plugins/olds_rscore.cfg; AutoExecConfig writes that file
 * with these defaults if it is missing):
 *   olds_rscore_time     4             Seconds the line stays (1 - 15).
 *   olds_rscore_color_t  "255 120 60"  Colour when the Terrorists lead (R G B).
 *   olds_rscore_color_ct "100 150 255" Colour when the CTs lead (R G B).
 *   olds_rscore_winlimit 0             1 = also show mp_winlimit ("first to N").
 *
 * Every text players read comes from data/lang/olds_rscore.txt (English).
 *
 * Requires AMX Mod X 1.10 or newer and ReAPI with ReGameDLL_CS. Written for
 * AMX Mod X 1.10.0.5490, ReAPI 5.29.0.358, ReGameDLL_CS 5.30.0.814.
 *
 * Copyright (C) 2026 alexit (olds.ro workshop)
 * SPDX-License-Identifier: GPL-3.0-or-later
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details: <https://www.gnu.org/licenses/>.
 */

#include <amxmodx>
#include <reapi>

#pragma semicolon 1

new const PLUGIN_NAME[] = "Round Start Score Display";
new const PLUGIN_VERSION[] = "1.0.0";
new const PLUGIN_AUTHOR[] = "alexit (olds.ro)";

new const DICTIONARY[] = "olds_rscore.txt";

const TASK_SHOW = 42147;

// The line is sent a moment after the restart, once the players have respawned.
const Float:SHOW_DELAY = 0.2;

// Where the line is drawn: centred, in the upper part of the screen, HUD channel 1.
const Float:HUD_X = -1.0;
const Float:HUD_Y = 0.25;
const HUD_CHANNEL = 1;

new Float:g_time;           // olds_rscore_time
new g_colorT[16];           // olds_rscore_color_t
new g_colorCT[16];          // olds_rscore_color_ct
new g_showWinLimit;         // olds_rscore_winlimit

new g_winLimit;             // mp_winlimit

public plugin_init()
{
	register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR);
	register_dictionary(DICTIONARY);

	bind_pcvar_float(create_cvar("olds_rscore_time", "4", FCVAR_NONE,
		"Seconds the score line stays on the screen (1 - 15)",
		true, 1.0, true, 15.0), g_time);

	bind_pcvar_string(create_cvar("olds_rscore_color_t", "255 120 60", FCVAR_NONE,
		"Colour of the line when the Terrorists lead: R G B (0 - 255)"), g_colorT, charsmax(g_colorT));

	bind_pcvar_string(create_cvar("olds_rscore_color_ct", "100 150 255", FCVAR_NONE,
		"Colour of the line when the Counter-Terrorists lead: R G B (0 - 255)"), g_colorCT, charsmax(g_colorCT));

	bind_pcvar_num(create_cvar("olds_rscore_winlimit", "0", FCVAR_NONE,
		"1 = the line also shows mp_winlimit (first to N), 0 = only the score",
		true, 0.0, true, 1.0), g_showWinLimit);

	AutoExecConfig(true, "olds_rscore");

	bind_pcvar_num(get_cvar_pointer("mp_winlimit"), g_winLimit);

	RegisterHookChain(RG_CSGameRules_RestartRound, "OnRestartRound_Post", true);

	register_clcmd("say /score", "cmd_score");
	register_clcmd("say_team /score", "cmd_score");
}

public OnRestartRound_Post()
{
	remove_task(TASK_SHOW);
	set_task(SHOW_DELAY, "task_show", TASK_SHOW);
}

public task_show()
{
	new players[MAX_PLAYERS], count;
	get_players(players, count, "c");

	for (new i = 0; i < count; i++)
		show_score(players[i]);
}

public cmd_score(id)
{
	show_score(id);
	return PLUGIN_HANDLED;
}

show_score(id)
{
	new winsT = get_member_game(m_iNumTerroristWins);
	new winsCT = get_member_game(m_iNumCTWins);

	new red, green, blue;
	new leader[16];

	if (winsT > winsCT)
	{
		read_color(g_colorT, red, green, blue);
		formatex(leader, charsmax(leader), "%L", id, "OLDS_RSCORE_T_LEADS");
	}
	else if (winsCT > winsT)
	{
		read_color(g_colorCT, red, green, blue);
		formatex(leader, charsmax(leader), "%L", id, "OLDS_RSCORE_CT_LEADS");
	}
	else
	{
		// A tie: the mix of both colours.
		new redCT, greenCT, blueCT;
		read_color(g_colorT, red, green, blue);
		read_color(g_colorCT, redCT, greenCT, blueCT);
		red = (red + redCT) / 2;
		green = (green + greenCT) / 2;
		blue = (blue + blueCT) / 2;
		formatex(leader, charsmax(leader), "%L", id, "OLDS_RSCORE_TIED");
	}

	new text[96];
	new length = formatex(text, charsmax(text), "%L", id, "OLDS_RSCORE_LINE", winsT, winsCT, leader);

	if (g_showWinLimit && g_winLimit > 0)
		formatex(text[length], charsmax(text) - length, "  %L", id, "OLDS_RSCORE_FIRST_TO", g_winLimit);

	set_hudmessage(red, green, blue, HUD_X, HUD_Y, 0, 0.0, g_time, 0.1, 0.2, HUD_CHANNEL);
	show_hudmessage(id, "%s", text);
}

/**
 * "255 120 60" -> 255, 120, 60. A missing or bad number reads as 255
 * (white), every value is kept within 0 - 255.
 */
read_color(const value[], &red, &green, &blue)
{
	new parts[3][8];
	parse(value, parts[0], charsmax(parts[]), parts[1], charsmax(parts[]), parts[2], charsmax(parts[]));

	red = color_part(parts[0]);
	green = color_part(parts[1]);
	blue = color_part(parts[2]);
}

color_part(const part[])
{
	if (!part[0])
		return 255;

	return clamp(str_to_num(part), 0, 255);
}

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.