/*
* CSB Speedometer
* Copyright (C) 2026 counter-strike-boost.com
*
* Shows the player's horizontal speed (units/s, from pev_velocity) as a live
* HUD number, colours it against configurable thresholds, and tracks a KZ-style
* peak speed for the current life. Refreshed on a short task and toggled per
* player with say /speed.
*
* 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. It 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 for details.
*/
#include
#include
new const PLUGIN[] = "CSB Speedometer"
new const VERSION[] = "1.0.0"
new const AUTHOR[] = "counter-strike-boost.com"
new g_pEnabled, g_pMid, g_pFast, g_pShowPeak
new bool:g_bShow[33]
new Float:g_fPeak[33]
new g_iSync
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
g_pEnabled = register_cvar("csb_speed_enabled", "1")
g_pMid = register_cvar("csb_speed_mid", "300")
g_pFast = register_cvar("csb_speed_fast", "500")
g_pShowPeak = register_cvar("csb_speed_peak", "1")
register_clcmd("say /speed", "cmdToggle")
register_clcmd("say_team /speed", "cmdToggle")
register_event("ResetHUD", "eventSpawn", "b")
g_iSync = CreateHudSyncObj()
set_task(0.2, "taskSpeed", 0, _, _, "b")
}
public client_putinserver(id)
{
g_bShow[id] = true
g_fPeak[id] = 0.0
}
public cmdToggle(id)
{
g_bShow[id] = !g_bShow[id]
client_print(id, print_chat, "[CSB] Speedometer %s.", g_bShow[id] ? "enabled" : "disabled")
return PLUGIN_HANDLED
}
public eventSpawn(id)
{
g_fPeak[id] = 0.0
}
public taskSpeed()
{
if (!get_pcvar_num(g_pEnabled))
return
new mid = get_pcvar_num(g_pMid)
new fast = get_pcvar_num(g_pFast)
new bool:peak = get_pcvar_num(g_pShowPeak) != 0
new players[32], num, id
get_players(players, num, "a")
for (new i = 0; i < num; i++)
{
id = players[i]
if (!g_bShow[id])
continue
static Float:fVel[3]
pev(id, pev_velocity, fVel)
new Float:speed = floatsqroot(fVel[0] * fVel[0] + fVel[1] * fVel[1])
new iSpeed = floatround(speed)
if (speed > g_fPeak[id])
g_fPeak[id] = speed
new r = 0, g = 255, b = 0
if (iSpeed >= fast)
{
r = 255
g = 40
b = 40
}
else if (iSpeed >= mid)
{
r = 255
g = 200
b = 0
}
set_hudmessage(r, g, b, -1.0, 0.82, 0, 0.0, 0.25, 0.0, 0.0, -1)
if (peak)
ShowSyncHudMsg(id, g_iSync, "%d u/s^nPeak: %d u/s", iSpeed, floatround(g_fPeak[id]))
else
ShowSyncHudMsg(id, g_iSync, "%d u/s", iSpeed)
}
}