From 9b4d09b1620915f3f105f6d9b5e1e1c7d99f4efc Mon Sep 17 00:00:00 2001 From: Jesusaves Date: Mon, 26 Aug 2019 12:48:17 -0300 Subject: New util function: array_highest() Will return first highest value in an array. For elections. --- npc/functions/array.txt | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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() +// Returns the index of the highest value in +// 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; +} + -- cgit v1.2.3-70-g09d2