2009-04-19 19:54:21 +02:00
|
|
|
/*
|
|
|
|
* ============================================================================
|
|
|
|
*
|
|
|
|
* Zombie:Reloaded
|
|
|
|
*
|
|
|
|
* File: damage.inc
|
|
|
|
* Description: (Core) Modify damage stuff here.
|
|
|
|
*
|
|
|
|
* ============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @section Damage type flags.
|
|
|
|
*/
|
2009-04-21 01:45:49 +02:00
|
|
|
#define DMG_FALL (1 << 5) /** Client was damaged by falling. */
|
|
|
|
#define DMG_BLAST (1 << 6) /** Client was damaged by explosion. */
|
|
|
|
#define DMG_BULLET (1 << 12) /** Client was shot or knifed. */
|
|
|
|
#define DMG_HEADSHOT (1 << 30) /** Client was shot in the head. */
|
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List of damage-related hooks.
|
|
|
|
*/
|
|
|
|
enum DamageHooks
|
|
|
|
{
|
2009-04-21 01:45:49 +02:00
|
|
|
Hook_TraceAttack, /** TraceAttack HookID */
|
|
|
|
Hook_OnTakeDamage, /** OnTakeDamage HookID */
|
2009-04-19 19:54:21 +02:00
|
|
|
}
|
|
|
|
|
2009-04-29 01:58:41 +02:00
|
|
|
new g_iDamageHookID[MAXPLAYERS + 1][DamageHooks];
|
2009-04-19 19:54:21 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Damage module init function.
|
|
|
|
*/
|
|
|
|
DamageInit()
|
|
|
|
{
|
|
|
|
// Create command callbacks (intercepts) for listed suicide commands.
|
|
|
|
decl String:suicidecmds[64];
|
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.
|
|
|
|
new cmdcount = ExplodeString(suicidecmds, ", ", arrayCmds, DAMAGE_SUICIDE_MAX_CMDS, DAMAGE_SUICIDE_MAX_LENGTH);
|
|
|
|
|
|
|
|
// x = array index.
|
|
|
|
// arrayCmds[x] = suicide command.
|
|
|
|
for (new x = 0; x <= cmdcount - 1; x++)
|
|
|
|
{
|
|
|
|
// 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-04-29 01:58:41 +02:00
|
|
|
g_iDamageHookID[client][Hook_TraceAttack] = Hacks_Hook(client, HACKS_HTYPE_TRACEATTACK, DamageTraceAttack);
|
|
|
|
g_iDamageHookID[client][Hook_OnTakeDamage] = Hacks_Hook(client, HACKS_HTYPE_ONTAKEDAMAGE, DamageOnTakeDamage);
|
2009-04-19 19:54:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Client is leaving the server.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
*/
|
|
|
|
DamageOnClientDisconnect(client)
|
|
|
|
{
|
2009-04-21 01:45:49 +02:00
|
|
|
// Unhook damage callbacks.
|
2009-04-29 01:58:41 +02:00
|
|
|
Hacks_Unhook(g_iDamageHookID[client][Hook_TraceAttack]);
|
|
|
|
Hacks_Unhook(g_iDamageHookID[client][Hook_OnTakeDamage]);
|
2009-04-19 19:54:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hook: TraceAttack
|
|
|
|
* Called right before the bullet enters a client.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
* @param inflictor Entity index of damage-causing entity.
|
|
|
|
* @param attacker The client doing the damage.
|
|
|
|
* @param damage The amount of damage that will be inflicted.
|
|
|
|
* @param hitbox The hitbox index.
|
|
|
|
* @param hitgroup The hitgroup index.
|
|
|
|
* @return Hacks_Continue allows shot to be made.
|
|
|
|
* 0 stops the bullet from impacting.
|
|
|
|
*/
|
|
|
|
public DamageTraceAttack(client, inflictor, attacker, damage, hitbox, hitgroup)
|
|
|
|
{
|
|
|
|
// Disabled
|
2009-04-20 02:56:26 +02:00
|
|
|
// new bool:enabled = GetConVarBool(g_hCvarsList[CVAR_ENABLE]);
|
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))
|
|
|
|
{
|
|
|
|
return Hacks_Continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If client is attacking himself, then stop.
|
|
|
|
if(attacker == client)
|
2009-04-19 19:54:21 +02:00
|
|
|
{
|
|
|
|
return Hacks_Continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
{
|
|
|
|
return Hacks_Continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Stop bullet from hurting client.
|
2009-04-19 19:54:21 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-04-23 06:39:11 +02:00
|
|
|
// Here we know that attacker and client are different teams.
|
|
|
|
|
|
|
|
// If damage hitgroups cvar is disabled, then allow damage.
|
|
|
|
new bool:damagehitgroups = GetConVarBool(g_hCvarsList[CVAR_DAMAGE_HITGROUPS]);
|
|
|
|
if (!damagehitgroups)
|
|
|
|
{
|
|
|
|
// Allow damage.
|
|
|
|
return Hacks_Continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If damage is disabled for this hitgroup, then stop.
|
|
|
|
new bool:candamage = HitgroupsCanDamageHitgroup(hitgroup);
|
|
|
|
if (!candamage)
|
|
|
|
{
|
|
|
|
// Stop bullet from hurting client.
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allow damage.
|
2009-04-19 19:54:21 +02:00
|
|
|
return Hacks_Continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hook: OnTakeDamage
|
|
|
|
* Called right before damage is done.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
* @param inflictor Entity index of damage-causing entity.
|
|
|
|
* @param attacker The client doing the damage.
|
|
|
|
* @param damage The amount of damage that will be inflicted.
|
|
|
|
* @param damagetype The type of damage done (see damage flag defines)
|
|
|
|
* @param ammotype Type of ammo attacker shot at client.
|
|
|
|
* @return Hacks_Continue allows shot to be made.
|
|
|
|
* 0 stops the bullet from doing damage.
|
|
|
|
*/
|
|
|
|
public DamageOnTakeDamage(client, inflictor, attacker, damage, damagetype, ammotype)
|
|
|
|
{
|
|
|
|
// Disabled.
|
|
|
|
/**
|
2009-04-20 02:56:26 +02:00
|
|
|
new bool:enabled = GetConVarBool(g_hCvarsList[CVAR_ENABLE]);
|
2009-04-19 19:54:21 +02:00
|
|
|
if (!enabled)
|
|
|
|
{
|
|
|
|
return Hacks_Continue;
|
|
|
|
}*/
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
{
|
|
|
|
return Hacks_Continue;
|
|
|
|
}
|
|
|
|
|
2009-04-23 06:39:11 +02:00
|
|
|
// Client was shot or knifed.
|
|
|
|
if (damagetype & DMG_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
|
|
|
{
|
|
|
|
return Hacks_Continue;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
return Hacks_Continue;
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
return Hacks_Continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Client is about to be infected, re-add HP so they aren't killed by knife.
|
|
|
|
new health = GetClientHealth(client);
|
|
|
|
SetEntityHealth(client, health + damage);
|
|
|
|
|
|
|
|
// Allow damage.
|
|
|
|
return Hacks_Continue;
|
2009-04-21 01:45:49 +02:00
|
|
|
}
|
|
|
|
// Client was damaged by explosion.
|
|
|
|
else if (damagetype & DMG_BLAST)
|
|
|
|
{
|
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)
|
|
|
|
{
|
|
|
|
return Hacks_Continue;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
return Hacks_Continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
{
|
|
|
|
return Hacks_Continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Stop damage.
|
|
|
|
return 0;
|
|
|
|
}
|
2009-04-23 06:39:11 +02:00
|
|
|
// Client was damaged by falling.
|
|
|
|
else if (damagetype & DMG_FALL)
|
2009-04-19 19:54:21 +02:00
|
|
|
{
|
2009-04-23 06:39:11 +02:00
|
|
|
// If client isn't a zombie, then allow damage.
|
2009-04-24 05:02:19 +02:00
|
|
|
if (!InfectIsClientInfected(client))
|
2009-04-19 19:54:21 +02:00
|
|
|
{
|
2009-04-21 01:45:49 +02:00
|
|
|
return Hacks_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
|
|
|
// If class has "nofalldamage" disabled, then allow damage.
|
|
|
|
new bool:blockfalldamage = ClassGetNoFallDamage(client);
|
|
|
|
if (!blockfalldamage)
|
2009-04-19 19:54:21 +02:00
|
|
|
{
|
|
|
|
return Hacks_Continue;
|
|
|
|
}
|
2009-04-21 01:45:49 +02:00
|
|
|
|
2009-04-23 06:39:11 +02:00
|
|
|
// Stop damage.
|
|
|
|
return 0;
|
2009-04-19 19:54:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Allow damage.
|
|
|
|
return Hacks_Continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
|
|
|
// Disabled.
|
|
|
|
/**
|
2009-04-20 02:56:26 +02:00
|
|
|
new bool:enabled = GetConVarBool(g_hCvarsList[CVAR_ENABLE]);
|
2009-04-19 19:54:21 +02:00
|
|
|
if (!enabled)
|
|
|
|
{
|
|
|
|
return Plugin_Continue;
|
|
|
|
}*/
|
|
|
|
|
|
|
|
// 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 zombie flag on client.
|
2009-04-24 05:02:19 +02:00
|
|
|
new bool:clientzombie = InfectIsClientInfected(client);
|
2009-04-19 19:54:21 +02:00
|
|
|
|
|
|
|
// Get cvar values for suicide interception.
|
2009-04-20 02:56:26 +02:00
|
|
|
new bool:suicidezombie = GetConVarBool(g_hCvarsList[CVAR_DAMAGE_SUICIDE_ZOMBIE]);
|
|
|
|
new bool:suicidehuman = GetConVarBool(g_hCvarsList[CVAR_DAMAGE_SUICIDE_HUMAN]);
|
2009-04-19 19:54:21 +02:00
|
|
|
|
|
|
|
// Determine whether to block suicide based off of the client's zombie flag and cvar values.
|
|
|
|
new bool:blocksuicide = clientzombie ? suicidezombie : suicidehuman;
|
|
|
|
|
|
|
|
// If cvar for this team is disabled, then stop.
|
|
|
|
if (!blocksuicide)
|
|
|
|
{
|
|
|
|
return Plugin_Continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tell client their command has been intercepted.
|
|
|
|
ZR_ReplyToCommand(client, "Damage suicide intercept");
|
|
|
|
|
|
|
|
// Log attempt.
|
2009-04-20 05:43:20 +02:00
|
|
|
if (LogCheckFlag(LOG_GAME_EVENTS, LOG_MODULE_DAMAGE))
|
2009-04-19 19:54:21 +02:00
|
|
|
{
|
2009-04-20 05:43:20 +02:00
|
|
|
LogMessageFormatted(client, "Damage", "Suicide Intercept", "Player %N attempted suicide.", LOG_FORMAT_TYPE_FULL, client);
|
2009-04-19 19:54:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Block command.
|
|
|
|
return Plugin_Handled;
|
2009-05-01 11:22:45 +02:00
|
|
|
}
|