From c77f2e6f7eaee7538abde395b667b24d17a85d99 Mon Sep 17 00:00:00 2001 From: Lyberta Date: Tue, 29 Aug 2017 00:47:35 +0300 Subject: [PATCH] URS: Added SetResourceAmount hook. --- qcsrc/server/mutators/events.qh | 11 +++++++++++ qcsrc/server/resources.qc | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/qcsrc/server/mutators/events.qh b/qcsrc/server/mutators/events.qh index 5de969f01..fd2e19878 100644 --- a/qcsrc/server/mutators/events.qh +++ b/qcsrc/server/mutators/events.qh @@ -630,6 +630,17 @@ resource limit. */ /**/ MUTATOR_HOOKABLE(GetResourceLimit, EV_GetResourceLimit); +/** Called when the amount of resource of an entity changes. See RESOURCE_* +constants for resource types. Return true to forbid the change. */ +#define EV_SetResourceAmount(i, o) \ + /** checked entity */ i(entity, MUTATOR_ARGV_0_entity) \ + /** resource type */ i(int, MUTATOR_ARGV_1_int) \ + /**/ o(int, MUTATOR_ARGV_1_int) \ + /** amount */ i(float, MUTATOR_ARGV_2_float) \ + /**/ o(float, MUTATOR_ARGV_2_float) \ + /**/ +MUTATOR_HOOKABLE(SetResourceAmount, EV_SetResourceAmount); + /** Called when entity is being given some resource. See RESOURCE_* constants for resource types. Return true to forbid giving. */ #define EV_GiveResource(i, o) \ diff --git a/qcsrc/server/resources.qc b/qcsrc/server/resources.qc index 94c21e9fb..cea10dcbe 100644 --- a/qcsrc/server/resources.qc +++ b/qcsrc/server/resources.qc @@ -71,6 +71,13 @@ float GetResourceAmount(entity e, int resource_type) void SetResourceAmount(entity e, int resource_type, float amount) { + bool forbid = MUTATOR_CALLHOOK(SetResourceAmount, e, resource_type, amount); + if (forbid) + { + return; + } + resource_type = M_ARGV(1, int); + amount = M_ARGV(2, float); .float resource_field = GetResourceField(resource_type); if (e.(resource_field) == amount) { -- 2.39.2