forked from SirPlease/L4D2-Competitive-Rework
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'SirPlease:master' into master
- Loading branch information
Showing
2 changed files
with
90 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,94 +1,114 @@ | ||
#pragma semicolon 1 | ||
#pragma newdecls required | ||
|
||
#include <sourcemod> | ||
#include <sdkhooks> | ||
|
||
#define TEAM_SURVIVOR 2 | ||
#define TEAM_INFECTED 3 | ||
#define ZC_CHARGER 6 | ||
#define CHARGER_DMG_POUND 15.0 | ||
#define DEBUG 0 | ||
|
||
bool bLateLoad; | ||
ConVar hDmgIncappedPound; | ||
#define TEAM_SURVIVOR 2 | ||
#define TEAM_ZOMBIE 3 | ||
|
||
public Plugin myinfo = | ||
{ | ||
name = "Incapped Charger Damage", | ||
author = "Sir", | ||
description = "Modify Charger pummel damage done to Survivors", | ||
version = "1.0", | ||
url = "https://github.com/SirPlease/L4D2-Competitive-Rework" | ||
} | ||
#define ZC_CHARGER 6 | ||
|
||
/* ------------------------------- | ||
* Init | ||
* ------------------------------- */ | ||
bool | ||
g_bLateLoad = false; | ||
|
||
public APLRes AskPluginLoad2(Handle plugin, bool late, char[] error, int errMax) | ||
ConVar | ||
g_hCvarZChargerPoundDmg = null, | ||
g_hCvarDmgIncappedPound = null; | ||
|
||
public Plugin myinfo = | ||
{ | ||
name = "Incapped Charger Damage", | ||
author = "Sir, A1m`", | ||
description = "Modify Charger pummel damage done to Survivors", | ||
version = "2.1.0", | ||
url = "https://github.com/SirPlease/L4D2-Competitive-Rework" | ||
}; | ||
|
||
public APLRes AskPluginLoad2(Handle hMyself, bool bLate, char[] sError, int iErrMax) | ||
{ | ||
bLateLoad = late; | ||
return APLRes_Success; | ||
g_bLateLoad = bLate; | ||
return APLRes_Success; | ||
} | ||
|
||
public void OnPluginStart() | ||
{ | ||
// hook already existing clients if loading late | ||
if (bLateLoad) { | ||
for (int i = 1; i < MaxClients+1; i++) { | ||
if (IsClientInGame(i)) { | ||
SDKHook(i, SDKHook_OnTakeDamage, OnTakeDamage); | ||
} | ||
} | ||
} | ||
hDmgIncappedPound = CreateConVar("charger_dmg_incapped", "15.0", "Pound Damage dealt to incapped Survivors."); | ||
} | ||
|
||
g_hCvarDmgIncappedPound = CreateConVar("charger_dmg_incapped", "-1.0", "Pound Damage dealt to incapped Survivors."); | ||
|
||
/* ------------------------------- | ||
* General hooks / events | ||
* ------------------------------- */ | ||
g_hCvarZChargerPoundDmg = FindConVar("z_charger_pound_dmg"); | ||
|
||
LateLoadPlugin(); | ||
} | ||
|
||
public void OnClientPostAdminCheck(int client) | ||
void LateLoadPlugin() | ||
{ | ||
SDKHook(client, SDKHook_OnTakeDamage, OnTakeDamage); | ||
// hook already existing clients if loading late | ||
if (!g_bLateLoad) { | ||
return; | ||
} | ||
|
||
for (int i = 1; i <= MaxClients; i++) { | ||
if (!IsClientInGame(i)) { | ||
continue; | ||
} | ||
|
||
OnClientPutInServer(i); | ||
} | ||
} | ||
|
||
/* -------------------------------------- | ||
* GOT MY EYES ON YOU, DAMAGE | ||
* -------------------------------------- */ | ||
|
||
Action OnTakeDamage(int victim, int &attacker, int &inflictor, float &damage, int &damagetype, int &weapon, float damageForce[3], float damagePosition[3]) | ||
public void OnClientPutInServer(int iClient) | ||
{ | ||
if (!inflictor || !attacker || !victim || !IsValidEdict(victim) || !IsValidEdict(inflictor)) { return Plugin_Continue; } | ||
|
||
// only check player-to-player damage | ||
if (!IsClientAndInGame(attacker) || !IsClientAndInGame(victim)) { return Plugin_Continue; } | ||
|
||
// check teams | ||
if (GetClientTeam(attacker) != TEAM_INFECTED || GetClientTeam(victim) != TEAM_SURVIVOR) { return Plugin_Continue; } | ||
|
||
// only allow chargers | ||
if (GetEntProp(attacker, Prop_Send, "m_zombieClass") != ZC_CHARGER) { return Plugin_Continue; } | ||
|
||
if (damage == CHARGER_DMG_POUND && (damageForce[0] == 0.0 && damageForce[1] == 0.0 && damageForce[2] == 0.0)) | ||
{ | ||
// POUND | ||
damage = IsIncapped(victim) ? GetConVarFloat(hDmgIncappedPound) : damage; | ||
return Plugin_Changed; | ||
} | ||
return Plugin_Continue; | ||
SDKHook(iClient, SDKHook_OnTakeDamage, Hook_OnTakeDamage); | ||
} | ||
|
||
/* -------------------------------------- | ||
* Shared function(s) | ||
* -------------------------------------- */ | ||
|
||
bool IsClientAndInGame(int index) | ||
/* @A1m`: | ||
Pound damage: | ||
- damageForce = 0 0 0 | ||
- Damage equal to convar 'z_charger_pound_dmg', def 15 | ||
- Game function: CTerrorPlayer::HandleAnimEvent | ||
[Hook_OnTakeDamage] Victim: Ellis (4), attacker: A1m` (2), inflictor: player (2), damage: 15.000000, damagetype: 128 | ||
weapon: None (-1), damageForce: 0.000000 0.000000 0.000000, damagePosition: 0.000000 0.000000 0.000000 | ||
m_carryVictim: -1, m_pummelVictim: 4, m_isCharging: 0 | ||
*/ | ||
Action Hook_OnTakeDamage(int iVictim, int &iAttacker, int &iInflictor, float &fDamage, int &iDamagetype, \ | ||
int &iWeapon, float fDamageForce[3], float fDamagePosition[3]) | ||
{ | ||
return (index > 0 && index <= MaxClients && IsClientInGame(index)); | ||
if (iDamagetype != DMG_CLUB | ||
|| fDamage != g_hCvarZChargerPoundDmg.FloatValue | ||
|| g_hCvarDmgIncappedPound.FloatValue <= 0.0 | ||
) { | ||
return Plugin_Continue; | ||
} | ||
|
||
if (GetClientTeam(iVictim) != TEAM_SURVIVOR | ||
|| GetEntProp(iVictim, Prop_Send, "m_isIncapacitated", 1) < 1 | ||
) { | ||
return Plugin_Continue; | ||
} | ||
|
||
if (iAttacker < 1 || iAttacker > MaxClients | ||
|| GetClientTeam(iAttacker) != TEAM_ZOMBIE | ||
|| GetEntProp(iAttacker, Prop_Send, "m_zombieClass") != ZC_CHARGER | ||
) { | ||
return Plugin_Continue; | ||
} | ||
|
||
int iPummelVictim = GetEntPropEnt(iAttacker, Prop_Send, "m_pummelVictim"); | ||
if (iPummelVictim != iVictim) { | ||
return Plugin_Continue; | ||
} | ||
|
||
#if DEBUG | ||
PrintToChatAll("[Hook_OnTakeDamage] Victim: (%N) %d, attacker: (%N) %d, inflictor: %d, damage: %f, damagetype: %d ", \ | ||
iVictim, iVictim, iAttacker, iAttacker, iInflictor, fDamage, iDamagetype); | ||
PrintToChatAll("[Hook_OnTakeDamage] Weapon: %d, damageforce: %f %f %f, damageposition: %f %f %f", \ | ||
iWeapon, fDamageForce[0], fDamageForce[1], fDamageForce[2], fDamagePosition[0], fDamagePosition[1], fDamagePosition[2]); | ||
#endif | ||
|
||
fDamage = g_hCvarDmgIncappedPound.FloatValue; | ||
return Plugin_Changed; | ||
} | ||
|
||
bool IsIncapped(int client) | ||
{ | ||
return view_as<bool>(GetEntProp(client, Prop_Send, "m_isIncapacitated")); | ||
} |