summaryrefslogtreecommitdiffstats
path: root/Common/Functions/Common_GetCommanderFromVotes.sqf
diff options
context:
space:
mode:
authorhybrid <hybrid@hybridlabs.pro>2026-06-11 19:55:04 +0300
committerhybrid <hybrid@hybridlabs.pro>2026-06-11 19:55:04 +0300
commitb06990293397d4b6d0374097f09d1cc5679216e3 (patch)
tree5719922562e317a8083250c178f24376b6692569 /Common/Functions/Common_GetCommanderFromVotes.sqf
downloada2wf_saralite-b06990293397d4b6d0374097f09d1cc5679216e3.tar.gz
a2wf_saralite-b06990293397d4b6d0374097f09d1cc5679216e3.tar.bz2
a2wf_saralite-b06990293397d4b6d0374097f09d1cc5679216e3.zip
init
Diffstat (limited to 'Common/Functions/Common_GetCommanderFromVotes.sqf')
-rw-r--r--Common/Functions/Common_GetCommanderFromVotes.sqf36
1 files changed, 36 insertions, 0 deletions
diff --git a/Common/Functions/Common_GetCommanderFromVotes.sqf b/Common/Functions/Common_GetCommanderFromVotes.sqf
new file mode 100644
index 0000000..c0210f6
--- /dev/null
+++ b/Common/Functions/Common_GetCommanderFromVotes.sqf
@@ -0,0 +1,36 @@
+Private["_AI","_commander","_count","_highest","_highestTeam","_side","_teams","_tie","_total","_vote","_votes"];
+
+_side = _this Select 0;
+
+_AI = 0;
+_teams = (Format["WFBE_%1TEAMS",str _side] Call GetNamespace);
+_total = Count _teams;
+
+_votes = [];
+for [{_count = 0},{_count < _total},{_count = _count + 1}] do {_votes = _votes + [0]};
+
+//Count votes.
+for [{_count = 0},{_count < _total},{_count = _count + 1}] do {
+ if (isPlayer (leader (_teams Select _count))) then {
+ _vote = Call Compile Format ["%1Team%2Vote",Str _side,_count + 1];
+ if (_vote != -1) then {
+ _votes Set[_vote,(_votes Select _vote) + 1];
+ } else {
+ _AI = _AI + 1;
+ };
+ };
+};
+
+_count = 0;
+_highest = 0;
+_highestTeam = -1;
+_tie = false;
+{if (_x == _highest && _x > 0) then {_tie = true};if (_x > _highest) then {_highestTeam = _count;_highest = _x;_tie = false};_count = _count + 1} ForEach _votes;
+
+_commander = ObjNull;
+
+if (!_tie && _highest > _AI && _highestTeam != -1) then {
+ _commander = _teams select _highestTeam;
+};
+
+_commander \ No newline at end of file