Skip to content

Commit

Permalink
Fix electrified wire damage being frametime-dependent
Browse files Browse the repository at this point in the history
Resolves #102
  • Loading branch information
SamVanheer committed Aug 25, 2023
1 parent df0607d commit f6917f2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Half-Life: Opposing Force Updated changelog

## Changes in V1.0.0 Release Candidate 002

> Note: this release candidate has not been released yet.
### Bug fixes

* Fixed electrified wire damage being frametime-dependent [#102](https://github.com/SamVanheer/halflife-op4-updated/issues/102) (Thanks malortie)

## Changes in V1.0.0 Release Candidate 001

### Bug fixes
Expand Down
10 changes: 9 additions & 1 deletion dlls/rope/CRopeSegment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ TYPEDESCRIPTION CRopeSegment::m_SaveData[] =
DEFINE_FIELD(CRopeSegment, m_flDefaultMass, FIELD_FLOAT),
DEFINE_FIELD(CRopeSegment, m_bCauseDamage, FIELD_BOOLEAN),
DEFINE_FIELD(CRopeSegment, m_bCanBeGrabbed, FIELD_BOOLEAN),
DEFINE_FIELD(CRopeSegment, m_LastDamageTime, FIELD_TIME),
};

LINK_ENTITY_TO_CLASS(rope_segment, CRopeSegment);
Expand Down Expand Up @@ -79,7 +80,14 @@ void CRopeSegment::Touch(CBaseEntity* pOther)
//Electrified wires deal damage. - Solokiller
if (m_bCauseDamage)
{
pOther->TakeDamage(pev, pev, 1, DMG_SHOCK);
// Like trigger_hurt we need to deal half a second's worth of damage per touch to make this frametime-independent.
if (m_LastDamageTime < gpGlobals->time)
{
// 1 damage per tick is 30 damage per second at 30 FPS.
const float damagePerHalfSecond = 30.f / 2;
pOther->TakeDamage(pev, pev, damagePerHalfSecond, DMG_SHOCK);
m_LastDamageTime = gpGlobals->time + 0.5f;
}
}

if (m_pSample->GetMasterRope()->IsAcceptingAttachment() && !pPlayer->IsOnRope())
Expand Down
1 change: 1 addition & 0 deletions dlls/rope/CRopeSegment.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,5 @@ class CRopeSegment : public CBaseAnimating
float m_flDefaultMass;
bool m_bCauseDamage;
bool m_bCanBeGrabbed;
float m_LastDamageTime{0};
};

0 comments on commit f6917f2

Please sign in to comment.