GREUH_squadmanagement.sqf 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. groups_list = [];
  2. squadaction = "";
  3. squadname = "";
  4. if (isNil "global_group_ids") then { global_group_ids = [] };
  5. if (isNil "global_groups_renamed") then { global_groups_renamed = [] };
  6. global_new_leader = [];
  7. while { true } do {
  8. if ( squadaction != "" ) then {
  9. _grp = grpNull;
  10. switch (squadaction) do {
  11. case "create" : {
  12. _grp = createGroup (side player);
  13. [player] join _grp;
  14. hint "New squad created";
  15. };
  16. case "join" : {
  17. if(lbCurSel 515 != -1) then { _grp = groups_list select (lbCurSel 515); };
  18. if (!(isNull _grp) && (_grp != group player)) then {
  19. [player] join _grp;
  20. hint "Squad joined";
  21. };
  22. };
  23. case "rename" : {
  24. if ( leader group player == player ) then {
  25. renaming = true;
  26. ctrlSetText [527, (groupid (group player))];
  27. waitUntil { ((squadaction == "") || (squadname != "") || !(dialog) || !(alive player)) };
  28. if ( alive player && dialog && ( squadname != "" )) then {
  29. if ( (group player) in global_groups_renamed ) then {
  30. global_group_ids set [global_groups_renamed find (group player),squadname];
  31. } else {
  32. global_group_ids = global_group_ids + [squadname];
  33. global_groups_renamed = global_groups_renamed + [group player];
  34. };
  35. publicVariable "global_group_ids";
  36. publicVariable "global_groups_renamed";
  37. };
  38. squadname = "";
  39. renaming = false;
  40. } else {
  41. hint "Sorry, only the squad leader can rename their squad.";
  42. };
  43. };
  44. case "leader" : {
  45. if ( leader group player == player ) then {
  46. choosingleader = true;
  47. choose_squadleader = -10;
  48. _player_group_filtered = [];
  49. {
  50. if ( isPlayer _x ) then {
  51. _player_group_filtered = _player_group_filtered + [_x];
  52. };
  53. } foreach (units group player);
  54. lbClear 567;
  55. {
  56. lbAdd [567, name _x ];
  57. } foreach _player_group_filtered;
  58. _count_units_grp_player = count (units group player);
  59. waitUntil { ((squadaction == "") || (choose_squadleader >= 0) || !(dialog) || !(alive player) || (_count_units_grp_player != count (units group player))) };
  60. if ( alive player && dialog && ( choose_squadleader >= 0 )) then {
  61. global_new_leader = [group player, _player_group_filtered select choose_squadleader];
  62. publicVariable "global_new_leader";
  63. };
  64. choose_squadleader = -10;
  65. choosingleader = false;
  66. } else {
  67. hint "Sorry, only the squad leader can choose a new leader.";
  68. };
  69. };
  70. };
  71. squadaction = "";
  72. };
  73. { if ( (isplayer leader _x) && (side _x == side player) && !(_x in groups_list)) then { groups_list = groups_list + [_x] }; } foreach allGroups;
  74. { if (!(_x in allGroups) || (!isplayer leader _x)) then { groups_list = groups_list - [_x] }; } foreach groups_list;
  75. {
  76. if (count global_groups_renamed != 0) then {
  77. if (_x in global_groups_renamed) then {
  78. if (groupid _x != global_group_ids select (global_groups_renamed find _x)) then {
  79. _x setgroupid [(global_group_ids select (global_groups_renamed find _x))];
  80. };
  81. };
  82. };
  83. } foreach groups_list;
  84. if ( count global_new_leader != 0 ) then {
  85. if ( group player == global_new_leader select 0 ) then {
  86. (global_new_leader select 0) selectLeader (global_new_leader select 1);
  87. hint format ["%1 is your new squad leader.",name (global_new_leader select 1)];
  88. global_new_leader = [];
  89. };
  90. };
  91. sleep 0.5;
  92. };