]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
URS: Added SetResourceAmount hook.
authorLyberta <lyberta@lyberta.net>
Mon, 28 Aug 2017 21:47:35 +0000 (00:47 +0300)
committerLyberta <lyberta@lyberta.net>
Mon, 28 Aug 2017 21:47:35 +0000 (00:47 +0300)
qcsrc/server/mutators/events.qh
qcsrc/server/resources.qc

index 5de969f01987336fb129c6e2bc0fb3d22c984f49..fd2e19878f54a78f7c03423865f4285ca94213f8 100644 (file)
@@ -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) \
index 94c21e9fbf6dd3013cb6c5d12dd8c268d5c7ce6b..cea10dcbef74706e21b4ef7970b4b46d2e7ea50f 100644 (file)
@@ -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)
        {