2009-04-19 19:54:21 +02:00
|
|
|
/*
|
|
|
|
* ============================================================================
|
|
|
|
*
|
2009-07-05 08:49:23 +02:00
|
|
|
* Zombie:Reloaded
|
2009-04-19 19:54:21 +02:00
|
|
|
*
|
2009-06-12 05:51:26 +02:00
|
|
|
* File: damage.inc
|
|
|
|
* Type: Core
|
|
|
|
* Description: Modify damage stuff here.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 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/>.
|
2009-04-19 19:54:21 +02:00
|
|
|
*
|
|
|
|
* ============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @endsection
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @section Suicide intercept defines.
|
|
|
|
*/
|
|
|
|
#define DAMAGE_SUICIDE_MAX_CMDS 5
|
|
|
|
#define DAMAGE_SUICIDE_MAX_LENGTH 16
|
|
|
|
/**
|
|
|
|
* @endsection
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2009-05-14 02:28:26 +02:00
|
|
|
* Array to store TraceAttack HookIDs.
|
2009-04-19 19:54:21 +02:00
|
|
|
*/
|
2009-05-14 02:28:26 +02:00
|
|
|
new g_iDamageTraceAttackHookID[MAXPLAYERS + 1] = {-1, ...};
|
2009-04-19 19:54:21 +02:00
|
|
|
|
2009-05-14 02:28:26 +02:00
|
|
|
/**
|
|
|
|
* Array to store OnTakeDamage HookIDs.
|
|
|
|
*/
|
|
|
|
new g_iDamageOnTakeDamageHookID[MAXPLAYERS + 1] = {-1, ...};
|
2009-04-19 19:54:21 +02:00
|
|
|
|
2009-06-26 04:38:03 +02:00
|
|
|
/**
|
|
|
|
* Array to keep track of normal/mother zombies.
|
|
|
|
*/
|
|
|
|
new bool:g_bDamageMotherZombie[MAXPLAYERS + 1];
|
|
|
|
|
2009-04-19 19:54:21 +02:00
|
|
|
/**
|
2009-05-14 02:28:26 +02:00
|
|
|
* Hook commands related to damage here.
|
2009-04-19 19:54:21 +02:00
|
|
|
*/
|
2009-05-14 02:28:26 +02:00
|
|
|
DamageOnCommandsHook()
|
2009-04-19 19:54:21 +02:00
|
|
|
{
|
|
|
|
// Create command callbacks (intercepts) for listed suicide commands.
|
2009-05-14 02:28:26 +02:00
|
|
|
decl String:suicidecmds[DAMAGE_SUICIDE_MAX_CMDS * DAMAGE_SUICIDE_MAX_LENGTH];
|
2009-04-20 02:56:26 +02:00
|
|
|
GetConVarString(g_hCvarsList[CVAR_DAMAGE_SUICIDE_CMDS], suicidecmds, sizeof(suicidecmds));
|
2009-04-19 19:54:21 +02:00
|
|
|
|
|
|
|
// Create array to store cmds
|
|
|
|
new String:arrayCmds[DAMAGE_SUICIDE_MAX_CMDS][DAMAGE_SUICIDE_MAX_LENGTH];
|
|
|
|
|
|
|
|
// Explode string into array indexes.
|
2009-07-24 00:05:14 +02:00
|
|
|
new cmdcount = ExplodeString(suicidecmds, ",", arrayCmds, sizeof(arrayCmds), sizeof(arrayCmds[]));
|
2009-04-19 19:54:21 +02:00
|
|
|
|
2009-05-29 08:43:15 +02:00
|
|
|
// x = Array index.
|
2009-04-19 19:54:21 +02:00
|
|
|
// arrayCmds[x] = suicide command.
|
|
|
|
for (new x = 0; x <= cmdcount - 1; x++)
|
|
|
|
{
|
2009-07-24 00:05:14 +02:00
|
|
|
// Trim whitespace.
|
|
|
|
TrimString(arrayCmds[x]);
|
|
|
|
|
2009-04-19 19:54:21 +02:00
|
|
|
// Prepare intercept for this command.
|
|
|
|
RegConsoleCmd(arrayCmds[x], DamageSuicideIntercept);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Client is joining the server.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
2009-04-22 04:53:19 +02:00
|
|
|
*/
|
2009-04-19 19:54:21 +02:00
|
|
|
DamageClientInit(client)
|
|
|
|
{
|
2009-04-21 01:45:49 +02:00
|
|
|
// Hook damage callbacks.
|
2009-05-14 02:28:26 +02:00
|
|
|
g_iDamageTraceAttackHookID[client] = ZRTools_HookTraceAttack(client, DamageTraceAttack);
|
|
|
|
g_iDamageOnTakeDamageHookID[client] = ZRTools_HookOnTakeDamage(client, DamageOnTakeDamage);
|
2009-04-19 19:54:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Client is leaving the server.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
*/
|
|
|
|
DamageOnClientDisconnect(client)
|
|
|
|
{
|
2009-05-14 02:28:26 +02:00
|
|
|
// Unhook damage callbacks, and reset variables.
|
|
|
|
|
|
|
|
if (g_iDamageTraceAttackHookID[client] != -1)
|
|
|
|
{
|
|
|
|
ZRTools_UnhookTraceAttack(g_iDamageTraceAttackHookID[client]);
|
|
|
|
g_iDamageTraceAttackHookID[client] = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_iDamageOnTakeDamageHookID[client] != -1)
|
|
|
|
{
|
|
|
|
ZRTools_UnhookOnTakeDamage(g_iDamageOnTakeDamageHookID[client]);
|
|
|
|
g_iDamageOnTakeDamageHookID[client] = -1;
|
|
|
|
}
|
2009-04-19 19:54:21 +02:00
|
|
|
}
|
|
|
|
|
2009-06-26 04:38:03 +02:00
|
|
|
/**
|
|
|
|
* A client was infected.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
* @param motherinfect True if the zombie is mother, false if not.
|
|
|
|
*/
|
|
|
|
DamageOnClientInfected(client, bool:motherinfect)
|
|
|
|
{
|
|
|
|
// Update if client is a mother zombie or not.
|
|
|
|
g_bDamageMotherZombie[client] = motherinfect;
|
|
|
|
}
|
|
|
|
|
2009-04-19 19:54:21 +02:00
|
|
|
/**
|
|
|
|
* Hook: TraceAttack
|
|
|
|
* Called right before the bullet enters a client.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
2009-05-11 04:47:09 +02:00
|
|
|
* @param inflictor The entity index of the inflictor.
|
|
|
|
* @param attacker The client index of the attacker.
|
|
|
|
* @param damage The amount of damage inflicted.
|
2009-04-19 19:54:21 +02:00
|
|
|
* @param hitbox The hitbox index.
|
2009-05-11 04:47:09 +02:00
|
|
|
* @param hitgroup The hitgroup index.
|
|
|
|
* @return Return ZRTools_Handled to stop bullet from hitting client.
|
|
|
|
* ZRTools_Continue to allow bullet to hit client.
|
2009-04-19 19:54:21 +02:00
|
|
|
*/
|
2009-05-11 04:47:09 +02:00
|
|
|
public ZRTools_Action:DamageTraceAttack(client, inflictor, attacker, Float:damage, hitbox, hitgroup)
|
2009-04-19 19:54:21 +02:00
|
|
|
{
|
|
|
|
// If attacker isn't valid, then stop.
|
2009-04-24 05:02:19 +02:00
|
|
|
if (!ZRIsClientValid(attacker))
|
|
|
|
{
|
2009-05-11 04:47:09 +02:00
|
|
|
return ZRTools_Continue;
|
2009-04-24 05:02:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// If client is attacking himself, then stop.
|
|
|
|
if(attacker == client)
|
2009-04-19 19:54:21 +02:00
|
|
|
{
|
2009-05-11 04:47:09 +02:00
|
|
|
return ZRTools_Continue;
|
2009-04-19 19:54:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get zombie flag for each client.
|
2009-04-24 05:02:19 +02:00
|
|
|
new bool:clientzombie = InfectIsClientInfected(client);
|
|
|
|
new bool:attackerzombie = InfectIsClientInfected(attacker);
|
2009-04-19 19:54:21 +02:00
|
|
|
|
|
|
|
// If the flags are the same on both clients, then stop.
|
|
|
|
if (clientzombie == attackerzombie)
|
|
|
|
{
|
2009-04-23 06:39:11 +02:00
|
|
|
// If friendly fire is blocked, then allow damage.
|
|
|
|
new bool:damageblockff = GetConVarBool(g_hCvarsList[CVAR_DAMAGE_BLOCK_FF]);
|
|
|
|
if (!damageblockff)
|
|
|
|
{
|
2009-05-11 04:47:09 +02:00
|
|
|
return ZRTools_Continue;
|
2009-04-23 06:39:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Stop bullet from hurting client.
|
2009-05-11 04:47:09 +02:00
|
|
|
return ZRTools_Handled;
|
2009-04-19 19:54:21 +02:00
|
|
|
}
|
|
|
|
|
2009-04-23 06:39:11 +02:00
|
|
|
// Here we know that attacker and client are different teams.
|
|
|
|
|
2009-06-26 09:00:05 +02:00
|
|
|
// If client is a human, then allow damage.
|
|
|
|
if (InfectIsClientHuman(client))
|
|
|
|
{
|
|
|
|
// Allow damage.
|
|
|
|
return ZRTools_Continue;
|
|
|
|
}
|
|
|
|
|
2009-04-23 06:39:11 +02:00
|
|
|
// If damage hitgroups cvar is disabled, then allow damage.
|
|
|
|
new bool:damagehitgroups = GetConVarBool(g_hCvarsList[CVAR_DAMAGE_HITGROUPS]);
|
|
|
|
if (!damagehitgroups)
|
|
|
|
{
|
|
|
|
// Allow damage.
|
2009-05-11 04:47:09 +02:00
|
|
|
return ZRTools_Continue;
|
2009-04-23 06:39:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// If damage is disabled for this hitgroup, then stop.
|
2009-05-29 08:43:15 +02:00
|
|
|
new index = HitgroupToIndex(hitgroup);
|
|
|
|
|
|
|
|
// If index can't be found, then allow damage.
|
|
|
|
if (index == -1)
|
|
|
|
{
|
|
|
|
// Allow damage.
|
|
|
|
return ZRTools_Continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
new bool:candamage = HitgroupsCanDamage(index);
|
2009-04-23 06:39:11 +02:00
|
|
|
if (!candamage)
|
|
|
|
{
|
|
|
|
// Stop bullet from hurting client.
|
2009-05-11 04:47:09 +02:00
|
|
|
return ZRTools_Handled;
|
2009-04-23 06:39:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Allow damage.
|
2009-05-11 04:47:09 +02:00
|
|
|
return ZRTools_Continue;
|
2009-04-19 19:54:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hook: OnTakeDamage
|
|
|
|
* Called right before damage is done.
|
2009-05-11 04:47:09 +02:00
|
|
|
*
|
2009-04-19 19:54:21 +02:00
|
|
|
* @param client The client index.
|
2009-05-11 04:47:09 +02:00
|
|
|
* @param inflictor The entity index of the inflictor.
|
|
|
|
* @param attacker The client index of the attacker.
|
|
|
|
* @param damage The amount of damage inflicted.
|
|
|
|
* @param damagetype The type of damage inflicted.
|
|
|
|
* @param ammotype The ammo type of the attacker's weapon.
|
|
|
|
* @return Return ZRTools_Handled to stop the damage to client.
|
|
|
|
* ZRTools_Continue to allow damage to client.
|
2009-04-19 19:54:21 +02:00
|
|
|
*/
|
2009-05-11 04:47:09 +02:00
|
|
|
public ZRTools_Action:DamageOnTakeDamage(client, inflictor, attacker, Float:damage, damagetype, ammotype)
|
2009-04-19 19:54:21 +02:00
|
|
|
{
|
|
|
|
// Get classname of the inflictor.
|
|
|
|
decl String:classname[64];
|
|
|
|
GetEdictClassname(inflictor, classname, sizeof(classname));
|
|
|
|
|
|
|
|
// If entity is a trigger, then allow damage. (Map is damaging client)
|
|
|
|
if (StrContains(classname, "trigger") > -1)
|
|
|
|
{
|
2009-05-11 04:47:09 +02:00
|
|
|
return ZRTools_Continue;
|
2009-04-19 19:54:21 +02:00
|
|
|
}
|
|
|
|
|
2009-07-17 03:34:56 +02:00
|
|
|
new action;
|
|
|
|
|
|
|
|
// Forward this hook to another module an return (or not) what it wants.
|
|
|
|
action = NapalmOnTakeDamage(client, damagetype);
|
|
|
|
|
|
|
|
// If the napalm module wants to return here, then return the int casted into the ZRTools_Action type.
|
|
|
|
if (action > -1)
|
|
|
|
{
|
|
|
|
return ZRTools_Action:action;
|
|
|
|
}
|
|
|
|
|
2009-04-23 06:39:11 +02:00
|
|
|
// Client was shot or knifed.
|
2009-05-11 04:47:09 +02:00
|
|
|
if (damagetype & DMG_CSS_BULLET)
|
2009-04-21 01:45:49 +02:00
|
|
|
{
|
2009-04-23 06:39:11 +02:00
|
|
|
// If attacker isn't valid, then allow damage.
|
2009-04-24 05:02:19 +02:00
|
|
|
if (!ZRIsClientValid(attacker))
|
2009-04-21 01:45:49 +02:00
|
|
|
{
|
2009-05-11 04:47:09 +02:00
|
|
|
return ZRTools_Continue;
|
2009-04-21 01:45:49 +02:00
|
|
|
}
|
|
|
|
|
2009-04-23 06:39:11 +02:00
|
|
|
// Get zombie flag for each client.
|
2009-04-24 05:02:19 +02:00
|
|
|
new bool:clientzombie = InfectIsClientInfected(client);
|
|
|
|
new bool:attackerzombie = InfectIsClientInfected(attacker);
|
2009-04-23 06:39:11 +02:00
|
|
|
|
|
|
|
// If client and attacker are on the same team, then let CS:S handle the rest.
|
|
|
|
if (clientzombie == attackerzombie)
|
2009-04-21 01:45:49 +02:00
|
|
|
{
|
2009-05-11 04:47:09 +02:00
|
|
|
return ZRTools_Continue;
|
2009-04-21 01:45:49 +02:00
|
|
|
}
|
|
|
|
|
2009-04-23 06:39:11 +02:00
|
|
|
// We know that clientzombie is the opposite of attacker zombie.
|
|
|
|
|
|
|
|
// If the client is a zombie, then allow damage.
|
|
|
|
if (clientzombie)
|
|
|
|
{
|
2009-05-11 04:47:09 +02:00
|
|
|
return ZRTools_Continue;
|
2009-04-23 06:39:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Client is about to be infected, re-add HP so they aren't killed by knife.
|
|
|
|
new health = GetClientHealth(client);
|
2009-05-11 04:47:09 +02:00
|
|
|
SetEntityHealth(client, health + RoundToNearest(damage));
|
2009-04-23 06:39:11 +02:00
|
|
|
|
|
|
|
// Allow damage.
|
2009-05-11 04:47:09 +02:00
|
|
|
return ZRTools_Continue;
|
2009-04-21 01:45:49 +02:00
|
|
|
}
|
|
|
|
// Client was damaged by explosion.
|
2009-05-11 04:47:09 +02:00
|
|
|
else if (damagetype & DMG_CSS_BLAST)
|
2009-04-21 01:45:49 +02:00
|
|
|
{
|
2009-04-23 06:39:11 +02:00
|
|
|
// If blast damage is blocked, then stop.
|
|
|
|
new bool:damageblockblast = GetConVarBool(g_hCvarsList[CVAR_DAMAGE_BLOCK_BLAST]);
|
|
|
|
if (!damageblockblast)
|
|
|
|
{
|
2009-05-11 04:47:09 +02:00
|
|
|
return ZRTools_Continue;
|
2009-04-23 06:39:11 +02:00
|
|
|
}
|
|
|
|
|
2009-04-21 01:45:49 +02:00
|
|
|
// If attacker isn't valid, then allow damage.
|
2009-04-24 05:02:19 +02:00
|
|
|
if (!ZRIsClientValid(attacker))
|
2009-04-21 01:45:49 +02:00
|
|
|
{
|
2009-05-11 04:47:09 +02:00
|
|
|
return ZRTools_Continue;
|
2009-04-21 01:45:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// If client is a zombie, then allow damage.
|
2009-04-24 05:02:19 +02:00
|
|
|
if (InfectIsClientInfected(client))
|
2009-04-21 01:45:49 +02:00
|
|
|
{
|
2009-05-11 04:47:09 +02:00
|
|
|
return ZRTools_Continue;
|
2009-04-21 01:45:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Stop damage.
|
2009-05-11 04:47:09 +02:00
|
|
|
return ZRTools_Handled;
|
2009-04-21 01:45:49 +02:00
|
|
|
}
|
2009-04-23 06:39:11 +02:00
|
|
|
// Client was damaged by falling.
|
2009-05-11 04:47:09 +02:00
|
|
|
else if (damagetype & DMG_CSS_FALL)
|
2009-04-19 19:54:21 +02:00
|
|
|
{
|
2009-04-23 06:39:11 +02:00
|
|
|
// If class has "nofalldamage" disabled, then allow damage.
|
|
|
|
new bool:blockfalldamage = ClassGetNoFallDamage(client);
|
|
|
|
if (!blockfalldamage)
|
2009-04-19 19:54:21 +02:00
|
|
|
{
|
2009-05-11 04:47:09 +02:00
|
|
|
return ZRTools_Continue;
|
2009-04-19 19:54:21 +02:00
|
|
|
}
|
2009-04-21 01:45:49 +02:00
|
|
|
|
2009-04-23 06:39:11 +02:00
|
|
|
// Stop damage.
|
2009-05-11 04:47:09 +02:00
|
|
|
return ZRTools_Handled;
|
2009-04-19 19:54:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Allow damage.
|
2009-05-11 04:47:09 +02:00
|
|
|
return ZRTools_Continue;
|
2009-04-19 19:54:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Command callback (kill, jointeam, spectate)
|
|
|
|
* Block command if plugin thinks they are trying to commit suicide.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
* @param argc The number of arguments in command string.
|
|
|
|
*/
|
|
|
|
public Action:DamageSuicideIntercept(client, argc)
|
|
|
|
{
|
|
|
|
// If zombie hasn't spawned, then stop.
|
|
|
|
if (!g_bZombieSpawned)
|
|
|
|
{
|
|
|
|
return Plugin_Continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If client is invalid, then stop. (Stop console.)
|
2009-04-24 05:02:19 +02:00
|
|
|
if (!ZRIsClientValid(client))
|
2009-04-19 19:54:21 +02:00
|
|
|
{
|
|
|
|
return Plugin_Continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If client is dead, then stop.
|
|
|
|
if (!IsPlayerAlive(client))
|
|
|
|
{
|
|
|
|
return Plugin_Continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get cvar values for suicide interception.
|
2009-04-20 02:56:26 +02:00
|
|
|
new bool:suicidezombie = GetConVarBool(g_hCvarsList[CVAR_DAMAGE_SUICIDE_ZOMBIE]);
|
2009-06-26 04:38:03 +02:00
|
|
|
new bool:suicidezombiemother = GetConVarBool(g_hCvarsList[CVAR_DAMAGE_SUICIDE_MZOMBIE]);
|
2009-04-20 02:56:26 +02:00
|
|
|
new bool:suicidehuman = GetConVarBool(g_hCvarsList[CVAR_DAMAGE_SUICIDE_HUMAN]);
|
2009-04-19 19:54:21 +02:00
|
|
|
|
2009-06-26 04:38:03 +02:00
|
|
|
// Check if client is a zombie.
|
|
|
|
if (InfectIsClientInfected(client))
|
|
|
|
{
|
|
|
|
// If client is a normal zombie, and suicide intercept is disabled for zombies, then let command go.
|
|
|
|
if (!g_bDamageMotherZombie[client] && !suicidezombie)
|
|
|
|
{
|
|
|
|
return Plugin_Continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If client is a mother zombie, and suicide intercept is disabled for mother zombies, then let command go.
|
|
|
|
if (g_bDamageMotherZombie[client] && !suicidezombiemother)
|
|
|
|
{
|
|
|
|
return Plugin_Continue;
|
|
|
|
}
|
|
|
|
}
|
2009-04-19 19:54:21 +02:00
|
|
|
|
2009-06-26 04:38:03 +02:00
|
|
|
// If client is a human, and suicide intercept is disabled for humans, then let command go.
|
|
|
|
if (InfectIsClientHuman(client) && !suicidehuman)
|
2009-04-19 19:54:21 +02:00
|
|
|
{
|
|
|
|
return Plugin_Continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tell client their command has been intercepted.
|
2009-05-14 09:32:01 +02:00
|
|
|
TranslationReplyToCommand(client, "Damage suicide intercept");
|
2009-04-19 19:54:21 +02:00
|
|
|
|
2009-05-14 09:32:01 +02:00
|
|
|
// Log suicide interception
|
2009-06-01 23:29:26 +02:00
|
|
|
LogEvent(false, LogType_Normal, LOG_GAME_EVENTS, LogModule_Damage, "Suicide Intercept", "Player \"%L\" attempted suicide.", client);
|
2009-04-19 19:54:21 +02:00
|
|
|
|
|
|
|
// Block command.
|
|
|
|
return Plugin_Handled;
|
2009-05-01 11:22:45 +02:00
|
|
|
}
|