From 00a333db0710bf49e1d3cda74bb7a9ab6f2dfc69 Mon Sep 17 00:00:00 2001 From: jenz Date: Sun, 23 Feb 2025 13:16:32 +0100 Subject: [PATCH] removed native, changed from float to int, added minimal default value --- .../scripting/include/unloze_playtime.inc | 12 +-- .../scripting/unloze_player_time.sp | 87 +++---------------- 2 files changed, 13 insertions(+), 86 deletions(-) diff --git a/discord_verificiation/scripting/include/unloze_playtime.inc b/discord_verificiation/scripting/include/unloze_playtime.inc index 83bbc68a..875140ac 100755 --- a/discord_verificiation/scripting/include/unloze_playtime.inc +++ b/discord_verificiation/scripting/include/unloze_playtime.inc @@ -8,17 +8,7 @@ */ native int GetAveragePlayerTimeOnServer(); -/** -* @returns the average playtime of all connected players for rtv, excluding autism bots and fakeclients. -*/ -native int GetAveragePlayerTimeOnServerRTV(); - -/** -* @returns the players worth in connected hours for the rtv -*/ -native int GetPlayerWorthRTV_(int client); - /** * @returns the players rtv amount boost */ -native float GetPlayerWorthRTV_boost_(int client); +native int GetPlayerWorthRTV_boost_(int client); diff --git a/discord_verificiation/scripting/unloze_player_time.sp b/discord_verificiation/scripting/unloze_player_time.sp index 40bf24cb..87cafea2 100644 --- a/discord_verificiation/scripting/unloze_player_time.sp +++ b/discord_verificiation/scripting/unloze_player_time.sp @@ -1,6 +1,6 @@ #pragma semicolon 1 #define PLUGIN_AUTHOR "jenz" -#define PLUGIN_VERSION "1.1" +#define PLUGIN_VERSION "1.2" #include #include #include @@ -17,8 +17,6 @@ int g_iPlayerAFKTime; int g_iPlayerCount_excludeSpec; int g_iPlayerRTVCapacity; -float g_fPlayerRTVWorth[MAXPLAYERS + 1]; - public Plugin myinfo = { name = "UNLOZE_player_time", @@ -51,10 +49,6 @@ public Action time_query_activity(Handle timer, any data) { Format(sServer, sizeof(sServer), "mg_time"); } - else if (i_port == 27023) - { - Format(sServer, sizeof(sServer), "jb_time"); - } else { return Plugin_Continue; @@ -87,7 +81,7 @@ public void OnPluginStart() Database.Connect(SQL_OnDatabaseConnect, "unloze_playtimestats"); } RegConsoleCmd("sm_playtime", Command_Time, "retreives total connection time on all connected servers"); - RegConsoleCmd("sm_topplaytime", Command_TopTime, "retreives top 12 playtime highscores on all connected servers"); + RegConsoleCmd("sm_topplaytime", Command_TopTime, "retreives top 1000 playtime highscores on all connected servers"); g_h_time_activity = CreateTimer(10.0, time_query_activity, INVALID_HANDLE, TIMER_REPEAT); @@ -126,8 +120,6 @@ public void Cvar_playerRTVAverageCap(ConVar convar, const char[] oldValue, const public APLRes AskPluginLoad2(Handle myself, bool late, char [] error, int err_max) { CreateNative("GetAveragePlayerTimeOnServer", Native_GetAveragePlayerActiveTimeServer); - CreateNative("GetAveragePlayerTimeOnServerRTV", Native_GetAveragePlayerActiveTimeServerRTV); - CreateNative("GetPlayerWorthRTV_", Native_GetPlayerWorthRTV); CreateNative("GetPlayerWorthRTV_boost_", Native_GetPlayerWorthRTV_boost); return APLRes_Success; } @@ -140,8 +132,8 @@ public int GetAveragePlayerActiveTimeServer() 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) + //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) + if (IsValidClient(i) && !IsFakeClient(i) && !IsClientSourceTV(i) && !is_bot_player[i] && (GetClientTeam(i) == CS_TEAM_T || GetClientTeam(i) == CS_TEAM_CT)) { active_player_count++; @@ -149,7 +141,7 @@ public int GetAveragePlayerActiveTimeServer() } 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 (IsValidClient(i) && !IsFakeClient(i) && !IsClientSourceTV(i) && !is_bot_player[i] && GetClientIdleTime(i) < g_iPlayerAFKTime) { if (active_player_count < g_iPlayerCount_excludeSpec && GetClientTeam(i) != CS_TEAM_T && GetClientTeam(i) != CS_TEAM_CT) { @@ -171,11 +163,6 @@ public int Native_GetAveragePlayerActiveTimeServer(Handle plugin, int numParams) return GetAveragePlayerActiveTimeServer(); } -public int Native_GetAveragePlayerActiveTimeServerRTV(Handle plugin, int numParams) -{ - return GetAveragePlayerActiveTimeServerRTV(); -} - public int Native_GetPlayerWorthRTV_boost(Handle plugin, int numParams) { int client = GetNativeCell(1); @@ -190,62 +177,22 @@ public int Native_GetPlayerWorthRTV_boost(Handle plugin, int numParams) ThrowNativeError(SP_ERROR_NATIVE, "Client is not in-game."); return view_as(-1); } - return view_as(g_fPlayerRTVWorth[client]); -} -public int Native_GetPlayerWorthRTV(Handle plugin, int numParams) -{ - int client = GetNativeCell(1); - - if(client > MaxClients || client <= 0) - { - ThrowNativeError(SP_ERROR_NATIVE, "Client is not valid."); - return -1; - } - - if(!IsClientInGame(client)) - { - ThrowNativeError(SP_ERROR_NATIVE, "Client is not in-game."); - return -1; - } - return view_as(GetPlayerWorthRTV(client)); -} - -public int GetPlayerWorthRTV(int client) -{ - int avg = GetAveragePlayerActiveTimeServerRTV(); + int avg = GetAveragePlayerActiveTimeServer(); if (g_iPlayerTimeServer[client] <= avg || avg == 0 || is_bot_player[client]) { - g_fPlayerRTVWorth[client] = 1.0; - return avg; + return 1; } if ((float(g_iPlayerTimeServer[client]) / float(avg)) > g_iPlayerRTVCapacity) { - g_fPlayerRTVWorth[client] = float(g_iPlayerRTVCapacity); - return avg * g_iPlayerRTVCapacity; + return g_iPlayerRTVCapacity; //1.0-5.0 booster probably } - g_fPlayerRTVWorth[client] = float(g_iPlayerTimeServer[client]) / float(avg); - return avg * (g_iPlayerTimeServer[client] / avg); -} - -public int GetAveragePlayerActiveTimeServerRTV() -{ - //for rockthevote and mapvote average we include spectators and afks. just not fakes, nosteamers and autismbots, thats why a different function is made. - int total_hours = 0; - int total_players = 0; - for (int i = 0; i < MaxClients; i++) + int val = RoundToFloor((g_iPlayerTimeServer[client]) / float(avg)); + if (val < 1) { - if (IsValidClient(i) && !IsFakeClient(i) && !IsClientSourceTV(i) && !is_bot_player[i] && PM_IsPlayerSteam(i)) - { - total_hours += g_iPlayerTimeServer[i]; - total_players++; - } + val = 1; } - if (total_hours == 0) - { - return 0; - } - return total_hours / total_players; + return val; } public void OnPluginEnd() @@ -280,7 +227,6 @@ public void OnClientPostAdminCheck(int client) { GetClientAuthId(client, AuthId_Steam2, g_csSID[client], sizeof(g_csSID[])); is_bot_player[client] = false; - g_fPlayerRTVWorth[client] = 0.0; g_iPlayerTimeServer[client] = 0; if(!IsValidClient(client) || IsFakeClient(client)) return; @@ -325,10 +271,6 @@ public void select_client_time_server(int client) { Format(sServer, sizeof(sServer), "mg_time"); } - else if (i_port == 27023) - { - Format(sServer, sizeof(sServer), "jb_time"); - } else { return; @@ -373,7 +315,6 @@ public void OnClientDisconnect(int client) { Format(g_csSID[client], sizeof(g_csSID[]), ""); is_bot_player[client] = false; - g_fPlayerRTVWorth[client] = 0.0; g_iPlayerTimeServer[client] = 0; } @@ -430,10 +371,6 @@ public void OnMapStart() { Format(sServer, sizeof(sServer), "mg_time"); } - else if (i_port == 27023) - { - Format(sServer, sizeof(sServer), "jb_time"); - } else { return;