Guest User

Untitled

a guest
Dec 11th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.58 KB | None | 0 0
  1. //--- Register the UI.
  2. uiNamespace setVariable ["wfbe_display_vote", _this select 0];
  3.  
  4. _u = 1;
  5. lnbClear 500100;
  6. lnbAddRow[500100, ["AI Commander", "0"]];
  7. lnbSetValue[500100, [0, 0], -1];
  8. for '_i' from 0 to count(WFBE_Client_Teams)-1 do {
  9. if (isPlayer leader (WFBE_Client_Teams select _i)) then {
  10. lnbAddRow[500100, [name leader (WFBE_Client_Teams select _i), "0"]];
  11. lnbSetValue[500100, [_u, 0], _i];
  12. _u = _u + 1;
  13. };
  14. };
  15.  
  16. WFBE_MenuAction = -1;
  17.  
  18. _update_list = -5;
  19. _voteArray = [];
  20.  
  21. while {alive player && dialog} do {
  22. _voteTime = WFBE_Client_Logic getVariable "wfbe_votetime";
  23.  
  24. //--- Exit when the timeout is reached.
  25. if (_voteTime < 0) exitWith {closeDialog 0};
  26.  
  27. for '_i' from 0 to WFBE_Client_Teams_Count do {_voteArray set [_i , 0]};
  28.  
  29. //--- The client has voted for x.
  30. if (WFBE_MenuAction == 1) then {
  31. WFBE_MenuAction = -1;
  32. _index = lnbValue [500100,[lnbCurSelRow 500100, 0]];
  33. if ((WFBE_Client_Team getVariable "wfbe_vote") != _index) then {WFBE_Client_Team setVariable ["wfbe_vote", _index, true]};
  34. };
  35.  
  36. //--- Update the votes.
  37. _playerCount = 0;
  38. {
  39. if (isPlayer leader _x) then {
  40. _vote = (_x getVariable "wfbe_vote") + 1;
  41. _voteArray set [_vote, (_voteArray select _vote) + 1];
  42. _playerCount = _playerCount + 1;
  43. };
  44. } forEach WFBE_Client_Teams;
  45.  
  46. _highestId = 0;
  47. for '_i' from 0 to WFBE_Client_Teams_Count do {if ((_voteArray select _i) > (_voteArray select _highestId)) then {_highestId = _i}}; //--- Get the most voted person.
  48.  
  49. if (time - _update_list > 1) then { //--- Refresh the list.
  50. _update_list = time;
  51.  
  52. _list_present = [];
  53. for '_i' from 1 to ((lnbSize 500100) select 0)-1 do { //--- Remove potential non-player controlled slots.
  54. _value = lnbValue [500100,[_i, 0]];
  55. _team = WFBE_Client_Teams select _value;
  56. if !(isPlayer leader _team) then {lnbDeleteRow [500100, _i]} else {[_list_present, _value] Call WFBE_CO_FNC_ArrayPush};
  57. };
  58.  
  59. for '_i' from 0 to WFBE_Client_Teams_Count do { //--- Add potential new player controlled slots.
  60. _team = WFBE_Client_Teams select _i;
  61. if (isPlayer leader _team && !(_i in _list_present)) then {
  62. lnbAddRow[500100, [name leader _team, "0"]];
  63. lnbSetValue[500100, [((lnbSize 500100) select 0)-1, 0], _i];
  64. };
  65. };
  66. };
  67.  
  68. if ((((uiNamespace getVariable "wfbe_display_vote") displayCtrl 500100) lnbText [0, 1]) != str(_voteArray select 0)) then {lnbSetText [500100, [0, 1], str(_voteArray select 0)]}; //--- AI Commander
  69.  
  70. for '_i' from 1 to ((lnbSize 500100) select 0)-1 do { //--- Update the UI list properties (name / votes) for players.
  71. _value = lnbValue [500100,[_i, 0]];
  72. _team = WFBE_Client_Teams select _value;
  73. if ((((uiNamespace getVariable "wfbe_display_vote") displayCtrl 500100) lnbText [_i, 0]) != name leader _team) then {lnbSetText [500100, [_i, 0], name leader _team]};
  74. if ((((uiNamespace getVariable "wfbe_display_vote") displayCtrl 500100) lnbText [_i, 1]) != str(_voteArray select _value+1)) then {lnbSetText [500100, [_i, 1], str(_voteArray select _value+1)]};
  75. if (((WFBE_Client_Teams select _i) getVariable "wfbe_vote") != -1) then {
  76. lnbSetColor [500100, [_i+1,0], [1,0,0,1]]
  77. } else {
  78. lnbSetColor [500100, [_i+1,0], [1,1,1,1]]
  79. };
  80.  
  81. };
  82.  
  83. //--- Update the text
  84. _voted_commander = if ((_voteArray select _highestId) <= (_playerCount/2) || _highestId == 0) then {localize "STR_WF_AI"} else {name leader (WFBE_Client_Teams select _highestId-1)};
  85. ctrlSetText [500101, _voted_commander];
  86. ctrlSetText [500102, Format ["%1",_voteTime]];
  87.  
  88. sleep 0.05;
  89. };
  90.  
  91. //--- Release the UI.
  92. uiNamespace setVariable ["wfbe_display_vote", nil];
Add Comment
Please, Sign In to add comment