Skip to content

Commit b34e802

Browse files
authored
Add a fallback for breakable hittables (#959)
* Add a fallback for breakable hittables Fix: - Hittable pieces will now make a new entry if the breakable parent doesn't have one, to resolve potential overhit issues. * Fallback to classname check and remove `OnEntityDestroyed` Change: - Added back the classname check in `OnTakeDamage`, and remove unnecessary resetting in `OnEntityDestroyed`. - Minor debug message changes.
1 parent 9669960 commit b34e802

2 files changed

Lines changed: 17 additions & 13 deletions

File tree

38 Bytes
Binary file not shown.

addons/sourcemod/scripting/l4d2_hittable_control.sp

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public Plugin myinfo =
140140
{
141141
name = "L4D2 Hittable Control",
142142
author = "Stabby, Visor, Sir, Derpduck, Forgetest",
143-
version = "0.9.1",
143+
version = "0.9.2",
144144
description = "Allows for customisation of hittable damage values (and debugging)"
145145
};
146146

@@ -360,19 +360,20 @@ public void OnEntityCreated(int entity, const char[] classname)
360360
}
361361
}
362362

363-
public void OnEntityDestroyed(int entity)
364-
{
365-
if (entity > 0 && entity < MAX_EDICTS)
366-
{
367-
g_nPhysicsHitInfoEntry[entity] = -1;
368-
}
369-
}
370-
371363
void Physics_OnSpawnPost(int entity)
372364
{
365+
g_nPhysicsHitInfoEntry[entity] = -1;
366+
373367
int parent = GetEntPropEnt(entity, Prop_Send, "m_hOwnerEntity");
374368
if (parent != -1)
375369
{
370+
// In case the breakable parent was forced to
371+
if (g_nPhysicsHitInfoEntry[parent] == -1)
372+
{
373+
g_nPhysicsHitInfoEntry[parent] = NewPhysicsHitInfo();
374+
DebugMsg("Physics_OnSpawnPost (missing info from breakable parent#%d) [#%d]", parent, g_nPhysicsHitInfoEntry[parent]);
375+
}
376+
376377
g_nPhysicsHitInfoEntry[entity] = g_nPhysicsHitInfoEntry[parent];
377378
}
378379
g_iPhysicsDamage[entity] = -1;
@@ -394,10 +395,10 @@ Action Physics_OnTakeDamage(int victim, int &attacker, int &inflictor, float &da
394395
if (!IsValidEdict(attacker))
395396
return Plugin_Continue;
396397

397-
DebugMsg("(#%d) Physics_OnTakeDamage (attacker %d)", victim, attacker);
398-
399398
if (attacker > 0 && attacker <= MaxClients && IsTank(attacker))
400399
{
400+
DebugMsg("(#%d) Physics_OnTakeDamage tank (%N #%d)", victim, attacker, attacker);
401+
401402
// A tank punches me, create a new entry if not
402403
if (g_nPhysicsHitInfoEntry[victim] == -1)
403404
{
@@ -416,6 +417,8 @@ Action Physics_OnTakeDamage(int victim, int &attacker, int &inflictor, float &da
416417
}
417418
else if (IsEntityClassname(attacker, "prop_physics*"))
418419
{
420+
DebugMsg("(#%d) Physics_OnTakeDamage prop_physics (#%d)", victim, attacker);
421+
419422
// Collides with other physics, clone their hit info
420423
if (g_nPhysicsHitInfoEntry[attacker] != -1)
421424
{
@@ -438,7 +441,7 @@ Action Physics_OnTakeDamage(int victim, int &attacker, int &inflictor, float &da
438441
selfinfo.lastAttackerTime = GetGameTime();
439442

440443
g_PhysicsHitInfos.SetArray(g_nPhysicsHitInfoEntry[victim], selfinfo);
441-
DebugMsg("(#%d) Physics_OnTakeDamage prop_physics (#%d) [%d]", victim, g_nPhysicsHitInfoEntry[attacker], selfinfo.lastAttackerId);
444+
DebugMsg("(#%d) Physics_OnTakeDamage prop_physics (#%d) [lastAttackerId %d]", victim, g_nPhysicsHitInfoEntry[attacker], selfinfo.lastAttackerId);
442445
}
443446
}
444447
else
@@ -597,7 +600,8 @@ Action OnTakeDamage(int victim, int &attacker, int &inflictor, float &damage, in
597600
// Hey, we don't care.
598601
if (!IsValidEdict(attacker)
599602
|| !IsValidEdict(inflictor)
600-
|| g_nPhysicsHitInfoEntry[inflictor] == -1)
603+
|| g_nPhysicsHitInfoEntry[inflictor] == -1
604+
|| !IsEntityClassname(inflictor, "prop_physics*"))
601605
return Plugin_Continue;
602606

603607
if (IsTank(victim) && hTankSelfDamage.BoolValue)

0 commit comments

Comments
 (0)