summaryrefslogtreecommitdiff
path: root/npc
diff options
context:
space:
mode:
authorJesusaves <cpntb1@ymail.com>2019-09-07 21:28:27 -0300
committerJesusaves <cpntb1@ymail.com>2019-09-07 21:28:27 -0300
commit7248dfdc9cdaff4b61aa260790bcbae3dbc36b7c (patch)
treefffd34e139cd8f62fab3cb28cc18a8f32296d58a /npc
parente24d87fefc4bea4b47d598c6dac588226f480573 (diff)
downloadserverdata-7248dfdc9cdaff4b61aa260790bcbae3dbc36b7c.tar.gz
serverdata-7248dfdc9cdaff4b61aa260790bcbae3dbc36b7c.tar.bz2
serverdata-7248dfdc9cdaff4b61aa260790bcbae3dbc36b7c.tar.xz
serverdata-7248dfdc9cdaff4b61aa260790bcbae3dbc36b7c.zip
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
Diffstat (limited to 'npc')
-rw-r--r--npc/functions/array.txt14
1 files changed, 13 insertions, 1 deletions
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;
}