GENERAL: Infection update.

This commit is contained in:
zaCade 2017-10-06 13:49:11 +02:00
parent bd10d160c4
commit 1b81c27314
3 changed files with 80 additions and 54 deletions

View File

@ -56,9 +56,10 @@ native bool ZR_IsClientHuman(int client);
* @param respawnOverride (Optional) Set to true to override respawn cvar. * @param respawnOverride (Optional) Set to true to override respawn cvar.
* @param respawn (Optional) Value to override with. * @param respawn (Optional) Value to override with.
* *
* @return True if the client was infected, false if not.
* @error Invalid client index, not connected or not alive. * @error Invalid client index, not connected or not alive.
*/ */
native int ZR_InfectClient(int client, int attacker = -1, bool motherInfect = false, bool respawnOverride = false, bool respawn = false); native bool ZR_InfectClient(int client, int attacker = -1, bool motherInfect = false, bool respawnOverride = false, bool respawn = false);
/** /**
* Turns a zombie back into a human. * Turns a zombie back into a human.
@ -70,9 +71,10 @@ native int ZR_InfectClient(int client, int attacker = -1, bool motherInfect = fa
* @param respawn Teleport client back to spawn. * @param respawn Teleport client back to spawn.
* @param protect Start spawn protection on client. * @param protect Start spawn protection on client.
* *
* @return True if the client was uninfected, false if not.
* @error Invalid client index, not connected or not alive. * @error Invalid client index, not connected or not alive.
*/ */
native int ZR_HumanClient(int client, bool respawn = false, bool protect = false); native bool ZR_HumanClient(int client, bool respawn = false, bool protect = false);
/** /**
* Called when a player is about to become a zombie. * Called when a player is about to become a zombie.

View File

@ -105,7 +105,7 @@ public APIInfectClient(Handle:plugin, numParams)
// Validate the client index. // Validate the client index.
APIValidateClientIndex(client, Condition_True); APIValidateClientIndex(client, Condition_True);
InfectHumanToZombie(client, attacker, motherInfect, respawnOverride, respawn); return InfectHumanToZombie(client, attacker, motherInfect, respawnOverride, respawn);
} }
/** /**
@ -123,7 +123,7 @@ public APIHumanClient(Handle:plugin, numParams)
// Validate the client index. // Validate the client index.
APIValidateClientIndex(client, Condition_True); APIValidateClientIndex(client, Condition_True);
InfectZombieToHuman(client, respawn, protect); return InfectZombieToHuman(client, respawn, protect);
} }
/** /**

View File

@ -533,77 +533,96 @@ public Action:InfectMotherZombie(Handle:timer)
} }
} }
new candidates = 0; new candidatesMain = 0;
new Handle:aCandidates = CreateArray(); new candidatesAlt = 0;
new Handle:aCandidatesMain = CreateArray();
new Handle:aCandidatesAlt = CreateArray();
for (new n = 0; n < eligibleclients; n++) for (new n = 0; n < eligibleclients; n++)
{ {
// Get the client stored in the array index. // Get the client stored in the array index.
new client = GetArrayCell(arrayEligibleClients, n); new client = GetArrayCell(arrayEligibleClients, n);
// If client hasn't been chosen this cycle, put into aCandidates array. // If client hasn't been chosen this cycle, put into aCandidatesMain array.
if (!SteamidCacheClientExists(g_hInfectMotherCycle, client)) if (!SteamidCacheClientExists(g_hInfectMotherCycle, client))
{ {
PushArrayCell(aCandidates, client); PushArrayCell(aCandidatesMain, client);
candidates++; candidatesMain++;
}
} }
// Not enough candidates found. // If client hasn't been chosen last round, put into aCandidatesAlt array.
if (candidates < mothercount) else if (!g_bInfectMotherLast[client])
{ {
for (new n = 0; n < eligibleclients; n++) PushArrayCell(aCandidatesAlt, client);
{ candidatesAlt++;
// Get the client stored in the array index.
new client = GetArrayCell(arrayEligibleClients, n);
// If client hasn't been chosen last round, put into aCandidates array,
// but only until we have enough candidates.
if (!g_bInfectMotherLast[client])
{
PushArrayCell(aCandidates, client);
candidates++;
// Enough candidates found.
if(candidates >= mothercount)
break;
} }
} }
// Restart the cycle.
// Clear mother zombie round-robin cycle storage.
SteamidCacheReset(g_hInfectMotherCycle);
// Announce start of new cycle
TranslationPrintToChatAll(true, false, "Mother zombie infect cycle reset");
}
// Remove mother zombie last flag from all players. // Remove mother zombie last flag from all players.
for (int client = 0; client <= MAXPLAYERS; client++) for (int client = 0; client <= MAXPLAYERS; client++)
{ {
g_bInfectMotherLast[client] = false; g_bInfectMotherLast[client] = false;
} }
// Infect players. new bool:resetcycle;
for (new n = 0; n < mothercount; n++)
{
// Stop if there are no more candidates.
if (candidates <= 0)
{
break;
}
// Infect players.
new infected = 0;
while (infected < mothercount)
{
// Infect one of the main candidates.
if (candidatesMain)
{
// Get a random array index. // Get a random array index.
new i = Math_GetRandomInt(0, candidates - 1); new i = Math_GetRandomInt(0, candidatesMain - 1);
// Get the client stored in the random array index. // Get the client stored in the random array index.
new client = GetArrayCell(aCandidates, i); new client = GetArrayCell(aCandidatesMain, i);
// Infect player. // Infect player.
InfectHumanToZombie(client, _, true); if (InfectHumanToZombie(client, _, true))
infected++;
// Remove player from eligible client list. // Remove player from eligible client list.
RemoveFromArray(aCandidates, i); RemoveFromArray(aCandidatesMain, i);
candidates--; candidatesMain--;
}
// Infect one of the alternate candidates.
else if (candidatesAlt)
{
// Get a random array index.
new i = Math_GetRandomInt(0, candidatesAlt - 1);
// Get the client stored in the random array index.
new client = GetArrayCell(aCandidatesAlt, i);
// Infect player.
if (InfectHumanToZombie(client, _, true))
infected++;
// Remove player from eligible client list.
RemoveFromArray(aCandidatesAlt, i);
candidatesAlt--;
// Enable the cycle reset.
resetcycle = true;
}
// We have no candidates at all, abort!
else
{
// Enable the cycle reset.
resetcycle = true;
break;
}
}
if (resetcycle)
{
// Restart the cycle.
// Clear mother zombie round-robin cycle storage.
SteamidCacheReset(g_hInfectMotherCycle);
// Announce start of new cycle
TranslationPrintToChatAll(true, false, "Mother zombie infect cycle reset");
} }
// Mother zombies have been infected. // Mother zombies have been infected.
@ -611,7 +630,8 @@ public Action:InfectMotherZombie(Handle:timer)
// Destroy client list. // Destroy client list.
CloseHandle(arrayEligibleClients); CloseHandle(arrayEligibleClients);
CloseHandle(aCandidates); CloseHandle(aCandidatesMain);
CloseHandle(aCandidatesAlt);
} }
/** /**
@ -712,7 +732,7 @@ InfectHumanToZombie(client, attacker = -1, bool:motherinfect = false, bool:respa
// Check if infection should be blocked. // Check if infection should be blocked.
if (result == Plugin_Handled) if (result == Plugin_Handled)
{ {
return; return false;
} }
// Mark player as zombie. // Mark player as zombie.
@ -812,6 +832,8 @@ InfectHumanToZombie(client, attacker = -1, bool:motherinfect = false, bool:respa
APIOnClientInfected(client, attacker, motherinfect, respawnoverride, respawn); APIOnClientInfected(client, attacker, motherinfect, respawnoverride, respawn);
ImmunityOnClientInfected(client); ImmunityOnClientInfected(client);
ZSpawnOnClientInfected(client); ZSpawnOnClientInfected(client);
return true;
} }
/** /**
@ -830,7 +852,7 @@ InfectZombieToHuman(client, bool:respawn = false, bool:protect = false)
// Check if action should be blocked. // Check if action should be blocked.
if (result == Plugin_Handled) if (result == Plugin_Handled)
{ {
return; return false;
} }
// Mark player as human. // Mark player as human.
@ -878,6 +900,8 @@ InfectZombieToHuman(client, bool:respawn = false, bool:protect = false)
APIOnClientHumanPost(client, respawn, protect); APIOnClientHumanPost(client, respawn, protect);
ImmunityOnClientHuman(client); ImmunityOnClientHuman(client);
ZSpawnOnClientHuman(client); ZSpawnOnClientHuman(client);
return true;
} }
/** /**