]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Added GiveResourceWithLimit hook.
authorLyberta <lyberta@lyberta.net>
Mon, 19 Mar 2018 08:39:22 +0000 (11:39 +0300)
committerLyberta <lyberta@lyberta.net>
Mon, 19 Mar 2018 08:39:22 +0000 (11:39 +0300)
qcsrc/server/mutators/events.qh
qcsrc/server/resources.qc

index 6853c04a15641dc69bd6e52f7da39615a41610a4..f0112a51971c9f8157d71412ca78470972f041dd 100644 (file)
@@ -690,6 +690,19 @@ for resource types. Return true to forbid giving. */
        /**/
 MUTATOR_HOOKABLE(GiveResource, EV_GiveResource);
 
+/** Called when entity is being given some resource with specified limit. See
+RESOURCE_* constants for resource types. Return true to forbid giving. */
+#define EV_GiveResourceWithLimit(i, o) \
+       /** receiver */      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) \
+       /** limit */         i(float, MUTATOR_ARGV_3_float) \
+       /**/                 o(float, MUTATOR_ARGV_3_float) \
+       /**/
+MUTATOR_HOOKABLE(GiveResourceWithLimit, EV_GiveResourceWithLimit);
+
 /** called at when a player connect */
 #define EV_ClientConnect(i, o) \
     /** player */ i(entity, MUTATOR_ARGV_0_entity) \
index a2a1358b97856196366b7dc95c909c620f2152ec..254db749fff871eb3331024e58e048d7afa704b9 100644 (file)
@@ -148,6 +148,19 @@ void GiveResourceWithLimit(entity receiver, int resource_type, float amount,
        {
                return;
        }
+       bool forbid = MUTATOR_CALLHOOK(GiveResourceWithLimit, receiver,
+               resource_type, amount, limit);
+       if (forbid)
+       {
+               return;
+       }
+       resource_type = M_ARGV(1, int);
+       amount = M_ARGV(2, float);
+       limit = M_ARGV(3, float);
+       if (amount <= 0)
+       {
+               return;
+       }
        float current_amount = GetResourceAmount(receiver, resource_type);
        if (current_amount + amount > limit)
        {