FakePopulation: small improvements

thx neon
This commit is contained in:
Dogan 2019-08-29 23:10:37 +02:00
parent fcb6913e6a
commit 492a36ec5a

View File

@ -6,6 +6,8 @@
#define NUMBEROFNAMES 48 #define NUMBEROFNAMES 48
char g_cName[NUMBEROFNAMES][] = {"Dwelitram", "Gwyri", "Caredus", "Arerawia", "Vilali", "Astiwiel", "Vardonydd", "Ybaossa", "Umyk", "Nico50Pax", "Onand", "Thelian", "Nydaleth", "Chomarin", "Traedien", "Miev", "Kaaede", "Koamond", "TheRottenBenson", "BigLegend2017", "TRIGGEREDHarambexXx", "InPepe2016", "xXxMaster2012", "InBoixXx", "TheKopsing", "Cornelius", "Gustavo", "Bryant", "Winfred", "Nicolas", "Mitchel", "Dana", "Carrol", "Darell", "Ruben", "Jeromy", "Wade", "Scotty", "Salvatore", "Kory", "Don", "Morgan", "Kurtis", "Federico", "Darin", "css-ru", "aimbot", "lastkraftwagenfahrzeug"}; char g_cName[NUMBEROFNAMES][] = {"Dwelitram", "Gwyri", "Caredus", "Arerawia", "Vilali", "Astiwiel", "Vardonydd", "Ybaossa", "Umyk", "Nico50Pax", "Onand", "Thelian", "Nydaleth", "Chomarin", "Traedien", "Miev", "Kaaede", "Koamond", "TheRottenBenson", "BigLegend2017", "TRIGGEREDHarambexXx", "InPepe2016", "xXxMaster2012", "InBoixXx", "TheKopsing", "Cornelius", "Gustavo", "Bryant", "Winfred", "Nicolas", "Mitchel", "Dana", "Carrol", "Darell", "Ruben", "Jeromy", "Wade", "Scotty", "Salvatore", "Kory", "Don", "Morgan", "Kurtis", "Federico", "Darin", "css-ru", "aimbot", "lastkraftwagenfahrzeug"};
bool g_bFakePopulation[MAXPLAYERS+1];
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
// Purpose: // Purpose:
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
@ -24,7 +26,7 @@ public Plugin myinfo =
public void OnPluginStart() public void OnPluginStart()
{ {
RegAdminCmd("sm_debugfakes", Command_DebugFakes, ADMFLAG_RCON, ""); RegAdminCmd("sm_debugfakes", Command_DebugFakes, ADMFLAG_RCON, "");
OnClientConnected(0); CheckPopulation();
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
@ -34,8 +36,11 @@ public void OnPluginEnd()
{ {
for(int i = 1; i <= MaxClients; i++) for(int i = 1; i <= MaxClients; i++)
{ {
if(IsClientConnected(i) && IsFakeClient(i) && !IsClientSourceTV(i)) if(g_bFakePopulation[i])
KickClient(i); {
g_bFakePopulation[i] = false;
KickClientEx(i);
}
} }
} }
@ -47,7 +52,7 @@ public Action Command_DebugFakes(int client, int argc)
int iFakes = 0; int iFakes = 0;
for(int i = 1; i <= MaxClients; i++) for(int i = 1; i <= MaxClients; i++)
{ {
if(IsClientConnected(i) && IsFakeClient(i) && !IsClientSourceTV(i)) if (g_bFakePopulation[i])
iFakes++; iFakes++;
} }
ReplyToCommand(client, "[SM] There are currently %d Fake Players.", iFakes); ReplyToCommand(client, "[SM] There are currently %d Fake Players.", iFakes);
@ -59,7 +64,8 @@ public Action Command_DebugFakes(int client, int argc)
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
public void OnClientConnected(int client) public void OnClientConnected(int client)
{ {
CheckPopulation(); if ((client > 0) && (!IsFakeClient(client)))
CheckPopulation();
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
@ -67,7 +73,14 @@ public void OnClientConnected(int client)
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
public void OnClientDisconnect(int client) public void OnClientDisconnect(int client)
{ {
CheckPopulation(); if (client > 0)
{
if(g_bFakePopulation[client])
g_bFakePopulation[client] = false;
if (!IsFakeClient(client))
CheckPopulation();
}
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
@ -76,21 +89,20 @@ public void OnClientDisconnect(int client)
public void CheckPopulation() public void CheckPopulation()
{ {
int iPlayers = 0; int iPlayers = 0;
int iFakesNeeded = 0;
int iFakes = 0;
for(int i = 1; i <= MaxClients; i++) for(int i = 1; i <= MaxClients; i++)
{ {
if(IsClientConnected(i) && !IsFakeClient(i)) if(IsClientConnected(i) && !IsFakeClient(i))
iPlayers++; iPlayers++;
} }
int iFakes = 0;
for(int i = 1; i <= MaxClients; i++) for(int i = 1; i <= MaxClients; i++)
{ {
if(IsClientConnected(i) && IsFakeClient(i) && !IsClientSourceTV(i)) if (g_bFakePopulation[i])
iFakes++; iFakes++;
} }
int iFakesNeeded = 0;
if (iPlayers >= 61) if (iPlayers >= 61)
iFakesNeeded = 0; iFakesNeeded = 0;
else if(iPlayers >= 60) else if(iPlayers >= 60)
@ -114,7 +126,8 @@ public void CheckPopulation()
while (iFakes < iFakesNeeded) while (iFakes < iFakesNeeded)
{ {
int RandomName = GetRandomInt(0, NUMBEROFNAMES - 1); int RandomName = GetRandomInt(0, NUMBEROFNAMES - 1);
CreateFakeClient(g_cName[RandomName]); int iIndex = CreateFakeClient(g_cName[RandomName]);
g_bFakePopulation[iIndex] = true;
iFakes++; iFakes++;
} }
@ -122,9 +135,10 @@ public void CheckPopulation()
{ {
for(int i = 1; i <= MaxClients; i++) for(int i = 1; i <= MaxClients; i++)
{ {
if(IsClientConnected(i) && IsFakeClient(i) && !IsClientSourceTV(i)) if(g_bFakePopulation[i])
{ {
KickClient(i); g_bFakePopulation[i] = false;
KickClientEx(i);
iFakes--; iFakes--;
break; break;
} }