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

@ -30,7 +30,7 @@
*
* @param client The client index.
*
* @return True if zombie, false if not.
* @return True if zombie, false if not.
* @error Invalid client index, not connected or not alive.
*/
native bool ZR_IsClientZombie(int client);
@ -40,7 +40,7 @@ native bool ZR_IsClientZombie(int client);
*
* @param client The client index.
*
* @return True if human, false if not.
* @return True if human, false if not.
* @error Invalid client index, not connected or not alive.
*/
native bool ZR_IsClientHuman(int client);
@ -56,9 +56,10 @@ native bool ZR_IsClientHuman(int client);
* @param respawnOverride (Optional) Set to true to override respawn cvar.
* @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.
*/
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.
@ -70,9 +71,10 @@ native int ZR_InfectClient(int client, int attacker = -1, bool motherInfect = fa
* @param respawn Teleport client back to spawn.
* @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.
*/
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.

View File

@ -105,7 +105,7 @@ public APIInfectClient(Handle:plugin, numParams)
// Validate the client index.
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.
APIValidateClientIndex(client, Condition_True);
InfectZombieToHuman(client, respawn, protect);
return InfectZombieToHuman(client, respawn, protect);
}
/**

View File

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