]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/resources.qc
Merge branch 'Mario/target_teleporter_v2' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / resources.qc
index 6526e2f11d262f80dd888a66d6bfbad60a904d60..a2a1358b97856196366b7dc95c909c620f2152ec 100644 (file)
@@ -1,9 +1,9 @@
+#include "resources.qh"
+
 /// \file
 /// \brief Source file that contains implementation of the resource system.
 /// \author Lyberta
-/// \copyright GNU GPLv3 or any later version.
-
-#include "resources.qh"
+/// \copyright GNU GPLv2 or any later version.
 
 #include "autocvars.qh"
 #include "miscfunctions.qh"
@@ -141,6 +141,21 @@ void GiveResource(entity receiver, int resource_type, float amount)
        }
 }
 
+void GiveResourceWithLimit(entity receiver, int resource_type, float amount,
+       float limit)
+{
+       if (amount == 0)
+       {
+               return;
+       }
+       float current_amount = GetResourceAmount(receiver, resource_type);
+       if (current_amount + amount > limit)
+       {
+               amount = limit - current_amount;
+       }
+       GiveResource(receiver, resource_type, amount);
+}
+
 int GetResourceType(.float resource_field)
 {
        switch (resource_field)