diff options
author | Jesusaves <cpntb1@ymail.com> | 2019-08-26 12:48:17 -0300 |
---|---|---|
committer | Jesusaves <cpntb1@ymail.com> | 2019-08-26 12:48:17 -0300 |
commit | 9b4d09b1620915f3f105f6d9b5e1e1c7d99f4efc (patch) | |
tree | ecdf6fc33a29ecc7c48bc86547a6bc5d751b32a6 /npc/functions | |
parent | ea6458f2d48e2598d527cf8ce2c0c2399a3bd9d4 (diff) | |
download | serverdata-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')
-rw-r--r-- | npc/functions/array.txt | 22 |
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; +} + |