2009-04-19 19:54:21 +02:00
|
|
|
/*
|
|
|
|
* ============================================================================
|
|
|
|
*
|
|
|
|
* Zombie:Reloaded
|
|
|
|
*
|
2009-05-06 02:28:09 +02:00
|
|
|
* File: damage.inc
|
|
|
|
* Type: Core
|
|
|
|
* Description: Modify damage stuff here.
|
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-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.
|
|
|
|
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-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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
new bool:candamage = HitgroupsCanDamageHitgroup(hitgroup);
|
|
|
|
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-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 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-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
|
|
|
// 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)
|
|
|
|
{
|
|
|
|
// 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
|
|
|
}
|