#pragma semicolon 1
#include <amxmodx>
#include <reapi>
#define PLUGIN_NAME "ReSpeedometer"
#define PLUGIN_VERS "1.0"
#define PLUGIN_AUTH "PurposeLess"
new g_speed[MAX_CLIENTS + 1], g_skipframes[MAX_CLIENTS + 1], hudsync;
public plugin_init() {
register_plugin(PLUGIN_NAME, PLUGIN_VERS, PLUGIN_AUTH);
register_clcmd("say /speed", "@clcmd_speed");
RegisterHookChain(RG_CBasePlayer_PostThink, "@CBasePlayer_PostThink", .post=true);
hudsync = CreateHudSyncObj();
}
public client_putinserver(id)
{
g_speed[id] = true;
}
public client_disconnected(id)
{
ClearSyncHud(id, hudsync);
}
@clcmd_speed(const id)
{
g_speed[id] = !g_speed[id];
if(!g_speed[id])
{
ClearSyncHud(id, hudsync);
}
}
@CBasePlayer_PostThink(const id)
{
if(!g_speed[id] || ++g_skipframes[id] < 25)
{
return;
}
static Float:velocity[3], Float:speed, Float:speedh;
get_entvar(id, var_velocity, velocity);
speed = vector_length(velocity);
speedh = floatsqroot(floatpower(velocity[0], 2.0) + floatpower(velocity[1], 2.0));
set_hudmessage(255, 0, 0, -1.0, 0.75, 0, 0.0, 0.1, 0.01, 0.0);
ShowSyncHudMsg(id, hudsync, "%3.2f units/second^n%3.2f velocity", speed, speedh);
g_skipframes[id] = 0;
}