Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //! zinc
- library Users requires GroupUtils{
- private{
- constant boolean AUTO_COLOR_UNITS = true;
- constant boolean ARRAY_LOOKUP = false;
- constant boolean HOOK_SAFETY = false;
- constant force FORCE_PLAYING = CreateForce();
- string User_Name[];
- string User_Hex[];
- string Original_Hex[];
- playercolor Current_Color[];
- }
- keyword UsersInit;
- public struct User extends array{
- static constant integer NULL = bj_MAX_PLAYER_SLOTS;
- player handle;
- integer id;
- thistype next;
- thistype prev;
- string originalName;
- boolean isPlaying;
- static thistype first;
- static thistype last;
- static player Local;
- static integer LocalId;
- static integer amountPlaying = 0;
- static playercolor userColor[];
- static group ENUM_GROUP = CreateGroup();
- static thistype playingPlayer[];
- static thistype playingPlayerIndex[];
- static method fromIndex(integer index) -> thistype{
- return thistype(index);
- }
- static method fromLocal() -> thistype{
- return thistype(thistype.LocalId);
- }
- static method fromPlaying(integer index) -> thistype{
- return playingPlayer[index];
- }
- static method operator [](player whichPlayer) -> thistype{
- return thistype(GetPlayerId(whichPlayer));
- }
- method toPlayer() -> player{
- return this.handle;
- }
- method operator name() -> string{
- static if (ARRAY_LOOKUP){
- return User_Name[this];
- }else{
- return GetPlayerName(this.handle);
- }
- }
- method operator name=(string newName){
- SetPlayerName(this.handle, newName);
- static if (ARRAY_LOOKUP){
- static if (!HOOK_SAFETY){
- User_Name[this] = newName;
- }
- }
- }
- method operator color() -> playercolor{
- static if (ARRAY_LOOKUP){
- return Current_Color[this];
- }else{
- return GetPlayerColor(this.handle);
- }
- }
- method operator hex() -> string{
- return Original_Hex[GetHandleId(this.color)];
- }
- method operator color=(playercolor newColor){
- SetPlayerColor(this.handle, newColor);
- static if (ARRAY_LOOKUP){
- Current_Color[this] = newColor;
- static if (!HOOK_SAFETY){
- static if (AUTO_COLOR_UNITS){
- this.colorUnits(newColor);
- }
- }
- }
- }
- method operator defaultColor() -> playercolor{
- return userColor[this];
- }
- method nameColored() -> string{
- return hex + this.name + "|r";
- }
- method colorUnits(playercolor newColor){
- unit u;
- GroupEnumUnitsOfPlayer(ENUM_GROUP, this.handle, null);
- u = FirstOfGroup(ENUM_GROUP);
- while (u != null){
- SetUnitColor(u, newColor);
- GroupRemoveUnit(ENUM_GROUP, u);
- }
- u = null;
- }
- static method onLeave() -> boolean{
- player p = GetTriggerPlayer();
- thistype h = thistype[GetTriggerPlayer()];
- integer i = playingPlayerIndex[h.id];
- amountPlaying = amountPlaying - 1;
- playingPlayer[i] = playingPlayer[amountPlaying];
- if (amountPlaying == 1){
- h.prev.next = User.NULL;
- h.next.prev = User.NULL;
- }else{
- h.prev.next = h.next;
- h.next.prev = h.prev;
- }
- last = playingPlayer[amountPlaying];
- h.isPlaying = false;
- return false;
- }
- module UsersInit;
- }
- private module UsersInit{
- static method onInit(){
- trigger t = CreateTrigger();
- integer i = 0;
- thistype p;
- thistype.Local = GetLocalPlayer();
- thistype.LocalId = GetPlayerId(thistype.Local);
- Original_Hex[0] = "|cffff0303";
- Original_Hex[1] = "|cff0042ff";
- Original_Hex[2] = "|cff1ce6b9";
- Original_Hex[3] = "|cff540081";
- Original_Hex[4] = "|cfffffc01";
- Original_Hex[5] = "|cfffe8a0e";
- Original_Hex[6] = "|cff20c000";
- Original_Hex[7] = "|cffe55bb0";
- Original_Hex[8] = "|cff959697";
- Original_Hex[9] = "|cff7ebff1";
- Original_Hex[10] = "|cff106246";
- Original_Hex[11] = "|cff4e2a04";
- if (bj_MAX_PLAYER_SLOTS > 12){
- Original_Hex[12] = "|cff9B0000";
- Original_Hex[13] = "|cff0000C3";
- Original_Hex[14] = "|cff00EAFF";
- Original_Hex[15] = "|cffBE00FE";
- Original_Hex[16] = "|cffEBCD87";
- Original_Hex[17] = "|cffF8A48B";
- Original_Hex[18] = "|cffBFFF80";
- Original_Hex[19] = "|cffDCB9EB";
- Original_Hex[20] = "|cff282828";
- Original_Hex[21] = "|cffEBF0FF";
- Original_Hex[22] = "|cff00781E";
- Original_Hex[23] = "|cffA46F33";
- }
- thistype.first = User.NULL;
- while (i < bj_MAX_PLAYER_SLOTS){
- p = User(i);
- p.handle = Player(i);
- p.id = i;
- thistype.userColor[i] = GetPlayerColor(p.handle);
- Current_Color[i] = thistype.userColor[i];
- if (GetPlayerController(p.handle) == MAP_CONTROL_USER
- && GetPlayerSlotState(p.handle) == PLAYER_SLOT_STATE_PLAYING){
- playingPlayer[amountPlaying] = p;
- playingPlayerIndex[i] = amountPlaying;
- last = i;
- if (first == User.NULL){
- first = i;
- User(i).next = User.NULL;
- User(i).prev = User.NULL;
- }else{
- User(i).prev = playingPlayer[amountPlaying - 1].id;
- playingPlayer[amountPlaying - 1].next = User(i);
- User(i).next = User.NULL;
- }
- p.isPlaying = true;
- TriggerRegisterPlayerEvent(t, p.handle, EVENT_PLAYER_LEAVE);
- ForceAddPlayer(FORCE_PLAYING, p.handle);
- User_Hex[p] = Original_Hex[GetHandleId(thistype.userColor[i])];
- amountPlaying += 1;
- }
- User_Name[p] = GetPlayerName(p.handle);
- p.originalName = User_Name[p];
- i += 1;
- }
- TriggerAddCondition(t, Filter(function thistype.onLeave));
- t = null;
- }
- }
- }
- //! endzinc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement