From 7248dfdc9cdaff4b61aa260790bcbae3dbc36b7c Mon Sep 17 00:00:00 2001 From: Jesusaves Date: Sat, 7 Sep 2019 21:28:27 -0300 Subject: Election: In case of a tie, sort a random selection. NOTE: Zero votes and first candidate (ID 0) are still giving me some trouble. They might render results inaccuarate --- npc/functions/array.txt | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'npc') diff --git a/npc/functions/array.txt b/npc/functions/array.txt index 161cedd0b..74a38a466 100644 --- a/npc/functions/array.txt +++ b/npc/functions/array.txt @@ -420,16 +420,28 @@ function script array_highest { .@size = getarraysize(getarg(0)); .@win=0; .@idx=0; + .@dw=false; freeloop(true); for (.@i = getarrayindex(getarg(0)); .@i < .@size; ++.@i) { if (getelementofarray(getarg(0), .@i) > .@win) { .@win=getelementofarray(getarg(0), .@i); .@idx=.@i; + if (.@dw) { + deletearray .@draw; + .@dw=false; + } + } else if (getelementofarray(getarg(0), .@i) == .@win) { + array_push(.@draw, .@i); + .@dw=true; } } + // Will we return .@idx or do we need to draw a loot? freeloop(false); - return .@idx; + if (.@dw) + return any_of(.@draw); + else + return .@idx; } -- cgit v1.2.3-70-g09d2