VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
VoltMod::Damage Class Reference

Every entity's damage, from CBaseEntity::TakeDamageOld, and a way to deal it. More...

#include <Damage.hpp>

Public Member Functions

 Damage (EntitySystem &entities, const Bindings &bindings, Interfaces &interfaces, GameEvents &events)
 
 Damage (const Damage &)=delete
 
Damage & operator= (const Damage &)=delete
 
Status Available () const
 
void Apply (const Entity &victim, const DamageInfo &info)
 

Public Attributes

Event< DamageHit & > Before
 

Detailed Description

Every entity's damage, from CBaseEntity::TakeDamageOld, and a way to deal it.

The hook sits where the function starts, so it sees players, props and anything else that takes damage, including hits from Apply. It installs on the first Before subscription.

_damage = runtime.Damage.Before += [this](VoltMod::DamageHit& hit) {
if (IsStructure(hit.Victim.Ref()))
hit.Blocked = HitStructure(hit.Victim.Ref(), hit.Attacker, hit.Amount);
};
runtime.Damage.Apply(bot, {.Attacker = owner.Ref(), .Inflictor = turret, .Amount = 25,
constexpr uint32_t DamageBullet
Definition Damage.hpp:24
static std::string ReadFile(const std::filesystem::path &path)
Definition Loader.cpp:56

Game-thread only.

Definition at line 79 of file Damage.hpp.

Constructor & Destructor Documentation

◆ Damage() [1/2]

VoltMod::Damage::Damage ( EntitySystem &  entities,
const Bindings &  bindings,
Interfaces &  interfaces,
GameEvents &  events 
)

entities resolves the refs, bindings supplies the two damage functions, interfaces the event manager and events each client's listener. All must outlive this service; the Runtime declares them above.

Definition at line 36 of file Damage.cpp.

◆ Damage() [2/2]

VoltMod::Damage::Damage ( const Damage &  )
delete

Member Function Documentation

◆ Apply()

void VoltMod::Damage::Apply ( const Entity &  victim,
const DamageInfo &  info 
)

Deal info to victim through the engine, so death, the kill feed and player_death credit info's attacker as if its own weapon had hit. Does nothing for a falsy victim or while Available fails.

Definition at line 91 of file Damage.cpp.

References Available(), VoltMod::Bindings::BuildDamageInfo, VoltMod::EntitySystem::Get(), VoltMod::EngineDamageResult::OriginatingInfo, VoltMod::Entity::Raw(), VoltMod::ReadFile(), and VoltMod::Bindings::TakeDamage.

◆ Available()

Status VoltMod::Damage::Available ( ) const

Why damage cannot be hooked or dealt: a damage signature did not bind.

Definition at line 78 of file Damage.cpp.

References VoltMod::Bindings::BuildDamageInfo, VoltMod::Bindings::TakeDamage, and VoltMod::Error::Unsupported().

Referenced by Apply().

◆ operator=()

Damage & VoltMod::Damage::operator= ( const Damage &  )
delete

Member Data Documentation

◆ Before

Event<DamageHit&> VoltMod::Damage::Before

Raised before the engine applies a hit.

Definition at line 94 of file Damage.hpp.


The documentation for this class was generated from the following files: