Skip to content

Commit

Permalink
Merge pull request #109 from Paimon-Kawaii/sipooltest
Browse files Browse the repository at this point in the history
修正SIPool会把克放入池中的Bug
  • Loading branch information
fantasylidong authored Mar 27, 2024
2 parents d81f4e9 + 6c7edc4 commit 916340b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 33 deletions.
Binary file modified addons/sourcemod/plugins/optional/AnneHappy/infected_control.smx
Binary file not shown.
Binary file modified addons/sourcemod/plugins/optional/AnneHappy/si_pool.smx
Binary file not shown.
6 changes: 3 additions & 3 deletions addons/sourcemod/scripting/AnneHappy/infected_control.sp
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ bool HasReachedLimit(int zombieclass)
int count = 0;
static char convar[16];
for (int infected = 1; infected <= MaxClients; infected++)
if (IsClientConnected(infected) && IsClientInGame(infected) && !IsGhost(infected)
if (IsClientConnected(infected) && IsClientInGame(infected) && !IsPlayerAlive(infected)
&& GetEntProp(infected, Prop_Send, "m_zombieClass") == zombieclass)
count += 1;

Expand Down Expand Up @@ -973,7 +973,7 @@ void ResetStatus()
g_iTotalSINum = 0;
for (int client = 1; client <= MaxClients; client++)
{
if (IsInfectedBot(client) && !IsGhost(client))
if (IsInfectedBot(client) && !IsPlayerAlive(client))
{
g_iTeleCount[client] = 0;
int type = GetEntProp(client, Prop_Send, "m_zombieClass");
Expand Down Expand Up @@ -1331,7 +1331,7 @@ stock int GetCurrentSINum()
{
int sum = 0;
for (int i = 0; i < MaxClients; i++)
if (IsInfectedBot(i) && !IsGhost(i))
if (IsInfectedBot(i) && !IsPlayerAlive(i))
sum++;

return sum;
Expand Down
71 changes: 41 additions & 30 deletions addons/sourcemod/scripting/AnneHappy/si_pool.sp
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@
* @Author: 我是派蒙啊
* @Last Modified by: 我是派蒙啊
* @Create Date: 2024-02-17 11:15:10
* @Last Modified time: 2024-03-25 21:07:19
* @Last Modified time: 2024-03-26 13:39:14
* @Github: https://github.com/Paimon-Kawaii
*/

#pragma semicolon 1
#pragma newdecls required

#define DEBUG 0

#if DEBUG
#define LOGFILE "addons/sourcemod/logs/si_pool_log.txt"
#endif

#define VERSION "2024.03.25#93"
#define VERSION "2024.03.26#121"

#define LIBRARY_NAME "si_pool"
#define GAMEDATA_FILE "si_pool"
Expand Down Expand Up @@ -147,30 +148,43 @@ any Native_SIPool_Instance_get(Handle plugin, int numParams)

any Native_SIPool_RequestSIBot(Handle plugin, int numParams)
{
static bool log = false;
int zclass_idx = GetNativeCell(2) - 1;
int size = g_iPoolSize[zclass_idx];
if (size < 1)
{
#if DEBUG
static bool log = false;
if (!log)
{
LogMessage("[SIPool] Pool empty or not sized !");
LogMessage("[SIPool] SIPool will auto set size to 1 !");
LogMessage("[SIPool] This log only showed once.");
LogToFile(LOGFILE, "[SIPool] Pool empty or not sized !");
LogToFile(LOGFILE, "[SIPool] SIPool will auto set size to 1 !");
LogToFile(LOGFILE, "[SIPool] This log only showed once.");
log = true;
}
#endif
OnPoolSizeChanged(0, 1, zclass_idx);
g_iPoolSize[zclass_idx] = 1;
}

int index = 1;
size = g_iPoolSize[zclass_idx];
int bot = g_iPoolArray[zclass_idx][size - index];
while (!(IsValidClient(bot) && IsFakeClient(bot) && IsGhost(bot)) && ++index <= size)
#if DEBUG
LogToFile(LOGFILE, "[SIPool] Start request (%s)pool, current size: %d", g_sZombieClass[zclass_idx], size);
LogToFile(LOGFILE, "[SIPool] %d is ghost:(%d), isalive:(%d)?", bot, IsGhost(bot), IsValidClient(bot) && IsPlayerAlive(bot));
#endif
while (!(IsValidClient(bot) && IsFakeClient(bot) && !IsPlayerAlive(bot)) && ++index <= size)
{
bot = g_iPoolArray[zclass_idx][size - index];
if (index > size && !(IsValidClient(bot) && IsFakeClient(bot) && IsGhost(bot)))
#if DEBUG
LogToFile(LOGFILE, "[SIPool] %d is ghost:(%d), isalive:(%d)?", bot, IsGhost(bot), IsValidClient(bot) && IsPlayerAlive(bot));
#endif
}
if (index > size && !(IsValidClient(bot) && IsFakeClient(bot) && !IsPlayerAlive(bot)))
{
LogMessage("[SIPool] No SI available !");
#if DEBUG
LogToFile(LOGFILE, "[SIPool] No SI available !");
#endif
OnPoolSizeChanged(size, 0, zclass_idx);
g_iPoolSize[zclass_idx] = 0;

Expand Down Expand Up @@ -200,7 +214,8 @@ any Native_SIPool_RequestSIBot(Handle plugin, int numParams)
g_iPoolSize[zclass_idx] -= index;

#if DEBUG
LogToFile(LOGFILE, "[SIPool] SI request: %d, type: %d", bot, zclass_idx + 1);
LogToFile(LOGFILE, "[SIPool] SI request: %d, type: %s", bot, g_sZombieClass[zclass_idx]);
LogToFile(LOGFILE, "[SIPool] Finish request (%s)pool, current size: %d", g_sZombieClass[zclass_idx], g_iPoolSize[zclass_idx]);
#endif

return bot;
Expand All @@ -209,29 +224,24 @@ any Native_SIPool_RequestSIBot(Handle plugin, int numParams)
any Native_SIPool_ReturnSIBot(Handle plugin, int numParams)
{
int bot = GetNativeCell(2);
if (!(IsInfected(bot) && IsFakeClient(bot)))
if (!(IsInfected(bot) && IsFakeClient(bot) && IsPlayerAlive(bot)))
{
LogMessage("[SIPool] SI is not available!");
#if DEBUG
LogToFile(LOGFILE, "[SIPool] SI is not available!");
#endif
return false;
}

// g_iPoolArray[GetZombieClass(bot) - 1][g_iPoolSize[GetZombieClass(bot) - 1]++] = bot;
// ResetDeadZombie(bot);
ForcePlayerSuicide(bot);

// Return bot dont need to resize...
// OnPoolSizeChanged(g_iPoolSize, g_iPoolSize + 1);
// g_iPoolSize++;

return true;
}

void OnPoolSizeChanged(int iOldPoolSize, int iNewPoolSize, int zclass_idx)
{
if (GetClientCount(false) >= MaxClients) return;
if (GetClientCount(false) >= MaxClients && iOldPoolSize < iNewPoolSize) return;

#if DEBUG
LogToFile(LOGFILE, "[SIPool] SI size change: %d -> %d of %d pool", iOldPoolSize, iNewPoolSize, zclass_idx);
LogToFile(LOGFILE, "[SIPool] (%s)pool sized(%d -> %d)", g_sZombieClass[zclass_idx], iOldPoolSize, iNewPoolSize);
#endif

bool add;
Expand Down Expand Up @@ -261,15 +271,15 @@ void OnPoolSizeChanged(int iOldPoolSize, int iNewPoolSize, int zclass_idx)
bot = CreateSIBot(zclass_idx);
if (bot == -1)
{
LogMessage("[SIPool] SI create failed for the unknow reason ?!");
LogError("[SIPool] SI create failed for the unknow reason ?!");
break;
}
}
g_iPoolArray[zclass_idx][i] = bot;
InitializeSpecial(bot, _, _, true);
ResetDeadZombie(bot);
#if DEBUG
LogToFile(LOGFILE, "[SIPool] SI create: %d", bot);
LogToFile(LOGFILE, "[SIPool] SI create: %d, (%s)pool sized(%d -> %d)", bot, g_sZombieClass[zclass_idx], iOldPoolSize, iNewPoolSize);
#endif
}
}
Expand All @@ -283,16 +293,17 @@ void HookEvents()
void Event_PlayerDeath(Event event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(event.GetInt("userid"));
if (!(IsInfected(client) && IsFakeClient(client))) return;

#if DEBUG
LogToFile(LOGFILE, "[SIPool] SI dead: %d", client);
#endif
if (!(IsInfected(client) && IsFakeClient(client)) || IsTank(client)) return;

// Return bot;
ResetDeadZombie(client);
g_iLastDeadTypeIdx = GetZombieClass(client) - 1;
g_iPoolArray[g_iLastDeadTypeIdx][g_iPoolSize[g_iLastDeadTypeIdx]++] = client;
ResetDeadZombie(client);

#if DEBUG
LogToFile(LOGFILE, "[SIPool] SI dead: %d, (%s)pool sized(%d -> %d)", client, g_sZombieClass[g_iLastDeadTypeIdx], g_iPoolSize[g_iLastDeadTypeIdx] - 1, g_iPoolSize[g_iLastDeadTypeIdx]);
LogToFile(LOGFILE, "[SIPool] %d is ghost:(%d), isalive:(%d)?", client, IsGhost(client), IsPlayerAlive(client));
#endif
}

void Event_RoundStart(Event event, const char[] name, bool dontBroadcast)
Expand Down Expand Up @@ -456,7 +467,7 @@ void LoadStringFromAddress(Address pAddr, char[] buffer, int maxlength)
// ability = SDKCall(g_hSDK_CBaseAbility_CreateForPlayer, client);

// if (ability != -1) SetEntPropEnt(client, Prop_Send, "m_customAbility", ability);
// else LogMessage("[SIPool] Failed to create ability for %N after %d times tried.", client, ABILITY_TRYTIMES);
// else LogToFile(LOGFILE, "[SIPool] Failed to create ability for %N after %d times tried.", client, ABILITY_TRYTIMES);
// }

void SetStateTransition(int client, int state)
Expand Down

0 comments on commit 916340b

Please sign in to comment.