removed native, changed from float to int, added minimal default value
This commit is contained in:
parent
4a69445495
commit
00a333db07
@ -8,17 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
native int GetAveragePlayerTimeOnServer();
|
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
|
* @returns the players rtv amount boost
|
||||||
*/
|
*/
|
||||||
native float GetPlayerWorthRTV_boost_(int client);
|
native int GetPlayerWorthRTV_boost_(int client);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#pragma semicolon 1
|
#pragma semicolon 1
|
||||||
#define PLUGIN_AUTHOR "jenz"
|
#define PLUGIN_AUTHOR "jenz"
|
||||||
#define PLUGIN_VERSION "1.1"
|
#define PLUGIN_VERSION "1.2"
|
||||||
#include <sourcemod>
|
#include <sourcemod>
|
||||||
#include <cstrike>
|
#include <cstrike>
|
||||||
#include <PlayerManager>
|
#include <PlayerManager>
|
||||||
@ -17,8 +17,6 @@ int g_iPlayerAFKTime;
|
|||||||
int g_iPlayerCount_excludeSpec;
|
int g_iPlayerCount_excludeSpec;
|
||||||
int g_iPlayerRTVCapacity;
|
int g_iPlayerRTVCapacity;
|
||||||
|
|
||||||
float g_fPlayerRTVWorth[MAXPLAYERS + 1];
|
|
||||||
|
|
||||||
public Plugin myinfo =
|
public Plugin myinfo =
|
||||||
{
|
{
|
||||||
name = "UNLOZE_player_time",
|
name = "UNLOZE_player_time",
|
||||||
@ -51,10 +49,6 @@ public Action time_query_activity(Handle timer, any data)
|
|||||||
{
|
{
|
||||||
Format(sServer, sizeof(sServer), "mg_time");
|
Format(sServer, sizeof(sServer), "mg_time");
|
||||||
}
|
}
|
||||||
else if (i_port == 27023)
|
|
||||||
{
|
|
||||||
Format(sServer, sizeof(sServer), "jb_time");
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return Plugin_Continue;
|
return Plugin_Continue;
|
||||||
@ -87,7 +81,7 @@ public void OnPluginStart()
|
|||||||
Database.Connect(SQL_OnDatabaseConnect, "unloze_playtimestats");
|
Database.Connect(SQL_OnDatabaseConnect, "unloze_playtimestats");
|
||||||
}
|
}
|
||||||
RegConsoleCmd("sm_playtime", Command_Time, "retreives total connection time on all connected servers");
|
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);
|
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)
|
public APLRes AskPluginLoad2(Handle myself, bool late, char [] error, int err_max)
|
||||||
{
|
{
|
||||||
CreateNative("GetAveragePlayerTimeOnServer", Native_GetAveragePlayerActiveTimeServer);
|
CreateNative("GetAveragePlayerTimeOnServer", Native_GetAveragePlayerActiveTimeServer);
|
||||||
CreateNative("GetAveragePlayerTimeOnServerRTV", Native_GetAveragePlayerActiveTimeServerRTV);
|
|
||||||
CreateNative("GetPlayerWorthRTV_", Native_GetPlayerWorthRTV);
|
|
||||||
CreateNative("GetPlayerWorthRTV_boost_", Native_GetPlayerWorthRTV_boost);
|
CreateNative("GetPlayerWorthRTV_boost_", Native_GetPlayerWorthRTV_boost);
|
||||||
return APLRes_Success;
|
return APLRes_Success;
|
||||||
}
|
}
|
||||||
@ -140,8 +132,8 @@ public int GetAveragePlayerActiveTimeServer()
|
|||||||
for (int i = 0; i < MaxClients; i++)
|
for (int i = 0; i < MaxClients; i++)
|
||||||
{
|
{
|
||||||
//checking player count before deciding if including or excluding spectators from actual average
|
//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)
|
//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] && PM_IsPlayerSteam(i)
|
if (IsValidClient(i) && !IsFakeClient(i) && !IsClientSourceTV(i) && !is_bot_player[i]
|
||||||
&& (GetClientTeam(i) == CS_TEAM_T || GetClientTeam(i) == CS_TEAM_CT))
|
&& (GetClientTeam(i) == CS_TEAM_T || GetClientTeam(i) == CS_TEAM_CT))
|
||||||
{
|
{
|
||||||
active_player_count++;
|
active_player_count++;
|
||||||
@ -149,7 +141,7 @@ public int GetAveragePlayerActiveTimeServer()
|
|||||||
}
|
}
|
||||||
for (int i = 0; i < MaxClients; i++)
|
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)
|
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();
|
return GetAveragePlayerActiveTimeServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Native_GetAveragePlayerActiveTimeServerRTV(Handle plugin, int numParams)
|
|
||||||
{
|
|
||||||
return GetAveragePlayerActiveTimeServerRTV();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int Native_GetPlayerWorthRTV_boost(Handle plugin, int numParams)
|
public int Native_GetPlayerWorthRTV_boost(Handle plugin, int numParams)
|
||||||
{
|
{
|
||||||
int client = GetNativeCell(1);
|
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.");
|
ThrowNativeError(SP_ERROR_NATIVE, "Client is not in-game.");
|
||||||
return view_as<int>(-1);
|
return view_as<int>(-1);
|
||||||
}
|
}
|
||||||
return view_as<int>(g_fPlayerRTVWorth[client]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int Native_GetPlayerWorthRTV(Handle plugin, int numParams)
|
int avg = GetAveragePlayerActiveTimeServer();
|
||||||
{
|
|
||||||
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<int>(GetPlayerWorthRTV(client));
|
|
||||||
}
|
|
||||||
|
|
||||||
public int GetPlayerWorthRTV(int client)
|
|
||||||
{
|
|
||||||
int avg = GetAveragePlayerActiveTimeServerRTV();
|
|
||||||
if (g_iPlayerTimeServer[client] <= avg || avg == 0 || is_bot_player[client])
|
if (g_iPlayerTimeServer[client] <= avg || avg == 0 || is_bot_player[client])
|
||||||
{
|
{
|
||||||
g_fPlayerRTVWorth[client] = 1.0;
|
return 1;
|
||||||
return avg;
|
|
||||||
}
|
}
|
||||||
if ((float(g_iPlayerTimeServer[client]) / float(avg)) > g_iPlayerRTVCapacity)
|
if ((float(g_iPlayerTimeServer[client]) / float(avg)) > g_iPlayerRTVCapacity)
|
||||||
{
|
{
|
||||||
g_fPlayerRTVWorth[client] = float(g_iPlayerRTVCapacity);
|
return g_iPlayerRTVCapacity; //1.0-5.0 booster probably
|
||||||
return avg * g_iPlayerRTVCapacity;
|
|
||||||
}
|
}
|
||||||
g_fPlayerRTVWorth[client] = float(g_iPlayerTimeServer[client]) / float(avg);
|
int val = RoundToFloor((g_iPlayerTimeServer[client]) / float(avg));
|
||||||
return avg * (g_iPlayerTimeServer[client] / avg);
|
if (val < 1)
|
||||||
}
|
|
||||||
|
|
||||||
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++)
|
|
||||||
{
|
{
|
||||||
if (IsValidClient(i) && !IsFakeClient(i) && !IsClientSourceTV(i) && !is_bot_player[i] && PM_IsPlayerSteam(i))
|
val = 1;
|
||||||
{
|
|
||||||
total_hours += g_iPlayerTimeServer[i];
|
|
||||||
total_players++;
|
|
||||||
}
|
}
|
||||||
}
|
return val;
|
||||||
if (total_hours == 0)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return total_hours / total_players;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnPluginEnd()
|
public void OnPluginEnd()
|
||||||
@ -280,7 +227,6 @@ public void OnClientPostAdminCheck(int client)
|
|||||||
{
|
{
|
||||||
GetClientAuthId(client, AuthId_Steam2, g_csSID[client], sizeof(g_csSID[]));
|
GetClientAuthId(client, AuthId_Steam2, g_csSID[client], sizeof(g_csSID[]));
|
||||||
is_bot_player[client] = false;
|
is_bot_player[client] = false;
|
||||||
g_fPlayerRTVWorth[client] = 0.0;
|
|
||||||
g_iPlayerTimeServer[client] = 0;
|
g_iPlayerTimeServer[client] = 0;
|
||||||
if(!IsValidClient(client) || IsFakeClient(client))
|
if(!IsValidClient(client) || IsFakeClient(client))
|
||||||
return;
|
return;
|
||||||
@ -325,10 +271,6 @@ public void select_client_time_server(int client)
|
|||||||
{
|
{
|
||||||
Format(sServer, sizeof(sServer), "mg_time");
|
Format(sServer, sizeof(sServer), "mg_time");
|
||||||
}
|
}
|
||||||
else if (i_port == 27023)
|
|
||||||
{
|
|
||||||
Format(sServer, sizeof(sServer), "jb_time");
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@ -373,7 +315,6 @@ public void OnClientDisconnect(int client)
|
|||||||
{
|
{
|
||||||
Format(g_csSID[client], sizeof(g_csSID[]), "");
|
Format(g_csSID[client], sizeof(g_csSID[]), "");
|
||||||
is_bot_player[client] = false;
|
is_bot_player[client] = false;
|
||||||
g_fPlayerRTVWorth[client] = 0.0;
|
|
||||||
g_iPlayerTimeServer[client] = 0;
|
g_iPlayerTimeServer[client] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -430,10 +371,6 @@ public void OnMapStart()
|
|||||||
{
|
{
|
||||||
Format(sServer, sizeof(sServer), "mg_time");
|
Format(sServer, sizeof(sServer), "mg_time");
|
||||||
}
|
}
|
||||||
else if (i_port == 27023)
|
|
||||||
{
|
|
||||||
Format(sServer, sizeof(sServer), "jb_time");
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user