VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
FireHold.cpp
Go to the documentation of this file.
3
4namespace VoltMod
5{
6
7void FireHold::Hold(const Pawn& pawn, const Clock& clock)
8{
9 const int tick = HoldFireTick(clock);
10 const Entity active = pawn.ActiveWeapon();
11 const Schema::CBasePlayerWeapon weapon{active.Raw()};
12 if (weapon && active.Ref() != _weapon)
13 {
14 _weapon = active.Ref();
15 _primary = weapon.NextPrimaryAttackTick();
16 _secondary = weapon.NextSecondaryAttackTick();
17 }
18 _until = tick;
19 // Pawn::HoldFire inline, on the weapon already looked up.
20 if (weapon && weapon.NextPrimaryAttackTick() < tick)
21 {
22 weapon.SetNextPrimaryAttackTick(tick);
23 }
24 if (weapon && weapon.NextSecondaryAttackTick() < tick)
25 {
26 weapon.SetNextSecondaryAttackTick(tick);
27 }
28}
29
30void FireHold::Release(const Pawn& pawn)
31{
32 if (_until == 0)
33 {
34 return;
35 }
36 const Entity active = pawn.ActiveWeapon();
37 const Schema::CBasePlayerWeapon weapon{active.Raw()};
38 // Ticks a reload or a switch has set since are the game's own, so only the hold's are put back.
39 if (weapon && active.Ref() == _weapon)
40 {
41 if (weapon.NextPrimaryAttackTick() == _until)
42 {
43 weapon.SetNextPrimaryAttackTick(_primary);
44 }
45 if (weapon.NextSecondaryAttackTick() == _until)
46 {
47 weapon.SetNextSecondaryAttackTick(_secondary);
48 }
49 }
50 _weapon = {};
51 _until = 0;
52}
53
54} // namespace VoltMod
The engine's simulation clock, read straight from IVEngineServer2::GetServerGlobals().
Definition Clock.hpp:19
A live entity, valid for this frame only.
Definition Entity.hpp:40
EntityRef Ref() const
Definition Entity.cpp:70
CEntityInstance * Raw() const noexcept
Definition Entity.hpp:58
void Release(const Pawn &pawn)
Definition FireHold.cpp:30
void Hold(const Pawn &pawn, const Clock &clock)
Definition FireHold.cpp:7
A player's body: health, armor, movement, aim, weapons. The engine replaces it on every spawn; the Co...
Definition Pawn.hpp:35
Entity ActiveWeapon() const
Definition Pawn.cpp:171
void SetNextPrimaryAttackTick(int32_t value) const
void SetNextSecondaryAttackTick(int32_t value) const
int HoldFireTick(const Clock &clock)
Definition Pawn.cpp:27