Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.84 KB | None | 0 0
  1. //! zinc
  2. library Users requires GroupUtils{
  3.  
  4. private{
  5. constant boolean AUTO_COLOR_UNITS = true;
  6. constant boolean ARRAY_LOOKUP = false;
  7. constant boolean HOOK_SAFETY = false;
  8. constant force FORCE_PLAYING = CreateForce();
  9.  
  10. string User_Name[];
  11. string User_Hex[];
  12. string Original_Hex[];
  13. playercolor Current_Color[];
  14. }
  15.  
  16. keyword UsersInit;
  17.  
  18. public struct User extends array{
  19.  
  20. static constant integer NULL = bj_MAX_PLAYER_SLOTS;
  21.  
  22. player handle;
  23. integer id;
  24. thistype next;
  25. thistype prev;
  26.  
  27. string originalName;
  28. boolean isPlaying;
  29.  
  30. static thistype first;
  31. static thistype last;
  32. static player Local;
  33. static integer LocalId;
  34. static integer amountPlaying = 0;
  35. static playercolor userColor[];
  36.  
  37. static group ENUM_GROUP = CreateGroup();
  38.  
  39. static thistype playingPlayer[];
  40. static thistype playingPlayerIndex[];
  41.  
  42. static method fromIndex(integer index) -> thistype{
  43.  
  44. return thistype(index);
  45. }
  46.  
  47. static method fromLocal() -> thistype{
  48.  
  49. return thistype(thistype.LocalId);
  50. }
  51.  
  52. static method fromPlaying(integer index) -> thistype{
  53.  
  54. return playingPlayer[index];
  55. }
  56.  
  57. static method operator [](player whichPlayer) -> thistype{
  58.  
  59. return thistype(GetPlayerId(whichPlayer));
  60. }
  61.  
  62. method toPlayer() -> player{
  63.  
  64. return this.handle;
  65. }
  66.  
  67. method operator name() -> string{
  68.  
  69. static if (ARRAY_LOOKUP){
  70. return User_Name[this];
  71. }else{
  72. return GetPlayerName(this.handle);
  73. }
  74. }
  75.  
  76. method operator name=(string newName){
  77.  
  78. SetPlayerName(this.handle, newName);
  79. static if (ARRAY_LOOKUP){
  80. static if (!HOOK_SAFETY){
  81. User_Name[this] = newName;
  82. }
  83. }
  84. }
  85.  
  86. method operator color() -> playercolor{
  87.  
  88. static if (ARRAY_LOOKUP){
  89. return Current_Color[this];
  90. }else{
  91. return GetPlayerColor(this.handle);
  92. }
  93. }
  94.  
  95. method operator hex() -> string{
  96.  
  97. return Original_Hex[GetHandleId(this.color)];
  98. }
  99.  
  100. method operator color=(playercolor newColor){
  101.  
  102. SetPlayerColor(this.handle, newColor);
  103. static if (ARRAY_LOOKUP){
  104. Current_Color[this] = newColor;
  105. static if (!HOOK_SAFETY){
  106. static if (AUTO_COLOR_UNITS){
  107. this.colorUnits(newColor);
  108. }
  109. }
  110. }
  111. }
  112.  
  113. method operator defaultColor() -> playercolor{
  114.  
  115. return userColor[this];
  116. }
  117.  
  118. method nameColored() -> string{
  119.  
  120. return hex + this.name + "|r";
  121. }
  122.  
  123. method colorUnits(playercolor newColor){
  124. unit u;
  125.  
  126. GroupEnumUnitsOfPlayer(ENUM_GROUP, this.handle, null);
  127. u = FirstOfGroup(ENUM_GROUP);
  128. while (u != null){
  129. SetUnitColor(u, newColor);
  130. GroupRemoveUnit(ENUM_GROUP, u);
  131. }
  132. u = null;
  133. }
  134.  
  135. static method onLeave() -> boolean{
  136. player p = GetTriggerPlayer();
  137. thistype h = thistype[GetTriggerPlayer()];
  138. integer i = playingPlayerIndex[h.id];
  139.  
  140. amountPlaying = amountPlaying - 1;
  141. playingPlayer[i] = playingPlayer[amountPlaying];
  142.  
  143. if (amountPlaying == 1){
  144. h.prev.next = User.NULL;
  145. h.next.prev = User.NULL;
  146. }else{
  147. h.prev.next = h.next;
  148. h.next.prev = h.prev;
  149. }
  150. last = playingPlayer[amountPlaying];
  151. h.isPlaying = false;
  152. return false;
  153. }
  154.  
  155. module UsersInit;
  156. }
  157.  
  158. private module UsersInit{
  159.  
  160. static method onInit(){
  161. trigger t = CreateTrigger();
  162. integer i = 0;
  163. thistype p;
  164.  
  165. thistype.Local = GetLocalPlayer();
  166. thistype.LocalId = GetPlayerId(thistype.Local);
  167.  
  168. Original_Hex[0] = "|cffff0303";
  169. Original_Hex[1] = "|cff0042ff";
  170. Original_Hex[2] = "|cff1ce6b9";
  171. Original_Hex[3] = "|cff540081";
  172. Original_Hex[4] = "|cfffffc01";
  173. Original_Hex[5] = "|cfffe8a0e";
  174. Original_Hex[6] = "|cff20c000";
  175. Original_Hex[7] = "|cffe55bb0";
  176. Original_Hex[8] = "|cff959697";
  177. Original_Hex[9] = "|cff7ebff1";
  178. Original_Hex[10] = "|cff106246";
  179. Original_Hex[11] = "|cff4e2a04";
  180. if (bj_MAX_PLAYER_SLOTS > 12){
  181. Original_Hex[12] = "|cff9B0000";
  182. Original_Hex[13] = "|cff0000C3";
  183. Original_Hex[14] = "|cff00EAFF";
  184. Original_Hex[15] = "|cffBE00FE";
  185. Original_Hex[16] = "|cffEBCD87";
  186. Original_Hex[17] = "|cffF8A48B";
  187. Original_Hex[18] = "|cffBFFF80";
  188. Original_Hex[19] = "|cffDCB9EB";
  189. Original_Hex[20] = "|cff282828";
  190. Original_Hex[21] = "|cffEBF0FF";
  191. Original_Hex[22] = "|cff00781E";
  192. Original_Hex[23] = "|cffA46F33";
  193. }
  194. thistype.first = User.NULL;
  195. while (i < bj_MAX_PLAYER_SLOTS){
  196. p = User(i);
  197. p.handle = Player(i);
  198. p.id = i;
  199.  
  200. thistype.userColor[i] = GetPlayerColor(p.handle);
  201. Current_Color[i] = thistype.userColor[i];
  202. if (GetPlayerController(p.handle) == MAP_CONTROL_USER
  203. && GetPlayerSlotState(p.handle) == PLAYER_SLOT_STATE_PLAYING){
  204. playingPlayer[amountPlaying] = p;
  205. playingPlayerIndex[i] = amountPlaying;
  206. last = i;
  207. if (first == User.NULL){
  208. first = i;
  209. User(i).next = User.NULL;
  210. User(i).prev = User.NULL;
  211. }else{
  212. User(i).prev = playingPlayer[amountPlaying - 1].id;
  213. playingPlayer[amountPlaying - 1].next = User(i);
  214. User(i).next = User.NULL;
  215. }
  216. p.isPlaying = true;
  217. TriggerRegisterPlayerEvent(t, p.handle, EVENT_PLAYER_LEAVE);
  218. ForceAddPlayer(FORCE_PLAYING, p.handle);
  219. User_Hex[p] = Original_Hex[GetHandleId(thistype.userColor[i])];
  220. amountPlaying += 1;
  221. }
  222. User_Name[p] = GetPlayerName(p.handle);
  223. p.originalName = User_Name[p];
  224. i += 1;
  225. }
  226. TriggerAddCondition(t, Filter(function thistype.onLeave));
  227. t = null;
  228. }
  229. }
  230.  
  231. }
  232. //! endzinc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement