VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
WeaponDrop.hpp
Go to the documentation of this file.
1#pragma once
2
10
11namespace VoltMod
12{
13
14/** A player dropping a weapon themselves, as a @ref WeaponDrop::Before handler sees it. */
16{
17 int Slot = -1;
18 /** True when a weapon being picked up pushes this one out; false for the drop key. */
19 bool Swapping = false;
20 /** Set to keep the weapon; the game drops nothing. */
21 bool Blocked = false;
22};
23
24/**
25 * @brief A player's own weapon drops, from `CCSPlayer_WeaponServices::DropWeapon`.
26 *
27 * The drop key (G) reaches the server here, not as a `drop` command. The hook runs before the
28 * game's own checks, so it sees the key even while `mp_death_drop_gun 0` or `mp_drop_knife_enable 0`
29 * keep the weapon in hand. It installs on the first `Before` subscription.
30 *
31 * @code
32 * _drops = runtime.WeaponDrop.Before += [this](VoltMod::WeaponDropRequest& drop) {
33 * if (!drop.Swapping)
34 * {
35 * drop.Blocked = true;
36 * OpenShop(drop.Slot);
37 * }
38 * };
39 * @endcode
40 *
41 * Game-thread only.
42 */
44{
45public:
46 /** @p entities resolves the dropping player and @p bindings supplies the drop function. Both must
47 * outlive this service; the Runtime declares them above. */
49 WeaponDrop(const WeaponDrop&) = delete;
50 WeaponDrop& operator=(const WeaponDrop&) = delete;
51
52private:
53 LazyHook _hook;
54
55public:
56 /** Raised before the game handles a player's drop. */
58
59 /** Why drops cannot be hooked: the drop signature did not bind. */
60 Status Available() const;
61
62private:
63 Result<Subscription> Install();
65
66 EntitySystem& _entities;
67 const Bindings& _bindings;
68};
69
70} // namespace VoltMod
runtime.Entities: finds and creates entities. Everything it returns is valid for this frame only; see...
A multicast signal with a fixed handler signature: the one way to subscribe in VoltMod.
Definition Event.hpp:54
A hook before-handler's verdict.
An engine hook that exists only while one of its events has handlers.
Definition LazyHook.hpp:30
A player's own weapon drops, from CCSPlayer_WeaponServices::DropWeapon.
Event< WeaponDropRequest & > Before
Status Available() const
WeaponDrop & operator=(const WeaponDrop &)=delete
WeaponDrop(const WeaponDrop &)=delete
static std::string ReadFile(const std::filesystem::path &path)
Definition Loader.cpp:56
std::expected< void, Error > Status
Definition Result.hpp:67
std::expected< T, Error > Result
Definition Result.hpp:64