/*
* GunGame Ranking HUD (olds.ro)
* Copyright (C) 2026 daemon (olds.ro), written by daemon's plugin agent
*
* 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/>.
*
* Shows the GunGame leaders (name and level) in the top-left of the HUD, plus your own row
* when you are not among them. The level comes from the GunGame core's gg_get_level(id).
*
* Cvars: olds_ggrank_top 5 (1-10), olds_ggrank_x 0.02, olds_ggrank_y 0.18,
* olds_ggrank_interval 2.0 (0.5-30 seconds)
* Say: /ggrank hides or shows the HUD for you only
* Admin: amx_ggrank_show (ADMIN_ADMIN) prints the current ranking to your console
*/
#include <amxmodx>
#include <amxmisc>
#pragma semicolon 0
#pragma reqlib "gungame"
/* Provided by the GunGame core (library "gungame"). */
native gg_get_level(id)
#define PLUGIN "GunGame Ranking HUD"
#define VERSION "1.0.0"
#define AUTHOR "daemon (olds.ro)"
#define TASK_DRAW 8390
#define MAX_TOP 10
new g_top
new Float:g_x
new Float:g_y
new Float:g_interval
new g_pInterval
new g_sync
new bool:g_hidden[MAX_PLAYERS + 1]
new g_level[MAX_PLAYERS + 1]
new g_order[MAX_PLAYERS]
new g_count
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
bind_pcvar_num(create_cvar("olds_ggrank_top", "5", FCVAR_NONE,
"Rows in the ranking (1-10)", true, 1.0, true, float(MAX_TOP)), g_top)
bind_pcvar_float(create_cvar("olds_ggrank_x", "0.02", FCVAR_NONE,
"HUD x position (0-1, -1 = centre)", true, -1.0, true, 1.0), g_x)
bind_pcvar_float(create_cvar("olds_ggrank_y", "0.18", FCVAR_NONE,
"HUD y position (0-1, -1 = centre)", true, -1.0, true, 1.0), g_y)
g_pInterval = create_cvar("olds_ggrank_interval", "2.0", FCVAR_NONE,
"Seconds between HUD refreshes (0.5-30)", true, 0.5, true, 30.0)
bind_pcvar_float(g_pInterval, g_interval)
hook_cvar_change(g_pInterval, "on_interval_change")
register_clcmd("say /ggrank", "cmd_toggle")
register_clcmd("say_team /ggrank", "cmd_toggle")
register_concmd("amx_ggrank_show", "cmd_show", ADMIN_ADMIN, "- print the GunGame ranking")
register_dictionary("olds_ggrank.txt")
g_sync = CreateHudSyncObj()
AutoExecConfig(true, "olds_ggrank")
}
public plugin_cfg()
{
start_task()
}
public on_interval_change(pcvar, const oldValue[], const newValue[])
{
/* bind_pcvar_float may run after this hook, so read the new value here. */
g_interval = floatclamp(str_to_float(newValue), 0.5, 30.0)
start_task()
}
start_task()
{
remove_task(TASK_DRAW)
set_task(floatclamp(g_interval, 0.5, 30.0), "task_draw", TASK_DRAW, _, _, "b")
}
public client_putinserver(id)
{
g_hidden[id] = false
}
public client_disconnected(id)
{
g_hidden[id] = false
}
public cmd_toggle(id)
{
if (!is_user_connected(id))
return PLUGIN_CONTINUE
g_hidden[id] = !g_hidden[id]
if (g_hidden[id])
{
ClearSyncHud(id, g_sync)
client_print_color(id, print_team_default, "%L", id, "GGRANK_HIDDEN")
}
else
{
client_print_color(id, print_team_default, "%L", id, "GGRANK_SHOWN")
draw_for(id)
}
return PLUGIN_HANDLED
}
public cmd_show(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
collect()
new name[32]
console_print(id, "%L", id, "GGRANK_CONSOLE_HEAD", g_count)
for (new i = 0; i < g_count; i++)
{
get_user_name(g_order[i], name, charsmax(name))
console_print(id, "%d. %s - %L %d", i + 1, name, id, "GGRANK_LEVEL", g_level[g_order[i]])
}
return PLUGIN_HANDLED
}
public task_draw()
{
collect()
if (!g_count)
return
for (new id = 1; id <= MaxClients; id++)
{
if (is_user_connected(id) && !is_user_bot(id) && !is_user_hltv(id) && !g_hidden[id])
draw_for(id)
}
}
/* Fills g_order with the ranked players, highest level first. */
collect()
{
g_count = 0
for (new id = 1; id <= MaxClients; id++)
{
if (!is_user_connected(id) || is_user_hltv(id))
continue
new level = gg_get_level(id)
g_level[id] = level < 0 ? 0 : level
g_order[g_count++] = id
}
if (g_count > 1)
SortCustom1D(g_order, g_count, "sort_level")
}
public sort_level(a, b)
{
if (g_level[a] != g_level[b])
return g_level[a] > g_level[b] ? -1 : 1
return a < b ? -1 : (a > b ? 1 : 0)
}
draw_for(id)
{
if (!g_count)
collect()
if (!g_count)
return
new text[512], len, name[32], mark[4], own = -1
new rows = clamp(g_top, 1, MAX_TOP)
if (rows > g_count)
rows = g_count
len = formatex(text, charsmax(text), "%L^n", id, "GGRANK_TITLE")
for (new i = 0; i < g_count; i++)
{
if (g_order[i] == id)
own = i
if (i >= rows)
continue
get_user_name(g_order[i], name, charsmax(name))
if (g_order[i] == id)
copy(mark, charsmax(mark), "> ")
else
mark[0] = EOS
len += formatex(text[len], charsmax(text) - len, "%s%d. %s - %L %d^n",
mark, i + 1, name, id, "GGRANK_LEVEL", g_level[g_order[i]])
}
if (own >= rows)
formatex(text[len], charsmax(text) - len, "...^n> %d. %L - %L %d",
own + 1, id, "GGRANK_YOU", id, "GGRANK_LEVEL", g_level[id])
set_hudmessage(255, 200, 60, g_x, g_y, 0, 0.0, floatclamp(g_interval, 0.5, 30.0) + 0.2, 0.0, 0.0, -1)
ShowSyncHudMsg(id, g_sync, "%s", text)
}