summaryrefslogtreecommitdiff
path: root/npc/functions/array.txt
diff options
context:
space:
mode:
authorJesusaves <cpntb1@ymail.com>2019-08-26 12:48:17 -0300
committerJesusaves <cpntb1@ymail.com>2019-08-26 12:48:17 -0300
commit9b4d09b1620915f3f105f6d9b5e1e1c7d99f4efc (patch)
treeecdf6fc33a29ecc7c48bc86547a6bc5d751b32a6 /npc/functions/array.txt
parentea6458f2d48e2598d527cf8ce2c0c2399a3bd9d4 (diff)
downloadserverdata-9b4d09b1620915f3f105f6d9b5e1e1c7d99f4efc.tar.gz
serverdata-9b4d09b1620915f3f105f6d9b5e1e1c7d99f4efc.tar.bz2
serverdata-9b4d09b1620915f3f105f6d9b5e1e1c7d99f4efc.tar.xz
serverdata-9b4d09b1620915f3f105f6d9b5e1e1c7d99f4efc.zip
New util function: array_highest(<array>)
Will return first highest value in an array. For elections.
Diffstat (limited to 'npc/functions/array.txt')
-rw-r--r--npc/functions/array.txt22
1 files changed, 22 insertions, 0 deletions
diff --git a/npc/functions/array.txt b/npc/functions/array.txt
index 1a106175e..161cedd0b 100644
--- a/npc/functions/array.txt
+++ b/npc/functions/array.txt
@@ -411,3 +411,25 @@ function script array_filter {
freeloop(false);
return .@count;
}
+
+// array_highest(<array>)
+// Returns the index of the highest value in <array>
+// NOTE: Array must be an INT array!
+
+function script array_highest {
+ .@size = getarraysize(getarg(0));
+ .@win=0;
+ .@idx=0;
+ freeloop(true);
+
+ for (.@i = getarrayindex(getarg(0)); .@i < .@size; ++.@i) {
+ if (getelementofarray(getarg(0), .@i) > .@win) {
+ .@win=getelementofarray(getarg(0), .@i);
+ .@idx=.@i;
+ }
+ }
+
+ freeloop(false);
+ return .@idx;
+}
+