exclude specs from average hour count if not too many people are active on the server
This commit is contained in:
parent
b18d551cf1
commit
bddf4ecab2
@ -2,6 +2,7 @@
|
||||
#define PLUGIN_AUTHOR "jenz"
|
||||
#define PLUGIN_VERSION "1.1"
|
||||
#include <sourcemod>
|
||||
#include <cstrike>
|
||||
#include <PlayerManager>
|
||||
#include <AFKManager>
|
||||
|
||||
@ -12,6 +13,7 @@ Handle g_h_time_activity = null;
|
||||
char g_cTimeRecords[100][128];
|
||||
int g_iPlayerTimeServer[MAXPLAYERS + 1];
|
||||
int g_iPlayerAFKTime;
|
||||
int g_iPlayerCount_excludeSpec;
|
||||
|
||||
public Plugin myinfo =
|
||||
{
|
||||
@ -91,6 +93,11 @@ public void OnPluginStart()
|
||||
HookConVarChange((cvar = CreateConVar("sm_mapchooser_afk_detect_time", "120", "Time in seconds until a player is considered as AFK and therefore excluded from player average time.")), Cvar_playerAFKTime);
|
||||
g_iPlayerAFKTime = cvar.IntValue;
|
||||
delete cvar;
|
||||
|
||||
ConVar cvar1;
|
||||
HookConVarChange((cvar1 = CreateConVar("sm_exclude_specs_avghour", "20", "How many players must be considered active on the server before specs are included in generating the average hour count")), Cvar_playerExcludeSpec);
|
||||
g_iPlayerCount_excludeSpec = cvar1.IntValue;
|
||||
delete cvar1;
|
||||
g_hTimer_avg_hour_count = CreateTimer(1800.0, log_average_hour_count, _, TIMER_REPEAT);
|
||||
}
|
||||
|
||||
@ -114,6 +121,11 @@ public void Cvar_playerAFKTime(ConVar convar, const char[] oldValue, const char[
|
||||
g_iPlayerAFKTime = convar.IntValue;
|
||||
}
|
||||
|
||||
public void Cvar_playerExcludeSpec(ConVar convar, const char[] oldValue, const char[] newValue)
|
||||
{
|
||||
g_iPlayerCount_excludeSpec = convar.IntValue;
|
||||
}
|
||||
|
||||
public APLRes AskPluginLoad2(Handle myself, bool late, char [] error, int err_max)
|
||||
{
|
||||
CreateNative("GetAveragePlayerTimeOnServer", Native_GetAveragePlayerActiveTimeServer);
|
||||
@ -124,10 +136,24 @@ public int GetAveragePlayerActiveTimeServer()
|
||||
{
|
||||
int total_hours = 0;
|
||||
int total_players = 0;
|
||||
int spec_player_count = 0;
|
||||
for (int i = 0; i < MaxClients; i++)
|
||||
{
|
||||
//checking player count before deciding if including or excluding spectators from actual average
|
||||
//the purpose of this is me (jenz) not boosting the hour average insanely when the server is very empty. (i often sit spec without playing and that ruins the generated average when low population because the count gets way too high due to me. But if i were actually playing it would instead be fine)
|
||||
if (IsValidClient(i) && !IsFakeClient(i) && !IsClientSourceTV(i) && !is_bot_player[i] && PM_IsPlayerSteam(i) && GetClientIdleTime(i) < g_iPlayerAFKTime)
|
||||
{
|
||||
spec_player_count++;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < MaxClients; i++)
|
||||
{
|
||||
if (IsValidClient(i) && !IsFakeClient(i) && !IsClientSourceTV(i) && !is_bot_player[i] && PM_IsPlayerSteam(i) && GetClientIdleTime(i) < g_iPlayerAFKTime)
|
||||
{
|
||||
if (spec_player_count <= g_iPlayerCount_excludeSpec && GetClientTeam(i) == CS_TEAM_SPECTATOR)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
total_hours += g_iPlayerTimeServer[i];
|
||||
total_players++;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user