Added infection countdown. Backported from zr-dev:52955b169945 (655).

This commit is contained in:
Richard Helgeby
2011-12-26 17:45:08 +01:00
parent e90b517fc1
commit 776f149247
9 changed files with 162 additions and 18 deletions

View File

@ -46,9 +46,13 @@
*/
/**
* Global variable to store infect timer handle.
* @section Global variables to store infect timer handles.
*/
new Handle:tInfect = INVALID_HANDLE;
new Handle:tInfectCountdown = INVALID_HANDLE;
/**
* @endsection
*/
/**
* Array for flagging client as zombie.
@ -74,8 +78,9 @@ new bool:bInfectImmune[MAXPLAYERS + 1][2];
*/
InfectOnMapStart()
{
// Reset timer handle.
tInfect = INVALID_HANDLE;
// Stop timers if running.
ZREndTimer(tInfect);
ZREndTimer(tInfectCountdown);
}
/**
@ -336,15 +341,9 @@ InfectOnClientHurt(client, attacker, const String:weapon[])
*/
InfectOnRoundStart()
{
// If infect timer is running, then kill it.
if (tInfect != INVALID_HANDLE)
{
// Kill timer.
KillTimer(tInfect);
// Reset timer handle.
tInfect = INVALID_HANDLE;
}
// Stop infect timers if running.
ZREndTimer(tInfect);
ZREndTimer(tInfectCountdown);
// Tell plugin there are no zombies.
g_bZombieSpawned = false;
@ -355,12 +354,9 @@ InfectOnRoundStart()
*/
InfectOnRoundFreezeEnd()
{
// If infect timer is running, then kill it.
if (tInfect != INVALID_HANDLE)
{
// Kill timer.
KillTimer(tInfect);
}
// Stop infect timers if running.
ZREndTimer(tInfect);
ZREndTimer(tInfectCountdown);
// If the zombie has spawned already (had to be through admin) then stop.
if (g_bZombieSpawned)
@ -375,7 +371,24 @@ InfectOnRoundFreezeEnd()
// Pick random time between min and max.
new Float:randomtime = GetRandomFloat(infectspawntimemin, infectspawntimemax);
// Round to the nearest whole number (and convert back to a float) so the countdown is synched with it.
float(RoundToNearest(randomtime));
tInfect = CreateTimer(randomtime, InfectMotherZombie, _, TIMER_FLAG_NO_MAPCHANGE);
// Check cvar and start a countdown timer if enabled.
new bool:countdown = GetConVarBool(g_hCvarsList[CVAR_INFECT_MZOMBIE_COUNTDOWN]);
if (countdown)
{
// Store the time until infection, and initialize the counter.
new Handle:hCountdownData = CreateDataPack();
WritePackFloat(hCountdownData, randomtime);
WritePackFloat(hCountdownData, 0.0);
tInfectCountdown = CreateTimer(1.0, InfectCountdown, hCountdownData, TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
// Display initial tick.
InfectCountdown(tInfectCountdown, hCountdownData);
}
}
/**
@ -551,6 +564,49 @@ public Action:InfectMotherZombie(Handle:timer)
CloseHandle(arrayEligibleClients);
}
/**
* Timer callback, displays countdown to clients.
*
* @param timer The timer handle.
*/
public Action:InfectCountdown(Handle:timer, Handle:hCountdownData)
{
new bool:countdown = GetConVarBool(g_hCvarsList[CVAR_INFECT_MZOMBIE_COUNTDOWN]);
if (!countdown)
{
// Kill the timer.
ZREndTimer(tInfectCountdown, false);
CloseHandle(hCountdownData);
return Plugin_Stop;
}
// Read the info from the datapack.
ResetPack(hCountdownData);
new Float:length = ReadPackFloat(hCountdownData);
new Float:counter = ReadPackFloat(hCountdownData);
// Check if the countdown has finished.
if (counter >= length)
{
// Kill timer.
ZREndTimer(tInfectCountdown, false);
CloseHandle(hCountdownData);
return Plugin_Stop;
}
// Print the countdown text to the clients.
TranslationPrintCenterTextAll(false, "Infect countdown", RoundToNearest(length - counter));
counter++;
// Write the new counter value to the datapack.
ResetPack(hCountdownData);
WritePackFloat(hCountdownData, length);
WritePackFloat(hCountdownData, counter);
return Plugin_Continue;
}
/**
* Infects a client. Execute events, sets attributes and flags that indicate
* that the client is a zombie.