summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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;
+}
+