2013-01-04 18:24:32 +01:00
|
|
|
/*
|
|
|
|
* ============================================================================
|
|
|
|
*
|
|
|
|
* Zombie:Reloaded
|
|
|
|
*
|
|
|
|
* File: immunityhandler.inc
|
|
|
|
* Type: Core module
|
|
|
|
* Description: Manages infection immunity modes for every player.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009-2013 Greyscale, Richard Helgeby
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* ============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2013-01-06 00:25:57 +01:00
|
|
|
* Maximum delay of infection.
|
2013-01-04 18:24:32 +01:00
|
|
|
*/
|
2013-01-06 00:25:57 +01:00
|
|
|
#define IMMUNITY_MAX_DELAY 300
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maximum shield duration.
|
|
|
|
*/
|
|
|
|
#define IMMUNITY_MAX_SHIELD_TIME 300
|
2013-01-04 18:24:32 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Timers for handling timed immunity actions.
|
|
|
|
*/
|
|
|
|
new Handle:PlayerImmunityTimer[MAXPLAYERS + 1] = {INVALID_HANDLE, ...};
|
|
|
|
|
|
|
|
/**
|
2013-01-05 02:44:46 +01:00
|
|
|
* Remaining time of timed immunity actions.
|
2013-01-04 18:24:32 +01:00
|
|
|
*/
|
2013-01-05 02:44:46 +01:00
|
|
|
new PlayerImmunityDuration[MAXPLAYERS + 1] = {-1, ...};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cached attacker index for delayed infections, if available.
|
|
|
|
*/
|
|
|
|
new PlayerImmunityAttacker[MAXPLAYERS + 1] = {0, ...};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Timestamp of last action. Usage depends on mode (cooldown, etc).
|
|
|
|
*/
|
|
|
|
new PlayerImmunityLastUse[MAXPLAYERS + 1] = {0, ...};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the player has passed a threshold (infect mode).
|
|
|
|
*/
|
|
|
|
new bool:PlayerImmunityThresholdPassed[MAXPLAYERS + 1] = {false, ...};
|
2013-01-04 18:24:32 +01:00
|
|
|
|
2013-01-05 22:58:43 +01:00
|
|
|
/*____________________________________________________________________________*/
|
|
|
|
|
2013-01-07 01:45:55 +01:00
|
|
|
/**
|
|
|
|
* Console commands are being created.
|
|
|
|
*/
|
|
|
|
ImmunityOnCommandsCreate()
|
|
|
|
{
|
2013-01-11 10:16:48 +01:00
|
|
|
RegConsoleCmd(SAYHOOKS_KEYWORD_ZSHIELD, Command_DeployShield, "Deploy the shield, if available.");
|
2013-01-07 01:45:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*____________________________________________________________________________*/
|
|
|
|
|
2016-02-06 00:47:47 +01:00
|
|
|
/**
|
2013-01-07 01:45:55 +01:00
|
|
|
* Client executed the deploy shield command.
|
|
|
|
*
|
|
|
|
* @param client Client index.
|
|
|
|
* @param argc Number of arguments.
|
|
|
|
*/
|
|
|
|
public Action:Command_DeployShield(client, argc)
|
|
|
|
{
|
|
|
|
// Block console.
|
|
|
|
if (ZRIsConsole(client))
|
|
|
|
{
|
|
|
|
TranslationPrintToServer("Must be player");
|
|
|
|
return Plugin_Handled;
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-07 01:45:55 +01:00
|
|
|
// Attempt to deploy shield.
|
|
|
|
ImmunityDeployShield(client);
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-07 01:45:55 +01:00
|
|
|
return Plugin_Handled;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*____________________________________________________________________________*/
|
|
|
|
|
2013-01-04 18:24:32 +01:00
|
|
|
/**
|
|
|
|
* Handles immunity when a client is about to be infected. This function may
|
|
|
|
* delay or block infection according to the immunity mode class settings.
|
|
|
|
*
|
|
|
|
* @param client Client that's being infected.
|
2013-01-05 02:44:46 +01:00
|
|
|
* @param attacker Attacker client (zombie).
|
2013-01-04 18:24:32 +01:00
|
|
|
*
|
|
|
|
* @return True if infection will be handled by this module, false if
|
|
|
|
* infection can be applied instantly.
|
|
|
|
*/
|
2013-01-05 02:44:46 +01:00
|
|
|
bool:ImmunityOnClientInfect(client, attacker)
|
2013-01-04 18:24:32 +01:00
|
|
|
{
|
2013-01-05 02:44:46 +01:00
|
|
|
// Get immunity mode from client class.
|
2013-01-04 18:24:32 +01:00
|
|
|
new ImmunityMode:mode = ClassGetImmunityMode(client);
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-04 18:24:32 +01:00
|
|
|
// Check mode.
|
|
|
|
switch(mode)
|
|
|
|
{
|
|
|
|
case Immunity_None:
|
|
|
|
{
|
|
|
|
// Instant infection.
|
|
|
|
return false;
|
|
|
|
}
|
2013-01-11 10:07:18 +01:00
|
|
|
case Immunity_Kill:
|
|
|
|
{
|
|
|
|
// Block infection. Damage is increased in ImmunityOnClientDamage.
|
|
|
|
return true;
|
|
|
|
}
|
2013-01-04 18:24:32 +01:00
|
|
|
case Immunity_Full:
|
|
|
|
{
|
|
|
|
// Full immunity, do nothing.
|
|
|
|
return true;
|
|
|
|
}
|
2013-01-05 02:44:46 +01:00
|
|
|
case Immunity_Infect:
|
2013-01-04 18:24:32 +01:00
|
|
|
{
|
2013-01-05 21:10:38 +01:00
|
|
|
return ImmunityInfectModeHandler(client);
|
2013-01-04 18:24:32 +01:00
|
|
|
}
|
|
|
|
case Immunity_Delay:
|
|
|
|
{
|
2013-01-05 02:44:46 +01:00
|
|
|
return ImmunityDelayModeHandler(client, attacker);
|
2013-01-04 18:24:32 +01:00
|
|
|
}
|
|
|
|
case Immunity_Shield:
|
|
|
|
{
|
|
|
|
return ImmunityShieldModeHandler(client);
|
|
|
|
}
|
2013-01-05 02:44:46 +01:00
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-05 02:44:46 +01:00
|
|
|
// Current mode doesn't apply to infection.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-01-05 22:58:43 +01:00
|
|
|
/*____________________________________________________________________________*/
|
|
|
|
|
2013-01-05 02:44:46 +01:00
|
|
|
/**
|
|
|
|
* TraceAttack hook.
|
|
|
|
*
|
|
|
|
* Returns whether attacker damage should be blocked. If damage is blocked this
|
|
|
|
* module will handle it.
|
|
|
|
*
|
|
|
|
* @param client Client index.
|
|
|
|
* @param attacker Attacker client, if any.
|
|
|
|
* @param damage Damage received by client.
|
|
|
|
* @param hitgroup Hitgroup receiving damage.
|
|
|
|
*
|
|
|
|
* @return True if damage should be blocked, false otherwise.
|
|
|
|
*/
|
|
|
|
bool:ImmunityOnClientTraceAttack(client, attacker, Float:damage, hitgroup, damageType)
|
|
|
|
{
|
|
|
|
// Check if there is no attacker (world damage).
|
|
|
|
if (!ZRIsClientValid(attacker))
|
|
|
|
{
|
|
|
|
// Allow damage.
|
|
|
|
return false;
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-05 02:44:46 +01:00
|
|
|
// Get immunity mode from client class.
|
|
|
|
new ImmunityMode:mode = ClassGetImmunityMode(client);
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-05 02:44:46 +01:00
|
|
|
// Check mode.
|
|
|
|
switch(mode)
|
|
|
|
{
|
|
|
|
case Immunity_Full:
|
2013-01-04 18:24:32 +01:00
|
|
|
{
|
2013-01-06 00:25:57 +01:00
|
|
|
// Block damage (implies blocking knock back on zombies).
|
2013-01-04 18:24:32 +01:00
|
|
|
return true;
|
|
|
|
}
|
2013-01-05 02:44:46 +01:00
|
|
|
case Immunity_Infect:
|
|
|
|
{
|
|
|
|
// Client must be human.
|
|
|
|
if (InfectIsClientInfected(client))
|
|
|
|
{
|
|
|
|
// Allow damage.
|
|
|
|
return false;
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-05 02:44:46 +01:00
|
|
|
// Check if damage give HP below the infection threshold.
|
|
|
|
if (ImmunityBelowInfectThreshold(client, damage))
|
|
|
|
{
|
|
|
|
PlayerImmunityThresholdPassed[client] = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PlayerImmunityThresholdPassed[client] = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case Immunity_Damage:
|
|
|
|
{
|
|
|
|
// Client must be zombie.
|
|
|
|
if (!InfectIsClientInfected(client))
|
|
|
|
{
|
2013-01-06 00:25:57 +01:00
|
|
|
// Allow damage.
|
2013-01-05 02:44:46 +01:00
|
|
|
return false;
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-05 02:44:46 +01:00
|
|
|
// Get attacker weapon.
|
|
|
|
decl String:weapon[32];
|
|
|
|
weapon[0] = 0;
|
|
|
|
if (damageType == DMG_BLAST)
|
|
|
|
{
|
|
|
|
// Most likely a HE grenade. GetClientWeapon can't be used if
|
|
|
|
// the attacker throw grenades. The attacker may switch weapon
|
|
|
|
// before the grenade explodes.
|
|
|
|
strcopy(weapon, sizeof(weapon), "hegrenade");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GetClientWeapon(attacker, weapon, sizeof(weapon));
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-05 02:44:46 +01:00
|
|
|
// Since damage is blocked, trigger knock back hurt event manually.
|
|
|
|
KnockbackOnClientHurt(client, attacker, weapon, hitgroup, RoundToNearest(damage));
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-05 02:44:46 +01:00
|
|
|
// Block damage from attacker.
|
|
|
|
return true;
|
|
|
|
}
|
2013-01-07 01:45:55 +01:00
|
|
|
case Immunity_Shield:
|
|
|
|
{
|
|
|
|
// Client must be human.
|
|
|
|
if (InfectIsClientInfected(client))
|
|
|
|
{
|
|
|
|
// Allow damage.
|
|
|
|
return false;
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-07 01:45:55 +01:00
|
|
|
// Check if shield is active.
|
|
|
|
if (PlayerImmunityTimer[client] != INVALID_HANDLE)
|
|
|
|
{
|
|
|
|
// Block damage for humans with shield enabled (preventing
|
|
|
|
// zombies from stabbing them to death).
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2013-01-04 18:24:32 +01:00
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-06 00:25:57 +01:00
|
|
|
// Allow damage.
|
2013-01-05 02:44:46 +01:00
|
|
|
return false;
|
2013-01-04 18:24:32 +01:00
|
|
|
}
|
|
|
|
|
2013-01-05 22:58:43 +01:00
|
|
|
/*____________________________________________________________________________*/
|
|
|
|
|
2013-01-04 18:24:32 +01:00
|
|
|
/**
|
2013-01-05 02:44:46 +01:00
|
|
|
* TakeDamage hook.
|
|
|
|
*
|
|
|
|
* Blocks or modifies damage in certain situations.
|
2013-01-04 18:24:32 +01:00
|
|
|
*
|
2013-01-05 02:44:46 +01:00
|
|
|
* @param client Client index.
|
|
|
|
* @param attacker Attacker client, if any.
|
|
|
|
* @param damage Damage received by client.
|
2013-01-11 10:07:18 +01:00
|
|
|
* @param weapon Weapon entity.
|
2013-01-04 18:24:32 +01:00
|
|
|
*
|
2013-01-11 10:07:18 +01:00
|
|
|
* @return Plugin_Handled if damage was blocked, Plugin_Changed if
|
|
|
|
* damage was modified, Plugin_Continue otherwise.
|
2013-01-04 18:24:32 +01:00
|
|
|
*/
|
2013-01-11 10:07:18 +01:00
|
|
|
Action:ImmunityOnClientDamage(client, attacker, &Float:damage)
|
2013-01-04 18:24:32 +01:00
|
|
|
{
|
2013-01-05 02:44:46 +01:00
|
|
|
// Check if there is no attacker (world damage).
|
|
|
|
if (!ZRIsClientValid(attacker))
|
|
|
|
{
|
|
|
|
// Allow damage.
|
2013-01-11 10:07:18 +01:00
|
|
|
return Plugin_Continue;
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-11 10:07:18 +01:00
|
|
|
// Check if spawn protection is on.
|
2017-01-22 15:09:22 +01:00
|
|
|
if (g_bInfectImmune[client])
|
2013-01-11 10:07:18 +01:00
|
|
|
{
|
|
|
|
// Block damage.
|
|
|
|
return Plugin_Handled;
|
2013-01-05 02:44:46 +01:00
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-05 02:44:46 +01:00
|
|
|
// Get immunity mode from client class.
|
|
|
|
new ImmunityMode:mode = ClassGetImmunityMode(client);
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-05 02:44:46 +01:00
|
|
|
switch(mode)
|
|
|
|
{
|
2013-01-11 10:07:18 +01:00
|
|
|
case Immunity_Kill:
|
|
|
|
{
|
|
|
|
// Client must be human and attacker must be zombie.
|
|
|
|
if (InfectIsClientInfected(client)
|
|
|
|
|| !InfectIsClientInfected(attacker))
|
|
|
|
{
|
|
|
|
// Don't modify damage.
|
|
|
|
return Plugin_Continue;
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-11 10:07:18 +01:00
|
|
|
// A zombie is attacking a human in kill immunity mode. Increase
|
|
|
|
// damage so human will be instantly killed. (Using a high damage
|
|
|
|
// value in case the human class has a lot of HP.)
|
|
|
|
damage = 60000.0;
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-11 10:07:18 +01:00
|
|
|
// Update score and health gain.
|
|
|
|
InfectUpdateScore(attacker, client);
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-11 10:07:18 +01:00
|
|
|
// Damage was changed.
|
|
|
|
return Plugin_Changed;
|
|
|
|
}
|
2013-01-05 02:44:46 +01:00
|
|
|
case Immunity_Infect:
|
|
|
|
{
|
|
|
|
// Prevent humans with low HP from dying when a zombie is
|
|
|
|
// attacking, and stab to death is disabled (threshold above zero).
|
|
|
|
if (ImmunityBelowInfectThreshold(client, damage))
|
|
|
|
{
|
|
|
|
// Fake hurt event because it's not triggered when the damage
|
|
|
|
// was removed (because no one is actually hurt).
|
|
|
|
InfectOnClientHurt(client, attacker, "knife");
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-05 02:44:46 +01:00
|
|
|
// Block damage to prevent player from dying.
|
2013-01-11 10:07:18 +01:00
|
|
|
return Plugin_Handled;
|
2013-01-05 02:44:46 +01:00
|
|
|
}
|
|
|
|
}
|
2013-01-05 22:58:43 +01:00
|
|
|
case Immunity_Delay:
|
|
|
|
{
|
|
|
|
// Fake hurt event because it's not triggered when the damage
|
|
|
|
// was removed (because no one is actually hurt). This event must
|
|
|
|
// still be triggered so that subsequent attacks are registered,
|
|
|
|
// without dealing any damage.
|
|
|
|
InfectOnClientHurt(client, attacker, "knife");
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-05 22:58:43 +01:00
|
|
|
// Block damage to prevent player from dying.
|
2013-01-11 10:07:18 +01:00
|
|
|
return Plugin_Handled;
|
2013-01-05 22:58:43 +01:00
|
|
|
}
|
2013-01-05 02:44:46 +01:00
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-05 02:44:46 +01:00
|
|
|
// Allow damage.
|
2013-01-11 10:07:18 +01:00
|
|
|
return Plugin_Continue;
|
2013-01-04 18:24:32 +01:00
|
|
|
}
|
|
|
|
|
2013-01-05 22:58:43 +01:00
|
|
|
/*____________________________________________________________________________*/
|
|
|
|
|
2013-01-04 18:24:32 +01:00
|
|
|
/**
|
2013-01-05 02:44:46 +01:00
|
|
|
* Handles infect mode immunity.
|
|
|
|
*
|
|
|
|
* Allow humans to receive damage from zombies until HP is below a certain
|
|
|
|
* threshold. If the threshold is zero, never infect.
|
2013-01-04 18:24:32 +01:00
|
|
|
*
|
|
|
|
* @param client Client that's being infected.
|
2013-01-05 02:44:46 +01:00
|
|
|
* @param attacker Attacker client (zombie).
|
2013-01-04 18:24:32 +01:00
|
|
|
*
|
|
|
|
* @return True if infection will be handled by this module, false if
|
|
|
|
* infection can be applied instantly.
|
|
|
|
*/
|
2013-01-05 21:10:38 +01:00
|
|
|
bool:ImmunityInfectModeHandler(client)
|
2013-01-04 18:24:32 +01:00
|
|
|
{
|
2013-01-05 02:44:46 +01:00
|
|
|
// Note: ImmunityOnClientDamage and ImmunityOnClientTraceAttack hook into
|
|
|
|
// the damage module to prevent humans with low HP from dying when
|
|
|
|
// they're not supposed to.
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-05 02:44:46 +01:00
|
|
|
new threshold = ClassGetImmunityAmount(client);
|
|
|
|
// Check if infection is disabled.
|
|
|
|
if (threshold == 0)
|
|
|
|
{
|
|
|
|
// Infection is handled here: blocked.
|
|
|
|
return true;
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-05 02:44:46 +01:00
|
|
|
if (PlayerImmunityThresholdPassed[client])
|
|
|
|
{
|
|
|
|
// Client HP below threshold, allow instant infection.
|
|
|
|
return false;
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-05 02:44:46 +01:00
|
|
|
return true;
|
2013-01-04 18:24:32 +01:00
|
|
|
}
|
|
|
|
|
2013-01-05 22:58:43 +01:00
|
|
|
/*____________________________________________________________________________*/
|
|
|
|
|
2013-01-04 18:24:32 +01:00
|
|
|
/**
|
|
|
|
* Handles delayed infections.
|
|
|
|
*
|
|
|
|
* @param client Client that's being infected.
|
|
|
|
*
|
|
|
|
* @return True if infection will be handled by this module, false if
|
|
|
|
* infection can be applied instantly.
|
|
|
|
*/
|
2013-01-05 02:44:46 +01:00
|
|
|
bool:ImmunityDelayModeHandler(client, attacker)
|
2013-01-04 18:24:32 +01:00
|
|
|
{
|
2013-01-05 02:44:46 +01:00
|
|
|
// Check if an infection is in progress
|
|
|
|
if (PlayerImmunityTimer[client] != INVALID_HANDLE)
|
|
|
|
{
|
|
|
|
// Additional attacks while a delayed infection is in progress will
|
|
|
|
// speedup the infection.
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-05 22:58:43 +01:00
|
|
|
// Get reduction amount for subsequent zombie attack.
|
|
|
|
new reduction = ClassGetImmunityCooldown(client);
|
|
|
|
if (reduction > 0)
|
|
|
|
{
|
|
|
|
// Reduce duration. Add one because the timer handler itself reduce
|
|
|
|
// duration by one.
|
|
|
|
PlayerImmunityDuration[client] -= reduction + 1;
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-05 22:58:43 +01:00
|
|
|
// Note: This feature can be used to trigger an instant infection
|
|
|
|
// when a human receive a second attack, by setting the
|
|
|
|
// reduction value high enough.
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-05 22:58:43 +01:00
|
|
|
// Trigger timer event to reduce delay and infect faster.
|
|
|
|
ImmunityDelayTimerHandler(PlayerImmunityTimer[client], client);
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-05 02:44:46 +01:00
|
|
|
// Block infection.
|
2013-01-05 22:58:43 +01:00
|
|
|
return true;
|
2013-01-05 02:44:46 +01:00
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-05 02:44:46 +01:00
|
|
|
// Start a delayed infection. Initialize duration and attacker.
|
|
|
|
PlayerImmunityDuration[client] = ClassGetImmunityAmount(client);
|
|
|
|
PlayerImmunityAttacker[client] = attacker;
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-05 22:58:43 +01:00
|
|
|
// Create repated 1-second timer for handling the countdown.
|
2013-01-05 02:44:46 +01:00
|
|
|
PlayerImmunityTimer[client] = CreateTimer(1.0, ImmunityDelayTimerHandler, client, TIMER_FLAG_NO_MAPCHANGE | TIMER_REPEAT);
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-05 02:44:46 +01:00
|
|
|
// Block infection.
|
2013-01-05 22:58:43 +01:00
|
|
|
return true;
|
2013-01-05 02:44:46 +01:00
|
|
|
}
|
|
|
|
|
2013-01-05 22:58:43 +01:00
|
|
|
/*____________________________________________________________________________*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delayed infection timer handler. Handles countdown and infection when time
|
|
|
|
* is up.
|
|
|
|
*/
|
2013-01-05 02:44:46 +01:00
|
|
|
public Action:ImmunityDelayTimerHandler(Handle:timer, any:client)
|
|
|
|
{
|
2013-01-05 22:58:43 +01:00
|
|
|
// Verify that client is still connected and alive.
|
2013-01-05 02:44:46 +01:00
|
|
|
if (!IsClientInGame(client) || !IsPlayerAlive(client))
|
|
|
|
{
|
|
|
|
// Client disconnected or died. Abort immunity action.
|
2013-01-07 01:45:55 +01:00
|
|
|
ImmunityAbortHandler(client);
|
2013-01-05 02:44:46 +01:00
|
|
|
return Plugin_Stop;
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-05 02:44:46 +01:00
|
|
|
// Reduce duration.
|
2013-01-05 22:58:43 +01:00
|
|
|
PlayerImmunityDuration[client] -= 1;
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-05 02:44:46 +01:00
|
|
|
// Check if time is up.
|
|
|
|
if (PlayerImmunityDuration[client] <= 0)
|
|
|
|
{
|
2013-04-14 02:36:10 +02:00
|
|
|
// Get attacker before cleaning up.
|
|
|
|
new attacker = PlayerImmunityAttacker[client];
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-05 02:44:46 +01:00
|
|
|
// Time is up. Reset data.
|
|
|
|
PlayerImmunityDuration[client] = 0;
|
2013-01-05 22:58:43 +01:00
|
|
|
ImmunityAbortHandler(client);
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-04-14 02:36:10 +02:00
|
|
|
// Infect client. Give credit to the stored attacker.
|
|
|
|
InfectHumanToZombie(client, attacker);
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-05 02:44:46 +01:00
|
|
|
return Plugin_Stop;
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-05 02:44:46 +01:00
|
|
|
return Plugin_Continue;
|
2013-01-04 18:24:32 +01:00
|
|
|
}
|
|
|
|
|
2013-01-05 22:58:43 +01:00
|
|
|
/*____________________________________________________________________________*/
|
|
|
|
|
2013-01-04 18:24:32 +01:00
|
|
|
/**
|
2013-01-07 01:45:55 +01:00
|
|
|
* Handles shield mode immunity when client is about to become infected.
|
2013-01-04 18:24:32 +01:00
|
|
|
*
|
2013-01-05 02:44:46 +01:00
|
|
|
* Zombies will get a shield against knock back, while humans become immune of
|
|
|
|
* infections.
|
|
|
|
*
|
|
|
|
* @param client Client deploying shield.
|
2013-01-04 18:24:32 +01:00
|
|
|
*
|
|
|
|
* @return True if infection will be handled by this module, false if
|
|
|
|
* infection can be applied instantly.
|
|
|
|
*/
|
2013-01-07 01:45:55 +01:00
|
|
|
bool:ImmunityShieldModeHandler(client)
|
|
|
|
{
|
|
|
|
// Check if shield is active.
|
|
|
|
if (PlayerImmunityTimer[client] != INVALID_HANDLE)
|
|
|
|
{
|
|
|
|
// Block infection.
|
|
|
|
return true;
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-07 01:45:55 +01:00
|
|
|
// Shield is not active, allow infection.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*____________________________________________________________________________*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attempts to deploy the shield.
|
|
|
|
*
|
|
|
|
* @param client Client index.
|
|
|
|
*/
|
|
|
|
ImmunityDeployShield(client)
|
2013-01-04 18:24:32 +01:00
|
|
|
{
|
2013-01-07 01:45:55 +01:00
|
|
|
// Check if shield is available.
|
|
|
|
if (!ImmunityCanDeployShield(client))
|
|
|
|
{
|
|
|
|
// Not available.
|
|
|
|
return;
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-07 01:45:55 +01:00
|
|
|
// Deploy the shield.
|
|
|
|
PlayerImmunityDuration[client] = ClassGetImmunityAmount(client);
|
|
|
|
PlayerImmunityLastUse[client] = GetTime();
|
|
|
|
PlayerImmunityTimer[client] = CreateTimer(1.0, ImmunityShieldTimerHandler, client, TIMER_FLAG_NO_MAPCHANGE | TIMER_REPEAT);
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-07 01:45:55 +01:00
|
|
|
// Trigger initial countdown.
|
|
|
|
ImmunityShieldTimerHandler(PlayerImmunityTimer[client], client);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*____________________________________________________________________________*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shield timer handler. Handles countdown and shield removal when time is up.
|
|
|
|
*/
|
|
|
|
public Action:ImmunityShieldTimerHandler(Handle:timer, any:client)
|
|
|
|
{
|
|
|
|
// Verify that client is still connected and alive.
|
|
|
|
if (!IsClientInGame(client) || !IsPlayerAlive(client))
|
2013-01-05 21:10:38 +01:00
|
|
|
{
|
2013-01-07 01:45:55 +01:00
|
|
|
// Client disconnected or died. Abort immunity action.
|
|
|
|
ImmunityAbortHandler(client);
|
|
|
|
return Plugin_Stop;
|
2013-01-05 21:10:38 +01:00
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-07 01:45:55 +01:00
|
|
|
// Reduce duration.
|
|
|
|
PlayerImmunityDuration[client] -= 1;
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-07 01:45:55 +01:00
|
|
|
// Print remaining shield time.
|
|
|
|
TranslationPrintCenterText(client, "Immunity Shield Time Left", PlayerImmunityDuration[client]);
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-07 01:45:55 +01:00
|
|
|
// Check if time is up.
|
|
|
|
if (PlayerImmunityDuration[client] <= 0)
|
2013-01-05 21:10:38 +01:00
|
|
|
{
|
2013-01-07 01:45:55 +01:00
|
|
|
// Time is up. Reset data, but not last use timestamp.
|
|
|
|
ImmunityAbortHandler(client, false);
|
|
|
|
return Plugin_Stop;
|
2013-01-05 21:10:38 +01:00
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-07 01:45:55 +01:00
|
|
|
return Plugin_Continue;
|
2013-01-04 18:24:32 +01:00
|
|
|
}
|
|
|
|
|
2013-01-05 22:58:43 +01:00
|
|
|
/*____________________________________________________________________________*/
|
|
|
|
|
2013-01-04 18:24:32 +01:00
|
|
|
/**
|
2013-01-05 02:44:46 +01:00
|
|
|
* Aborts any immunity mode in action (shields, delays, etc.). Resets values.
|
2013-01-04 18:24:32 +01:00
|
|
|
*
|
2013-01-05 02:44:46 +01:00
|
|
|
* @param client Client that's aborting immunity mode actions.
|
|
|
|
* @param resetLastUse Reset timestamp of last use. This will reset cooldown.
|
2013-01-04 18:24:32 +01:00
|
|
|
*/
|
2013-01-05 02:44:46 +01:00
|
|
|
ImmunityAbortHandler(client, bool:resetLastUse = true)
|
2013-01-04 18:24:32 +01:00
|
|
|
{
|
2013-01-05 02:44:46 +01:00
|
|
|
// Stop timer, if running.
|
|
|
|
ZREndTimer(PlayerImmunityTimer[client]);
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-05 02:44:46 +01:00
|
|
|
// Reset data.
|
|
|
|
PlayerImmunityDuration[client] = -1;
|
|
|
|
PlayerImmunityAttacker[client] = 0;
|
|
|
|
PlayerImmunityThresholdPassed[client] = false;
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-05 02:44:46 +01:00
|
|
|
if (resetLastUse)
|
|
|
|
{
|
|
|
|
PlayerImmunityLastUse[client] = 0;
|
|
|
|
}
|
2013-01-04 18:24:32 +01:00
|
|
|
}
|
|
|
|
|
2013-01-05 22:58:43 +01:00
|
|
|
/*____________________________________________________________________________*/
|
|
|
|
|
2013-01-05 02:44:46 +01:00
|
|
|
/**
|
|
|
|
* Aborts all immunity modes in action.
|
|
|
|
*
|
|
|
|
* @param resetLastUse Reset timestamp of last use. This will reset cooldown.
|
|
|
|
*/
|
|
|
|
ImmunityAbortAll(bool:resetLastUse = true)
|
2013-01-04 18:24:32 +01:00
|
|
|
{
|
2013-01-05 02:44:46 +01:00
|
|
|
for (new client = 0; client < MAXPLAYERS + 1; client++)
|
|
|
|
{
|
|
|
|
ImmunityAbortHandler(resetLastUse);
|
|
|
|
}
|
2013-01-04 18:24:32 +01:00
|
|
|
}
|
|
|
|
|
2013-01-05 22:58:43 +01:00
|
|
|
/*____________________________________________________________________________*/
|
|
|
|
|
2013-01-07 01:45:55 +01:00
|
|
|
/**
|
|
|
|
* Client is about to receive knock back.
|
|
|
|
*
|
|
|
|
* @param Client that's receiving knock back.
|
|
|
|
*
|
|
|
|
* @return True if knock back should be blocked, false otherwise.
|
|
|
|
*/
|
|
|
|
bool:ImmunityOnClientKnockBack(client)
|
|
|
|
{
|
|
|
|
// Knock back filter is currently only used in shield mode.
|
|
|
|
if (ClassGetImmunityMode(client) == Immunity_Shield)
|
|
|
|
{
|
|
|
|
// Client must be zombie. (In case a future change allow knock back
|
|
|
|
// on humans.)
|
|
|
|
if (!InfectIsClientInfected(client))
|
|
|
|
{
|
|
|
|
// Client is human, allow knock back.
|
|
|
|
return false;
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-07 01:45:55 +01:00
|
|
|
// Block knock back if shield is deployed.
|
|
|
|
if (PlayerImmunityTimer[client] != INVALID_HANDLE)
|
|
|
|
{
|
|
|
|
// Block knock back.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-07 01:45:55 +01:00
|
|
|
// Allow knock back.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*____________________________________________________________________________*/
|
|
|
|
|
2013-01-05 22:58:43 +01:00
|
|
|
/**
|
|
|
|
* Client was infected.
|
|
|
|
*/
|
|
|
|
ImmunityOnClientInfected(client)
|
|
|
|
{
|
|
|
|
// In case client was infected through an admin command or mother zombie
|
|
|
|
// selection, abort other actions in progress.
|
|
|
|
ImmunityAbortHandler(client);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*____________________________________________________________________________*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Client was turned back into a human.
|
|
|
|
*/
|
2013-01-04 18:24:32 +01:00
|
|
|
ImmunityOnClientHuman(client)
|
|
|
|
{
|
2013-01-05 02:44:46 +01:00
|
|
|
ImmunityAbortHandler(client);
|
2013-01-04 18:24:32 +01:00
|
|
|
}
|
|
|
|
|
2013-01-05 22:58:43 +01:00
|
|
|
/*____________________________________________________________________________*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Client died.
|
|
|
|
*/
|
2013-01-05 02:44:46 +01:00
|
|
|
ImmunityOnClientDeath(client)
|
2013-01-04 18:24:32 +01:00
|
|
|
{
|
2013-01-05 02:44:46 +01:00
|
|
|
ImmunityAbortHandler(client, false);
|
2013-01-04 18:24:32 +01:00
|
|
|
}
|
|
|
|
|
2013-01-05 22:58:43 +01:00
|
|
|
/*____________________________________________________________________________*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Client connected to the server.
|
|
|
|
*/
|
2013-01-04 18:24:32 +01:00
|
|
|
ImmunityClientInit(client)
|
|
|
|
{
|
2013-01-05 02:44:46 +01:00
|
|
|
ImmunityAbortHandler(client);
|
2013-01-04 18:24:32 +01:00
|
|
|
}
|
|
|
|
|
2013-01-05 22:58:43 +01:00
|
|
|
/*____________________________________________________________________________*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Client spawned.
|
|
|
|
*/
|
2013-01-05 02:44:46 +01:00
|
|
|
ImmunityClientSpawn(client)
|
2013-01-04 18:24:32 +01:00
|
|
|
{
|
2013-01-05 02:44:46 +01:00
|
|
|
ImmunityAbortHandler(client, false);
|
2013-01-04 18:24:32 +01:00
|
|
|
}
|
|
|
|
|
2013-01-05 22:58:43 +01:00
|
|
|
/*____________________________________________________________________________*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Client disconnected.
|
|
|
|
*/
|
2013-01-05 02:44:46 +01:00
|
|
|
ImmunityOnClientDisconnect(client)
|
2013-01-04 18:24:32 +01:00
|
|
|
{
|
2013-01-05 21:10:38 +01:00
|
|
|
ImmunityAbortHandler(client);
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-05 02:44:46 +01:00
|
|
|
// Loop through attacker cache and remove client (set to 0).
|
2013-01-05 21:10:38 +01:00
|
|
|
for (new victim = 0; victim < sizeof(PlayerImmunityAttacker); victim++)
|
|
|
|
{
|
|
|
|
if (PlayerImmunityAttacker[victim] == client)
|
|
|
|
{
|
|
|
|
// The victim was attacked by this client, but the client is
|
|
|
|
// disconnecting now. Reset the attacker index to the world index.
|
|
|
|
PlayerImmunityAttacker[victim] = 0;
|
|
|
|
}
|
|
|
|
}
|
2013-01-05 02:44:46 +01:00
|
|
|
}
|
|
|
|
|
2013-01-05 22:58:43 +01:00
|
|
|
/*____________________________________________________________________________*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Client changed team.
|
|
|
|
*/
|
2013-01-05 02:44:46 +01:00
|
|
|
ImmunityOnClientTeam(client)
|
|
|
|
{
|
|
|
|
ImmunityAbortHandler(client);
|
2013-01-04 18:24:32 +01:00
|
|
|
}
|
|
|
|
|
2013-01-05 22:58:43 +01:00
|
|
|
/*____________________________________________________________________________*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Round ended.
|
|
|
|
*/
|
2013-01-04 18:24:32 +01:00
|
|
|
ImmunityOnRoundEnd()
|
|
|
|
{
|
|
|
|
ImmunityAbortAll();
|
|
|
|
}
|
|
|
|
|
2013-01-05 22:58:43 +01:00
|
|
|
/*____________________________________________________________________________*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Map ended.
|
|
|
|
*/
|
2013-01-04 18:24:32 +01:00
|
|
|
ImmunityOnMapEnd()
|
|
|
|
{
|
|
|
|
ImmunityAbortAll();
|
|
|
|
}
|
|
|
|
|
2013-01-05 22:58:43 +01:00
|
|
|
/*____________________________________________________________________________*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether the specified damage will take a client's HP below the
|
|
|
|
* infection threshold. Only used by "infect" immunity mode.
|
|
|
|
*
|
2013-01-11 10:07:18 +01:00
|
|
|
* If threshold is disabled (zero) this function will always return false.
|
|
|
|
*
|
2013-01-05 22:58:43 +01:00
|
|
|
* @param client Client index.
|
|
|
|
* @param damage Damage applied to client.
|
|
|
|
*
|
|
|
|
* @return True if client HP go below threshold (immunity_amount) when
|
2013-01-11 10:07:18 +01:00
|
|
|
* applying damage, false if above threshold or if threshold
|
|
|
|
* is disabled (zero).
|
2013-01-05 22:58:43 +01:00
|
|
|
*/
|
2013-01-05 02:44:46 +01:00
|
|
|
bool:ImmunityBelowInfectThreshold(client, Float:damage)
|
|
|
|
{
|
|
|
|
new threshold = ClassGetImmunityAmount(client);
|
|
|
|
new clientHP = GetClientHealth(client);
|
|
|
|
new dmg = RoundToNearest(damage);
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-11 10:07:18 +01:00
|
|
|
// Check if the damage go below the HP threshold. Client can only go below
|
|
|
|
// threshold when threshold is enabled (above zero).
|
|
|
|
if (clientHP - dmg <= threshold && threshold > 0)
|
2013-01-05 02:44:46 +01:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-05 02:44:46 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-01-05 22:58:43 +01:00
|
|
|
/*____________________________________________________________________________*/
|
|
|
|
|
2013-01-04 18:24:32 +01:00
|
|
|
/**
|
|
|
|
* Converts a string to an immunity mode.
|
|
|
|
*
|
|
|
|
* @param mode String to convert.
|
|
|
|
*
|
|
|
|
* @return Immunity mode or Immunity_Invalid on error.
|
|
|
|
*/
|
|
|
|
ImmunityMode:ImmunityStringToMode(const String:mode[])
|
|
|
|
{
|
|
|
|
if (strlen(mode) == 0)
|
|
|
|
{
|
|
|
|
return Immunity_Invalid;
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-04 18:24:32 +01:00
|
|
|
if (StrEqual(mode, "none", false))
|
|
|
|
{
|
|
|
|
return Immunity_None;
|
|
|
|
}
|
2013-01-11 10:07:18 +01:00
|
|
|
if (StrEqual(mode, "kill", false))
|
|
|
|
{
|
|
|
|
return Immunity_Kill;
|
|
|
|
}
|
2013-01-04 18:24:32 +01:00
|
|
|
else if (StrEqual(mode, "full", false))
|
|
|
|
{
|
|
|
|
return Immunity_Full;
|
|
|
|
}
|
|
|
|
else if (StrEqual(mode, "infect", false))
|
|
|
|
{
|
|
|
|
return Immunity_Infect;
|
|
|
|
}
|
|
|
|
else if (StrEqual(mode, "damage", false))
|
|
|
|
{
|
|
|
|
return Immunity_Damage;
|
|
|
|
}
|
|
|
|
else if (StrEqual(mode, "delay", false))
|
|
|
|
{
|
|
|
|
return Immunity_Delay;
|
|
|
|
}
|
|
|
|
else if (StrEqual(mode, "shield", false))
|
|
|
|
{
|
|
|
|
return Immunity_Shield;
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-04 18:24:32 +01:00
|
|
|
return Immunity_Invalid;
|
|
|
|
}
|
2013-01-05 22:58:43 +01:00
|
|
|
|
|
|
|
/*____________________________________________________________________________*/
|
2013-01-05 21:10:38 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts an immunity mode to a string.
|
|
|
|
*
|
|
|
|
* @param mode Mode to convert.
|
|
|
|
* @param buffer Destination string buffer.
|
|
|
|
* @param maxlen Size of buffer.
|
|
|
|
*
|
|
|
|
* @return Number of cells written.
|
|
|
|
*/
|
|
|
|
ImmunityModeToString(ImmunityMode:mode, String:buffer[], maxlen)
|
|
|
|
{
|
|
|
|
if (mode == Immunity_Invalid)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-05 21:10:38 +01:00
|
|
|
switch (mode)
|
|
|
|
{
|
|
|
|
case Immunity_None:
|
|
|
|
{
|
|
|
|
return strcopy(buffer, maxlen, "none");
|
|
|
|
}
|
2013-01-11 10:07:18 +01:00
|
|
|
case Immunity_Kill:
|
|
|
|
{
|
|
|
|
return strcopy(buffer, maxlen, "kill");
|
|
|
|
}
|
2013-01-05 21:10:38 +01:00
|
|
|
case Immunity_Full:
|
|
|
|
{
|
|
|
|
return strcopy(buffer, maxlen, "full");
|
|
|
|
}
|
|
|
|
case Immunity_Infect:
|
|
|
|
{
|
|
|
|
return strcopy(buffer, maxlen, "infect");
|
|
|
|
}
|
|
|
|
case Immunity_Damage:
|
|
|
|
{
|
|
|
|
return strcopy(buffer, maxlen, "damage");
|
|
|
|
}
|
|
|
|
case Immunity_Delay:
|
|
|
|
{
|
|
|
|
return strcopy(buffer, maxlen, "delay");
|
|
|
|
}
|
|
|
|
case Immunity_Shield:
|
|
|
|
{
|
|
|
|
return strcopy(buffer, maxlen, "shield");
|
|
|
|
}
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-05 21:10:38 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2013-01-06 00:25:57 +01:00
|
|
|
|
2013-01-07 01:45:55 +01:00
|
|
|
/*____________________________________________________________________________*/
|
|
|
|
|
2013-01-06 00:25:57 +01:00
|
|
|
/**
|
|
|
|
* Returns whether the amount value is valid for the specified mode.
|
|
|
|
*
|
|
|
|
* @param mode Immunity mode to validate against.
|
|
|
|
* @param amount Amount value to test.
|
|
|
|
*
|
|
|
|
* @return True if valid, false otherwise.
|
|
|
|
*/
|
|
|
|
bool:ImmunityIsValidAmount(ImmunityMode:mode, amount)
|
|
|
|
{
|
|
|
|
switch (mode)
|
|
|
|
{
|
|
|
|
case Immunity_Invalid:
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
case Immunity_None:
|
|
|
|
{
|
|
|
|
// Immunity mode disabled, amount ignored.
|
|
|
|
return true;
|
|
|
|
}
|
2013-01-11 10:07:18 +01:00
|
|
|
case Immunity_Kill:
|
|
|
|
{
|
|
|
|
// Amount isn't used in this mode.
|
|
|
|
return true;
|
|
|
|
}
|
2013-01-06 00:25:57 +01:00
|
|
|
case Immunity_Full:
|
|
|
|
{
|
|
|
|
// Amount isn't used in this mode.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
case Immunity_Infect:
|
|
|
|
{
|
|
|
|
// Check if HP threshold is negative.
|
|
|
|
if (amount < 0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-06 00:25:57 +01:00
|
|
|
// There's no upper limit. If the value is too high it will
|
|
|
|
// overflow and become negative.
|
|
|
|
}
|
|
|
|
case Immunity_Damage:
|
|
|
|
{
|
|
|
|
// Amount isn't used in this mode.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
case Immunity_Delay:
|
|
|
|
{
|
|
|
|
if (amount <= 0 || amount > IMMUNITY_MAX_DELAY)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case Immunity_Shield:
|
|
|
|
{
|
|
|
|
if (amount <= 0 || amount > IMMUNITY_MAX_SHIELD_TIME)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
// Invalid mode.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-06 00:25:57 +01:00
|
|
|
// Passed.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-01-07 01:45:55 +01:00
|
|
|
/*____________________________________________________________________________*/
|
|
|
|
|
2013-01-06 00:25:57 +01:00
|
|
|
/**
|
|
|
|
* Returns whether the cooldown value is valid for the specified mode.
|
|
|
|
*
|
|
|
|
* @param mode Immunity mode to validate against.
|
|
|
|
* @param cooldown Cooldown value to test.
|
|
|
|
*
|
|
|
|
* @return True if valid, false otherwise.
|
|
|
|
*/
|
|
|
|
bool:ImmunityIsValidCooldown(ImmunityMode:mode, cooldown)
|
|
|
|
{
|
|
|
|
switch (mode)
|
|
|
|
{
|
|
|
|
case Immunity_Invalid:
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
case Immunity_None:
|
|
|
|
{
|
|
|
|
// Immunity mode disabled, amount ignored.
|
|
|
|
return true;
|
|
|
|
}
|
2013-01-11 10:07:18 +01:00
|
|
|
case Immunity_Kill:
|
|
|
|
{
|
|
|
|
// Cooldown isn't used in this mode.
|
|
|
|
return true;
|
|
|
|
}
|
2013-01-06 00:25:57 +01:00
|
|
|
case Immunity_Full:
|
|
|
|
{
|
|
|
|
// Cooldown isn't used in this mode.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
case Immunity_Infect:
|
|
|
|
{
|
|
|
|
// Cooldown isn't used in this mode.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
case Immunity_Damage:
|
|
|
|
{
|
|
|
|
// Cooldown isn't used in this mode.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
case Immunity_Delay:
|
|
|
|
{
|
|
|
|
if (cooldown < 0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-06 00:25:57 +01:00
|
|
|
// No upper limit. It may be intentional to use a high value so that
|
|
|
|
// the section attack will remove all delay and infect instantly.
|
|
|
|
}
|
|
|
|
case Immunity_Shield:
|
|
|
|
{
|
|
|
|
if (cooldown < 0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-06 00:25:57 +01:00
|
|
|
// No upper limit. It may be intentional to use a high value so that
|
|
|
|
// the shield can only be used once per life.
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
// Invalid mode.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-06 00:25:57 +01:00
|
|
|
// Passed.
|
|
|
|
return true;
|
|
|
|
}
|
2013-01-07 01:45:55 +01:00
|
|
|
|
|
|
|
/*____________________________________________________________________________*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether the client is allowed to deploy a shield now. Tests whether
|
|
|
|
* the client has shield immunity mode and whether cooldown is done, or a shield
|
|
|
|
* is already active.
|
|
|
|
*
|
|
|
|
* @param client Client index.
|
|
|
|
* @param printResponse Whether a response message is printed on the
|
|
|
|
* client's screen.
|
|
|
|
*
|
|
|
|
* @return True if shield can be deployed, false otherwise.
|
|
|
|
*/
|
|
|
|
bool:ImmunityCanDeployShield(client, bool:printResponse = true)
|
|
|
|
{
|
|
|
|
// Check immunity mode.
|
|
|
|
if (ClassGetImmunityMode(client) != Immunity_Shield)
|
|
|
|
{
|
|
|
|
if (printResponse)
|
|
|
|
{
|
|
|
|
TranslationPrintToChat(client, "Immunity Shield Not Available");
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-07 01:45:55 +01:00
|
|
|
// Check if cooldown is still in progress.
|
|
|
|
new cooldown = ClassGetImmunityCooldown(client);
|
|
|
|
new timeLeft = PlayerImmunityLastUse[client] + cooldown - GetTime();
|
|
|
|
if (timeLeft > 0)
|
|
|
|
{
|
|
|
|
if (printResponse)
|
|
|
|
{
|
|
|
|
TranslationPrintToChat(client, "Immunity Shield Cooldown", timeLeft);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-07 01:45:55 +01:00
|
|
|
// Check if a shield is already deployed.
|
|
|
|
if (PlayerImmunityTimer[client] != INVALID_HANDLE)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-07 01:45:55 +01:00
|
|
|
// Humans cannot deploy shield before first zombie.
|
2015-03-22 18:06:40 +01:00
|
|
|
if (!InfectHasZombieSpawned())
|
2013-01-07 01:45:55 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-01-07 01:45:55 +01:00
|
|
|
return true;
|
|
|
|
}
|