Add sm_realclients to FakeClients and update several plugins

FakeClients: sm_realclients, autism bots counted separately.

Updated: Extend, HostnameManager, PlayerRankings_nohlstats.

Add shared include: BotTargeting.
This commit is contained in:
2026-11-24 03:21:45 +00:00
parent dd33584e57
commit 7c111cd0f8
5 changed files with 249 additions and 169 deletions
+4 -3
View File
@@ -59,7 +59,7 @@ public void OnPluginStart()
g_cvarExtendVote = CreateConVar("sm_extendvote_enabled", "1", "Enable Extend Vote? [1 = Enable | 0 = Disable]", FCVAR_NONE, true, 0.0, true, 1.0); g_cvarExtendVote = CreateConVar("sm_extendvote_enabled", "1", "Enable Extend Vote? [1 = Enable | 0 = Disable]", FCVAR_NONE, true, 0.0, true, 1.0);
g_cvarExtendVoteTime = CreateConVar("sm_extendvote_time", "15", "Time that will be added to mp_timelimit shall the extend vote succeed", FCVAR_NONE, true, 1.0); g_cvarExtendVoteTime = CreateConVar("sm_extendvote_time", "15", "Time that will be added to mp_timelimit shall the extend vote succeed", FCVAR_NONE, true, 1.0);
g_cvarExtendVoteMaxDuration = CreateConVar("sm_extendvote_max_duration", "30", "Maximum minutes an admin can request with \"sm_extend <time>\"", FCVAR_NONE, true, 1.0); g_cvarExtendVoteMaxDuration = CreateConVar("sm_extendvote_max_duration", "30", "Maximum minutes an admin can request with \"sm_voteextend <time>\"", FCVAR_NONE, true, 1.0);
g_cvarExtendVotePercent = CreateConVar("sm_extendvote_percent", "0.6", "Percentage of \"yes\" votes required to consider the vote successful", FCVAR_NONE, true, 0.05, true, 1.0); g_cvarExtendVotePercent = CreateConVar("sm_extendvote_percent", "0.6", "Percentage of \"yes\" votes required to consider the vote successful", FCVAR_NONE, true, 0.05, true, 1.0);
g_cvarExtendVotePercentIncrement = CreateConVar("sm_extendvote_percent_increment", "0.1", "Percentage added to the required \"yes\" votes for each successful extend vote on the current map", FCVAR_NONE, true, 0.0, true, 1.0); g_cvarExtendVotePercentIncrement = CreateConVar("sm_extendvote_percent_increment", "0.1", "Percentage added to the required \"yes\" votes for each successful extend vote on the current map", FCVAR_NONE, true, 0.0, true, 1.0);
g_cvarExtendVotePercentMax = CreateConVar("sm_extendvote_percent_max", "0.9", "Maximum percentage of \"yes\" votes that can be required after increments", FCVAR_NONE, true, 0.05, true, 1.0); g_cvarExtendVotePercentMax = CreateConVar("sm_extendvote_percent_max", "0.9", "Maximum percentage of \"yes\" votes that can be required after increments", FCVAR_NONE, true, 0.05, true, 1.0);
@@ -85,8 +85,9 @@ public void OnPluginStart()
if (g_cvarMpTimeLimit != null) if (g_cvarMpTimeLimit != null)
{ {
RegAdminCmd("sm_extend", Command_Extend, ADMFLAG_GENERIC, "Add more time to mp_timelimit");
RegAdminCmd("sm_extendmap", Command_Extend, ADMFLAG_GENERIC, "Add more time to mp_timelimit"); RegAdminCmd("sm_extendmap", Command_Extend, ADMFLAG_GENERIC, "Add more time to mp_timelimit");
RegAdminCmd("sm_extend", Command_ExtendVote, ADMFLAG_GENERIC, "sm_extend [time] - Start an extendvote"); RegAdminCmd("sm_voteextend", Command_ExtendVote, ADMFLAG_GENERIC, "sm_voteextend [time] - Start an extendvote");
RegAdminCmd("sm_settimeleft", Command_SetTimeLeft, ADMFLAG_GENERIC, "sm_settimeleft <minutes> - Set the time left on the map"); RegAdminCmd("sm_settimeleft", Command_SetTimeLeft, ADMFLAG_GENERIC, "sm_settimeleft <minutes> - Set the time left on the map");
// Relies on the m_fRoundStartTime gamerules prop, which only Counter-Strike games have // Relies on the m_fRoundStartTime gamerules prop, which only Counter-Strike games have
@@ -149,7 +150,7 @@ public Action Command_Extend_Wins(int client, int argc)
public Action Command_Extend(int client, int argc) public Action Command_Extend(int client, int argc)
{ {
return HandleLimitCommand(client, argc, g_cvarMpTimeLimit, "sm_extendmap", "minutes", "Unit Minute", "Unit Minutes"); return HandleLimitCommand(client, argc, g_cvarMpTimeLimit, "sm_extend", "minutes", "Unit Minute", "Unit Minutes");
} }
public Action Command_ExtendVote(int client, int argc) public Action Command_ExtendVote(int client, int argc)
+135 -3
View File
@@ -2,9 +2,16 @@
#include <sdktools> #include <sdktools>
#include <cstrike> #include <cstrike>
#undef REQUIRE_PLUGIN
#include <AFKManager>
#include <BotTargeting>
#define REQUIRE_PLUGIN
#pragma semicolon 1 #pragma semicolon 1
#pragma newdecls required #pragma newdecls required
ConVar g_cvRealClientsAfkTime;
ArrayList g_hNames; ArrayList g_hNames;
ArrayList g_hClanNames; ArrayList g_hClanNames;
@@ -36,6 +43,9 @@ public void OnPluginStart()
{ {
RegAdminCmd("sm_debugfakes", Command_DebugFakes, ADMFLAG_GENERIC, "Shows the amount of fake-clients on server"); RegAdminCmd("sm_debugfakes", Command_DebugFakes, ADMFLAG_GENERIC, "Shows the amount of fake-clients on server");
RegAdminCmd("sm_fakes", Command_Fakes, ADMFLAG_GENERIC, "Shows the fake-clients on server"); RegAdminCmd("sm_fakes", Command_Fakes, ADMFLAG_GENERIC, "Shows the fake-clients on server");
RegAdminCmd("sm_realclients", Command_RealClients, ADMFLAG_GENERIC, "Shows the real clients on server, split into active and spec/afk");
g_cvRealClientsAfkTime = CreateConVar("sm_realclients_afk_time", "30", "Seconds idle (AFKManager) before sm_realclients lists a player on a team as AFK", 0, true, 0.0);
int arraySize = ByteCountToCells(MAX_NAME_LENGTH); int arraySize = ByteCountToCells(MAX_NAME_LENGTH);
g_hNames = CreateArray(arraySize); g_hNames = CreateArray(arraySize);
@@ -418,6 +428,7 @@ public Action Command_DebugFakes(int client, int argc)
{ {
int iFakes = 0; int iFakes = 0;
int iFakesInTeam = 0; int iFakesInTeam = 0;
int iAutismBots = 0;
int iPlayers = GetClientCount(false); int iPlayers = GetClientCount(false);
for(int i = 1; i <= MaxClients; i++) for(int i = 1; i <= MaxClients; i++)
@@ -430,15 +441,30 @@ public Action Command_DebugFakes(int client, int argc)
{ {
iFakes++; iFakes++;
iPlayers--; iPlayers--;
} if (IsClientInGame(i) && GetClientTeam(i) > CS_TEAM_SPECTATOR)
if (IsFakeClient(i) && GetClientTeam(i) > CS_TEAM_SPECTATOR)
iFakesInTeam++; iFakesInTeam++;
} }
else if (IsAutismBot(i))
{
iAutismBots++;
iPlayers--;
}
}
ReplyToCommand(client, "[SM] There are currently %d Fake-Clients, from which %d are in Spectate. Real Clients %d", iFakes, iFakes - iFakesInTeam, iPlayers); ReplyToCommand(client, "[SM] There are currently %d Fake-Clients, from which %d are in Spectate. Autism Bots %d. Real Clients %d", iFakes, iFakes - iFakesInTeam, iAutismBots, iPlayers);
return Plugin_Handled; return Plugin_Handled;
} }
//----------------------------------------------------------------------------------------------------
// Purpose: autism bots are real Steam clients (BotTargeting SteamID list) that statistics treat as fakes
//----------------------------------------------------------------------------------------------------
bool IsAutismBot(int client)
{
return GetFeatureStatus(FeatureType_Native, "IsClientAutismBot") == FeatureStatus_Available
&& IsClientInGame(client) && IsClientAuthorized(client) && !IsFakeClient(client)
&& IsClientAutismBot(client);
}
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
// Purpose: // Purpose:
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
@@ -457,6 +483,12 @@ public Action Command_Fakes(int client, int args)
StrCat(aBuf, sizeof(aBuf), aBuf2); StrCat(aBuf, sizeof(aBuf), aBuf2);
StrCat(aBuf, sizeof(aBuf), ", "); StrCat(aBuf, sizeof(aBuf), ", ");
} }
else if(IsAutismBot(i))
{
GetClientName(i, aBuf2, sizeof(aBuf2));
StrCat(aBuf, sizeof(aBuf), aBuf2);
StrCat(aBuf, sizeof(aBuf), " (autism bot), ");
}
} }
} }
@@ -471,6 +503,106 @@ public Action Command_Fakes(int client, int args)
return Plugin_Handled; return Plugin_Handled;
} }
//----------------------------------------------------------------------------------------------------
// Purpose: lists real clients split into active (on a team, not idle) and spec/afk
//----------------------------------------------------------------------------------------------------
public Action Command_RealClients(int client, int args)
{
bool bAfkKnown = GetFeatureStatus(FeatureType_Native, "GetClientIdleTime") == FeatureStatus_Available;
int iAfkTime = g_cvRealClientsAfkTime.IntValue;
int iActive[MAXPLAYERS + 1], iInactive[MAXPLAYERS + 1], iAutism[MAXPLAYERS + 1];
int iActiveCount = 0, iInactiveCount = 0, iAutismCount = 0;
for(int i = 1; i <= MaxClients; i++)
{
if(!IsClientInGame(i) || IsFakeClient(i) || IsClientSourceTV(i))
continue;
if(IsAutismBot(i))
{
iAutism[iAutismCount++] = i;
continue;
}
if(GetClientTeam(i) > CS_TEAM_SPECTATOR && !(bAfkKnown && iAfkTime > 0 && GetClientIdleTime(i) >= iAfkTime))
iActive[iActiveCount++] = i;
else
iInactive[iInactiveCount++] = i;
}
// Name lists overflow a chat line, so they always go to console.
if(GetCmdReplySource() == SM_REPLY_TO_CHAT)
ReplyToCommand(client, "[SM] Real clients: %d (active %d, spec/afk %d). See console for the list.", iActiveCount + iInactiveCount, iActiveCount, iInactiveCount);
char sBar[64];
BuildProgressBar(sBar, sizeof(sBar), iActiveCount + iInactiveCount, MaxClients);
PrintRealClientsLine(client, "Real %s %d/%d", sBar, iActiveCount + iInactiveCount, MaxClients);
BuildProgressBar(sBar, sizeof(sBar), iActiveCount, MaxClients);
PrintRealClientsLine(client, "Active %s %d/%d", sBar, iActiveCount, MaxClients);
PrintRealClientsLine(client, "[SM] Real clients: %d (active %d, spec/afk %d)%s", iActiveCount + iInactiveCount, iActiveCount, iInactiveCount,
bAfkKnown ? "" : ", AFKManager not loaded so only spectators count as inactive");
PrintRealClientsLine(client, "Active (%d):", iActiveCount);
for(int j = 0; j < iActiveCount; j++)
PrintRealClientsLine(client, " %N", iActive[j]);
PrintRealClientsLine(client, "Spec/AFK (%d):", iInactiveCount);
for(int j = 0; j < iInactiveCount; j++)
{
int i = iInactive[j];
int iTeam = GetClientTeam(i);
int iIdle = bAfkKnown ? GetClientIdleTime(i) : 0;
if(iTeam > CS_TEAM_SPECTATOR)
PrintRealClientsLine(client, " %N (afk %dm%02ds, %s)", i, iIdle / 60, iIdle % 60, iTeam == CS_TEAM_CT ? "CT" : "T");
else if(bAfkKnown)
PrintRealClientsLine(client, " %N (%s, idle %dm%02ds)", i, iTeam == CS_TEAM_SPECTATOR ? "spec" : "unassigned", iIdle / 60, iIdle % 60);
else
PrintRealClientsLine(client, " %N (%s)", i, iTeam == CS_TEAM_SPECTATOR ? "spec" : "unassigned");
}
if(GetFeatureStatus(FeatureType_Native, "IsClientAutismBot") != FeatureStatus_Available)
{
PrintRealClientsLine(client, "Autism bots: unknown, BotTargeting not loaded so they count as real clients above");
}
else if(iAutismCount)
{
PrintRealClientsLine(client, "Autism bots, counted as fakes (%d):", iAutismCount);
for(int j = 0; j < iAutismCount; j++)
PrintRealClientsLine(client, " %N", iAutism[j]);
}
return Plugin_Handled;
}
// [##########--------------------] style bar, filled in proportion to value/max.
void BuildProgressBar(char[] buffer, int maxlen, int value, int max, int width = 32)
{
int iFilled = max > 0 ? RoundToNearest(float(value) / float(max) * float(width)) : 0;
if(iFilled > width)
iFilled = width;
int iPos = 0;
buffer[iPos++] = '[';
for(int i = 0; i < width && iPos < maxlen - 2; i++)
buffer[iPos++] = i < iFilled ? '#' : '-';
buffer[iPos++] = ']';
buffer[iPos] = '\0';
}
void PrintRealClientsLine(int client, const char[] format, any ...)
{
char sLine[256];
VFormat(sLine, sizeof(sLine), format, 3);
if(client == 0)
PrintToServer("%s", sLine);
else
PrintToConsole(client, "%s", sLine);
}
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
// Purpose: // Purpose:
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
+15 -1
View File
@@ -49,11 +49,22 @@ public void OnPluginStart()
g_cvMaxLength = CreateConVar("sm_hostname_max_length", "63", "Fold LagCompensation, then NoSteam, out of the hostname while it is longer than this many bytes (the server browser shows at most 63)", 0, true, 1.0, true, 127.0); g_cvMaxLength = CreateConVar("sm_hostname_max_length", "63", "Fold LagCompensation, then NoSteam, out of the hostname while it is longer than this many bytes (the server browser shows at most 63)", 0, true, 1.0, true, 127.0);
g_cvSendToClients = CreateConVar("sm_hostname_send_to_clients", "1", "Send the new hostname to connected clients so their scoreboard updates without a reconnect", 0, true, 0.0, true, 1.0); g_cvSendToClients = CreateConVar("sm_hostname_send_to_clients", "1", "Send the new hostname to connected clients so their scoreboard updates without a reconnect", 0, true, 0.0, true, 1.0);
g_cvFormattedHostname.AddChangeHook(OnFormatChanged);
g_cvMaxLength.AddChangeHook(OnFormatChanged);
CreateTimer(60.0, TimerRepeat, INVALID_HANDLE, TIMER_REPEAT); CreateTimer(60.0, TimerRepeat, INVALID_HANDLE, TIMER_REPEAT);
HookEvent("round_start", OnRoundStart, EventHookMode_PostNoCopy); HookEvent("round_start", OnRoundStart, EventHookMode_PostNoCopy);
} }
//----------------------------------------------------------------------------------------------------
// Purpose: Apply a new format (e.g. from event_on.cfg) straight away instead of on the next timer.
//----------------------------------------------------------------------------------------------------
public void OnFormatChanged(ConVar convar, const char[] oldValue, const char[] newValue)
{
RefreshHostname();
}
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
// Purpose: // Purpose:
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
@@ -107,10 +118,12 @@ public void OnLibraryRemoved(const char[] sName)
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
// Purpose: // Purpose: Refresh now for anything that changed during the restart, then again once StageDisplay
// has worked out the new stage (it checks 3s after round_start).
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
public void OnRoundStart(Event hEvent, const char[] sEvent, bool bDontBroadcast) public void OnRoundStart(Event hEvent, const char[] sEvent, bool bDontBroadcast)
{ {
RefreshHostname();
CreateTimer(5.0, TimerRoundStart, INVALID_HANDLE, TIMER_FLAG_NO_MAPCHANGE); CreateTimer(5.0, TimerRoundStart, INVALID_HANDLE, TIMER_FLAG_NO_MAPCHANGE);
} }
@@ -120,6 +133,7 @@ public void OnRoundStart(Event hEvent, const char[] sEvent, bool bDontBroadcast)
public Action TimerRoundStart(Handle timer) public Action TimerRoundStart(Handle timer)
{ {
RefreshHostname(); RefreshHostname();
return Plugin_Stop;
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
@@ -14,7 +14,6 @@ bool g_bEngineCSGO;
bool g_bHideCrown[MAXPLAYERS+1]; bool g_bHideCrown[MAXPLAYERS+1];
bool g_bHideDialog[MAXPLAYERS+1]; bool g_bHideDialog[MAXPLAYERS+1];
bool g_bProtection[MAXPLAYERS+1]; bool g_bProtection[MAXPLAYERS+1];
bool g_bTitleSet[MAXPLAYERS+1];
/* COOKIES */ /* COOKIES */
Handle g_hCookie_HideCrown; Handle g_hCookie_HideCrown;
@@ -31,14 +30,6 @@ ConVar g_hCVar_Display;
ConVar g_hCVar_HudChannel; ConVar g_hCVar_HudChannel;
ConVar g_hCVar_HudX; ConVar g_hCVar_HudX;
ConVar g_hCVar_HudY; ConVar g_hCVar_HudY;
ConVar g_hCVar_Hostname;
ConVar g_hCVar_HostIP;
ConVar g_hCVar_HostPort;
ConVar g_hCVar_Password;
/* STRINGS */
char g_sRankTitle[MAXPLAYERS+1][128];
char g_sTitleSent[MAXPLAYERS+1][128];
/* INTERGERS */ /* INTERGERS */
int g_iDialogLevel = 100000; int g_iDialogLevel = 100000;
@@ -85,17 +76,12 @@ public void OnPluginStart()
g_hCVar_ProtectionMinimal2 = CreateConVar("sm_topdefenders_minimal_2", "30", "", FCVAR_NONE, true, 1.0, true, 64.0); g_hCVar_ProtectionMinimal2 = CreateConVar("sm_topdefenders_minimal_2", "30", "", FCVAR_NONE, true, 1.0, true, 64.0);
g_hCVar_ProtectionMinimal3 = CreateConVar("sm_topdefenders_minimal_3", "45", "", FCVAR_NONE, true, 1.0, true, 64.0); g_hCVar_ProtectionMinimal3 = CreateConVar("sm_topdefenders_minimal_3", "45", "", FCVAR_NONE, true, 1.0, true, 64.0);
g_hCVar_Grenade = CreateConVar("sm_topdefenders_grenade", "1", "", FCVAR_NONE, true, 0.0, true, 1.0); g_hCVar_Grenade = CreateConVar("sm_topdefenders_grenade", "1", "", FCVAR_NONE, true, 0.0, true, 1.0);
g_hCVar_Display = CreateConVar("sm_topdefenders_display", "2", "Rank display: 0 off, 1 dialog, 2 hudtext, 3 scoreboard title (set sm_hostname_send_to_clients 0 so HostnameManager doesn't overwrite it)", FCVAR_NONE, true, 0.0, true, 3.0); g_hCVar_Display = CreateConVar("sm_topdefenders_display", "1", "Rank display: 0 off, 1 dialog, 2 hudtext", FCVAR_NONE, true, 0.0, true, 2.0);
g_hCVar_HudChannel = CreateConVar("sm_topdefenders_hud_channel", "5", "Hudtext channel for the rank display (0-5)", FCVAR_NONE, true, 0.0, true, 5.0); g_hCVar_HudChannel = CreateConVar("sm_topdefenders_hud_channel", "5", "Hudtext channel for the rank display (0-5)", FCVAR_NONE, true, 0.0, true, 5.0);
g_hCVar_HudX = CreateConVar("sm_topdefenders_hud_x", "0.01", "Hudtext x position for the rank display (-1 centres)", FCVAR_NONE, true, -1.0, true, 1.0); g_hCVar_HudX = CreateConVar("sm_topdefenders_hud_x", "0.01", "Hudtext x position for the rank display (-1 centres)", FCVAR_NONE, true, -1.0, true, 1.0);
g_hCVar_HudY = CreateConVar("sm_topdefenders_hud_y", "0.01", "Hudtext y position for the rank display (-1 centres)", FCVAR_NONE, true, -1.0, true, 1.0); g_hCVar_HudY = CreateConVar("sm_topdefenders_hud_y", "0.01", "Hudtext y position for the rank display (-1 centres)", FCVAR_NONE, true, -1.0, true, 1.0);
AutoExecConfig(true); AutoExecConfig(true);
g_hCVar_Hostname = FindConVar("hostname");
g_hCVar_HostIP = FindConVar("hostip");
g_hCVar_HostPort = FindConVar("hostport");
g_hCVar_Password = FindConVar("sv_password");
g_hCookie_HideCrown = RegClientCookie("topdefenders_hidecrown", "", CookieAccess_Private); g_hCookie_HideCrown = RegClientCookie("topdefenders_hidecrown", "", CookieAccess_Private);
g_hCookie_HideDialog = RegClientCookie("topdefenders_hidedialog", "", CookieAccess_Private); g_hCookie_HideDialog = RegClientCookie("topdefenders_hidedialog", "", CookieAccess_Private);
g_hCookie_Protection = RegClientCookie("topdefenders_protection", "", CookieAccess_Private); g_hCookie_Protection = RegClientCookie("topdefenders_protection", "", CookieAccess_Private);
@@ -117,14 +103,6 @@ public void OnPluginStart()
SetCookieMenuItem(MenuHandler_CookieMenu, 0, "Player Rankings"); SetCookieMenuItem(MenuHandler_CookieMenu, 0, "Player Rankings");
} }
//----------------------------------------------------------------------------------------------------
// Purpose: Hand everyone showing a rank title the real hostname back.
//----------------------------------------------------------------------------------------------------
public void OnPluginEnd()
{
ResetAllTitles();
}
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
// Purpose: // Purpose:
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
@@ -318,21 +296,11 @@ public void OnClientCookiesCached(int client)
g_bProtection[client] = false; g_bProtection[client] = false;
} }
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnClientPutInServer(int client)
{
g_bTitleSet[client] = false;
}
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
// Purpose: // Purpose:
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
public void OnClientDisconnect(int client) public void OnClientDisconnect(int client)
{ {
g_bTitleSet[client] = false;
g_iPlayerDamage[client] = 0; g_iPlayerDamage[client] = 0;
g_iPlayerDamageHits[client] = 0; g_iPlayerDamageHits[client] = 0;
g_iPlayerDamageFrom1K[client] = 0; g_iPlayerDamageFrom1K[client] = 0;
@@ -392,23 +360,14 @@ public Action UpdateDialog(Handle timer)
{ {
int iDisplay = g_hCVar_Display.IntValue; int iDisplay = g_hCVar_Display.IntValue;
if (iDisplay != 3 || g_iDialogLevel <= 0)
ResetAllTitles();
if (g_bEngineCSGO || g_iDialogLevel <= 0 || iDisplay <= 0) if (g_bEngineCSGO || g_iDialogLevel <= 0 || iDisplay <= 0)
return; return;
// Hudtext (held for 1s) and the scoreboard title only need a refresh every 0.5s, the dialog keeps the 0.1s rate. // Hudtext (held for 1s) only needs a refresh every 0.5s, the dialog keeps the 0.1s rate.
static int iHudTick; static int iHudTick;
if (iDisplay >= 2 && (iHudTick++ % 5) != 0) if (iDisplay == 2 && (iHudTick++ % 5) != 0)
return; return;
if (iDisplay == 3)
{
for (int client = 1; client <= MaxClients; client++)
g_sRankTitle[client][0] = '\0';
}
int iSortedList[MAXPLAYERS+1][2]; int iSortedList[MAXPLAYERS+1][2];
int iSortedCount; int iSortedCount;
@@ -425,27 +384,39 @@ public Action UpdateDialog(Handle timer)
SortCustom2D(iSortedList, iSortedCount, SortRankingsList); SortCustom2D(iSortedList, iSortedCount, SortRankingsList);
char sBuffer[128]; char sBuffer[128];
char sRank[16], sDamage[16], sGap[16], sFirst[16];
for (int rank = 0; rank < iSortedCount; rank++) for (int rank = 0; rank < iSortedCount; rank++)
{ {
FormatCommas(rank + 1, sRank, sizeof(sRank));
FormatCommas(iSortedList[rank][1], sDamage, sizeof(sDamage));
switch(rank) switch(rank)
{ {
case(0): Format(sBuffer, sizeof(sBuffer), "#%d (D: %d | P: -%d)", rank + 1, iSortedList[rank][1], iSortedList[rank][1] - iSortedList[rank + 1][1]); case(0):
case(1): Format(sBuffer, sizeof(sBuffer), "#%d (D: %d | N: +%d)", rank + 1, iSortedList[rank][1], iSortedList[rank - 1][1] - iSortedList[rank][1]); {
default: Format(sBuffer, sizeof(sBuffer), "#%d (D: %d | N: +%d | F: +%d)", rank + 1, iSortedList[rank][1], iSortedList[rank - 1][1] - iSortedList[rank][1], iSortedList[0][1] - iSortedList[rank][1]); FormatCommas(iSortedList[rank][1] - iSortedList[rank + 1][1], sGap, sizeof(sGap));
Format(sBuffer, sizeof(sBuffer), "#%s (D: %s | P: -%s)", sRank, sDamage, sGap);
}
case(1):
{
FormatCommas(iSortedList[rank - 1][1] - iSortedList[rank][1], sGap, sizeof(sGap));
Format(sBuffer, sizeof(sBuffer), "#%s (D: %s | N: +%s)", sRank, sDamage, sGap);
}
default:
{
FormatCommas(iSortedList[rank - 1][1] - iSortedList[rank][1], sGap, sizeof(sGap));
FormatCommas(iSortedList[0][1] - iSortedList[rank][1], sFirst, sizeof(sFirst));
Format(sBuffer, sizeof(sBuffer), "#%s (D: %s | N: +%s | F: +%s)", sRank, sDamage, sGap, sFirst);
}
} }
if (iDisplay == 1) if (iDisplay == 1)
SendDialog(iSortedList[rank][0], "%s", g_iDialogLevel, 1, sBuffer); SendDialog(iSortedList[rank][0], "%s", g_iDialogLevel, 1, sBuffer);
else if (iDisplay == 2)
SendRankHud(iSortedList[rank][0], sBuffer);
else else
Format(g_sRankTitle[iSortedList[rank][0]], sizeof(g_sRankTitle[]), "[UNLOZE] Pos. %s", sBuffer); SendRankHud(iSortedList[rank][0], sBuffer);
} }
if (iDisplay == 3)
UpdateTitles();
g_iDialogLevel--; g_iDialogLevel--;
} }
@@ -515,11 +486,14 @@ public void OnRoundEnding(Event hEvent, const char[] sEvent, bool bDontBroadcast
if (iSortedCountDefenders) if (iSortedCountDefenders)
{ {
char sBuffer[512]; char sBuffer[512];
char sDamage[16], sHits[16];
Format(sBuffer, sizeof(sBuffer), "TOP DEFENDERS:"); Format(sBuffer, sizeof(sBuffer), "TOP DEFENDERS:");
if (iSortedListDefenders[0][0]) if (iSortedListDefenders[0][0])
{ {
Format(sBuffer, sizeof(sBuffer), "%s\n1. %N - %d damage in %d hits", sBuffer, iSortedListDefenders[0][0], iSortedListDefenders[0][1], iSortedListDefenders[0][2]); FormatCommas(iSortedListDefenders[0][1], sDamage, sizeof(sDamage));
FormatCommas(iSortedListDefenders[0][2], sHits, sizeof(sHits));
Format(sBuffer, sizeof(sBuffer), "%s\n1. %N - %s damage in %s hits", sBuffer, iSortedListDefenders[0][0], sDamage, sHits);
g_iPlayerWinner[0] = GetSteamAccountID(iSortedListDefenders[0][0]); g_iPlayerWinner[0] = GetSteamAccountID(iSortedListDefenders[0][0]);
@@ -527,7 +501,9 @@ public void OnRoundEnding(Event hEvent, const char[] sEvent, bool bDontBroadcast
if (iSortedListDefenders[1][0]) if (iSortedListDefenders[1][0])
{ {
Format(sBuffer, sizeof(sBuffer), "%s\n2. %N - %d damage in %d hits", sBuffer, iSortedListDefenders[1][0], iSortedListDefenders[1][1], iSortedListDefenders[1][2]); FormatCommas(iSortedListDefenders[1][1], sDamage, sizeof(sDamage));
FormatCommas(iSortedListDefenders[1][2], sHits, sizeof(sHits));
Format(sBuffer, sizeof(sBuffer), "%s\n2. %N - %s damage in %s hits", sBuffer, iSortedListDefenders[1][0], sDamage, sHits);
g_iPlayerWinner[1] = GetSteamAccountID(iSortedListDefenders[1][0]); g_iPlayerWinner[1] = GetSteamAccountID(iSortedListDefenders[1][0]);
@@ -535,7 +511,9 @@ public void OnRoundEnding(Event hEvent, const char[] sEvent, bool bDontBroadcast
if (iSortedListDefenders[2][0]) if (iSortedListDefenders[2][0])
{ {
Format(sBuffer, sizeof(sBuffer), "%s\n3. %N - %d damage in %d hits", sBuffer, iSortedListDefenders[2][0], iSortedListDefenders[2][1], iSortedListDefenders[2][2]); FormatCommas(iSortedListDefenders[2][1], sDamage, sizeof(sDamage));
FormatCommas(iSortedListDefenders[2][2], sHits, sizeof(sHits));
Format(sBuffer, sizeof(sBuffer), "%s\n3. %N - %s damage in %s hits", sBuffer, iSortedListDefenders[2][0], sDamage, sHits);
g_iPlayerWinner[2] = GetSteamAccountID(iSortedListDefenders[2][0]); g_iPlayerWinner[2] = GetSteamAccountID(iSortedListDefenders[2][0]);
@@ -566,11 +544,13 @@ public void OnRoundEnding(Event hEvent, const char[] sEvent, bool bDontBroadcast
if (iSortedCountInfectors) if (iSortedCountInfectors)
{ {
char sBuffer[512]; char sBuffer[512];
char sInfections[16];
Format(sBuffer, sizeof(sBuffer), "TOP INFECTORS:"); Format(sBuffer, sizeof(sBuffer), "TOP INFECTORS:");
if (iSortedListInfectors[0][0]) if (iSortedListInfectors[0][0])
{ {
Format(sBuffer, sizeof(sBuffer), "%s\n1. %N - %d infections", sBuffer, iSortedListInfectors[0][0], iSortedListInfectors[0][1]); FormatCommas(iSortedListInfectors[0][1], sInfections, sizeof(sInfections));
Format(sBuffer, sizeof(sBuffer), "%s\n1. %N - %s infections", sBuffer, iSortedListInfectors[0][0], sInfections);
g_iPlayerWinner[3] = GetSteamAccountID(iSortedListInfectors[0][0]); g_iPlayerWinner[3] = GetSteamAccountID(iSortedListInfectors[0][0]);
@@ -578,7 +558,8 @@ public void OnRoundEnding(Event hEvent, const char[] sEvent, bool bDontBroadcast
if (iSortedListInfectors[1][0]) if (iSortedListInfectors[1][0])
{ {
Format(sBuffer, sizeof(sBuffer), "%s\n2. %N - %d infections", sBuffer, iSortedListInfectors[1][0], iSortedListInfectors[1][1]); FormatCommas(iSortedListInfectors[1][1], sInfections, sizeof(sInfections));
Format(sBuffer, sizeof(sBuffer), "%s\n2. %N - %s infections", sBuffer, iSortedListInfectors[1][0], sInfections);
g_iPlayerWinner[4] = GetSteamAccountID(iSortedListInfectors[1][0]); g_iPlayerWinner[4] = GetSteamAccountID(iSortedListInfectors[1][0]);
@@ -586,7 +567,8 @@ public void OnRoundEnding(Event hEvent, const char[] sEvent, bool bDontBroadcast
if (iSortedListInfectors[2][0]) if (iSortedListInfectors[2][0])
{ {
Format(sBuffer, sizeof(sBuffer), "%s\n3. %N - %d infections", sBuffer, iSortedListInfectors[2][0], iSortedListInfectors[2][1]); FormatCommas(iSortedListInfectors[2][1], sInfections, sizeof(sInfections));
Format(sBuffer, sizeof(sBuffer), "%s\n3. %N - %s infections", sBuffer, iSortedListInfectors[2][0], sInfections);
g_iPlayerWinner[5] = GetSteamAccountID(iSortedListInfectors[2][0]); g_iPlayerWinner[5] = GetSteamAccountID(iSortedListInfectors[2][0]);
@@ -1134,118 +1116,31 @@ void SendRankHud(int client, const char[] text)
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
// Purpose: Rank line as the scoreboard title. Unranked spectators see the title of the player they // Purpose: Writes value with thousands separators, 1487 -> "1,487".
// watch in first or third person, everyone else gets the real hostname back.
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
void UpdateTitles() void FormatCommas(int value, char[] buffer, int maxlen)
{ {
for (int client = 1; client <= MaxClients; client++) char sDigits[16];
IntToString(value, sDigits, sizeof(sDigits));
int iStart = (sDigits[0] == '-') ? 1 : 0;
int iLength = strlen(sDigits);
int iPos;
for (int i = 0; i < iLength && iPos < maxlen - 1; i++)
{ {
if (!IsClientInGame(client) || IsFakeClient(client)) if (i > iStart && (iLength - i) % 3 == 0)
continue;
int source = client;
if (!g_sRankTitle[client][0] && IsClientObserver(client))
{ {
int specMode = GetClientSpectatorMode(client); buffer[iPos++] = ',';
int specTarget = GetClientSpectatorTarget(client);
if ((specMode == SPECMODE_FIRSTPERSON || specMode == SPECMODE_THIRDPERSON) && specTarget >= 1 && specTarget <= MaxClients) if (iPos >= maxlen - 1)
source = specTarget; break;
} }
if (g_bHideDialog[client] || !g_sRankTitle[source][0]) buffer[iPos++] = sDigits[i];
ResetTitle(client);
else
SetTitle(client, g_sRankTitle[source]);
}
} }
//---------------------------------------------------------------------------------------------------- buffer[iPos] = '\0';
// Purpose: Only sends when the title changes.
//----------------------------------------------------------------------------------------------------
void SetTitle(int client, const char[] title)
{
if (g_bTitleSet[client] && strcmp(g_sTitleSent[client], title, true) == 0)
return;
SendClientHostname(client, title);
strcopy(g_sTitleSent[client], sizeof(g_sTitleSent[]), title);
g_bTitleSet[client] = true;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
void ResetTitle(int client)
{
if (!g_bTitleSet[client])
return;
g_bTitleSet[client] = false;
if (!IsClientInGame(client))
return;
char sHostname[128];
g_hCVar_Hostname.GetString(sHostname, sizeof(sHostname));
SendClientHostname(client, sHostname);
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
void ResetAllTitles()
{
for (int client = 1; client <= MaxClients; client++)
ResetTitle(client);
}
//----------------------------------------------------------------------------------------------------
// Purpose: Copied from HostnameManager. The scoreboard only reads the hostname from server_spawn,
// which the client's engine fires locally from svc_ServerInfo on connect. Send a copy
// straight to the client so it never reaches server-side listeners, and fill every field so
// other client listeners (mumble, abuse report, steam share) see the values they got on connect.
//----------------------------------------------------------------------------------------------------
void SendClientHostname(int client, const char[] hostname)
{
Event hEvent = CreateEvent("server_spawn", true);
if (hEvent == null)
return;
int iIP = g_hCVar_HostIP.IntValue;
int iPort = g_hCVar_HostPort.IntValue;
char sAddress[32];
Format(sAddress, sizeof(sAddress), "%d.%d.%d.%d:%d", (iIP >>> 24) & 0xFF, (iIP >>> 16) & 0xFF, (iIP >>> 8) & 0xFF, iIP & 0xFF, iPort);
char sGame[32];
GetGameFolderName(sGame, sizeof(sGame));
char sMap[PLATFORM_MAX_PATH];
GetCurrentMap(sMap, sizeof(sMap));
char sPassword[64];
g_hCVar_Password.GetString(sPassword, sizeof(sPassword));
hEvent.SetString("hostname", hostname);
hEvent.SetString("address", sAddress);
hEvent.SetInt("ip", iIP);
hEvent.SetInt("port", iPort);
hEvent.SetString("game", sGame);
hEvent.SetString("mapname", sMap);
hEvent.SetInt("maxplayers", MaxClients);
hEvent.SetString("os", "LINUX");
hEvent.SetBool("dedicated", IsDedicatedServer());
hEvent.SetBool("password", sPassword[0] != '\0');
hEvent.FireToClient(client);
// FireToClient does not free the event.
hEvent.Cancel();
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
+38
View File
@@ -0,0 +1,38 @@
#if defined _BotTargeting_Included
#endinput
#endif
#define _BotTargeting_Included
/**
* Returns whether the client is one of the autism bots.
* Throws an error if the client is invalid, not in-game or not authorized.
*/
native bool IsClientAutismBot(int client);
/**
* Returns which autism bot the client is.
* Throws an error if the client is invalid, not in-game or not authorized.
*
* @param client Client index.
* @return 1-4 for autism bot 1 to 4, 0 if the client is not an autism bot.
*/
native int GetClientAutismBotIndex(int client);
public SharedPlugin __pl_BotTargeting =
{
name = "BotTargeting",
file = "BotTargeting.smx",
#if defined REQUIRE_PLUGIN
required = 1,
#else
required = 0,
#endif
};
#if !defined REQUIRE_PLUGIN
public __pl_BotTargeting_SetNTVOptional()
{
MarkNativeAsOptional("IsClientAutismBot");
MarkNativeAsOptional("GetClientAutismBotIndex");
}
#endif