Code:
#include <sourcemod>
#include <clientprefs>
public Plugin:myinfo =
{
name = "DtK Velocity HUD",
author = "ArathusX & Bauxe",
description = "Display velocity, kills and deaths",
version = "1.2",
url = "http://www.dying2kill.com.au/"
}
enum playerData
{
p_Frags,
p_Deaths,
Float:p_Velocity,
Float:p_MaxVel,
bool:p_enabled
}
new playersArray[MAXPLAYERS][playerData];
new Handle:p_VelEnCookie = INVALID_HANDLE;
new String:cValue[8];
public OnPluginStart()
{
ServerCommand("sv_hudhint_sound 0");
HookEvent("player_death", Event_player_Death);
HookEvent("round_end", Event_round_end);
HookEvent("round_start", Event_round_start);
RegConsoleCmd("sm_velmet", Cmd_VelMet, "HUD On/Off");
RegConsoleCmd("sm_meter", Cmd_VelMet, "HUD On/Off");
RegConsoleCmd("sm_vel", Cmd_VelMet, "HUD On/Off");
RegConsoleCmd("sm_velocity", Cmd_VelMet, "HUD On/Off");
RegConsoleCmd("sm_speed", Cmd_VelMet, "HUD On/Off");
RegConsoleCmd("sm_hud", Cmd_VelMet, "HUD On/Off");
p_VelEnCookie = RegClientCookie("velmet_velencookie", "VelMet VelEn Cookie", CookieAccess_Protected);
for(new i = 1; i < MAXPLAYERS; i++)
{
if(!AreClientCookiesCached(i))
{
continue;
}
OnClientCookiesCached(i);
}
}
public OnClientConnected(client)
{
playersArray[client][p_Frags] = 0;
playersArray[client][p_Deaths] = 0;
if(AreClientCookiesCached(client))
{
OnClientCookiesCached(client);
}
}
public OnClientCookiesCached(client)
{
GetClientCookie(client, p_VelEnCookie, cValue, sizeof(cValue));
playersArray[client][p_enabled] = true;
if(cValue[0] != '\0')
{
playersArray[client][p_enabled] = (cValue[0] != '\0' && StringToInt(cValue));
}
}
public Action:Event_player_Death(Handle:event, const String:name[], bool:dontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));
new attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
playersArray[client][p_Deaths] = playersArray[client][p_Deaths] + 1;
if(attacker != client)
{
playersArray[attacker][p_Frags] = playersArray[attacker][p_Frags] + 1;
}
}
public Action:OnPlayerRunCmd(client)
{
if(IsClientInGame(client) && IsPlayerAlive(client) && !IsFakeClient(client))
{
decl Float:fVelocity[3];
GetEntPropVector(client, Prop_Data, "m_vecVelocity", fVelocity);
playersArray[client][p_Velocity] = SquareRoot(Pow(fVelocity[0], 2.0) + Pow(fVelocity[1], 2.0) + Pow(fVelocity[2], 2.0));
if(playersArray[client][p_Velocity] > playersArray[client][p_MaxVel])
{
playersArray[client][p_MaxVel] = playersArray[client][p_Velocity];
}
if(playersArray[client][p_enabled])
{
PrintHintText(client, "[ VelMet Surf Velocity ]\nVelocity: %.2f\nKills: %i\nDeaths: %i", playersArray[client][p_Velocity], playersArray[client][p_Frags], playersArray[client][p_Deaths]);
}
}
}
public Action:Event_round_end(Handle:event, const String:name[], bool:dontBroadcast)
{
new Float:roundMax;
new clientMax;
decl String:p_name[64];
roundMax = 0.0;
for(new i = 1; i < MAXPLAYERS; i++)
{
if(IsClientInGame(i) && !IsFakeClient(i) && playersArray[i][p_MaxVel] > 0.0)
{
if(roundMax < playersArray[i][p_MaxVel])
{
GetClientName(i, p_name, sizeof(p_name));
clientMax = i;
roundMax = playersArray[i][p_MaxVel];
}
PrintToChat(i, "\x05[VelMet] \x01My Max Velocity: %.2f.", playersArray[i][p_MaxVel]);
}
}
GetClientName(clientMax, p_name, sizeof(p_name));
if(roundMax > 0.0)
{
PrintToChatAll("\x05[VelMet] \x01%s had the Highest Velocity, with: %.2f.", p_name, roundMax);
}
}
public Action:Event_round_start(Handle:event, const String:name[], bool:dontBroadcast)
{
for(new i = 0; i < MAXPLAYERS; i++)
{
playersArray[i][p_MaxVel] = 0.0;
}
}
//COMMANDS
public Action:Cmd_VelMet(client, args)
{
if(IsClientInGame(client) && !IsFakeClient(client))
{
decl String:str[8];
if(playersArray[client][p_enabled])
{
playersArray[client][p_enabled] = false;
IntToString(playersArray[client][p_enabled], str, sizeof(str));
SetClientCookie(client, p_VelEnCookie, str);
PrintToChat(client, "\x05[VelMet] \x01Velocity HUD Disabled.");
}
else
{
playersArray[client][p_enabled] = true;
IntToString(playersArray[client][p_enabled], str, sizeof(str));
SetClientCookie(client, p_VelEnCookie, str);
PrintToChat(client, "\x05[VelMet] \x01Velocity HUD Enabled.");
}
}
return Plugin_Handled
}