Advertisement
jst96

Dynamic Team Party

Nov 6th, 2016
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 14.79 KB | None | 0 0
  1. #include <a_samp>
  2. #include <easyDialog>
  3. #include <sscanf2>
  4. #include <YSI\y_iterate>
  5. #include <YSI\y_groups>
  6. #include <YSI\y_commands>
  7.  
  8. #define COLOR_SYNTAX_WARNING 0xAFAFAFAA // color _ grey
  9. #define COLOR_ADMIN_WARNING 0xFFFF0000 // color _ yellow
  10. #define COLOR_LIGHTBLUE 0x33CCFFAA
  11.  
  12. #define MAX_PARTY_NAME 32
  13. #define MAX_PARTIES 5
  14.  
  15. #define RGBAToInt(%0,%1,%2,%3) ((16777216 * (%0)) + (65536 * (%1)) + (256 * (%2)) + (%3))
  16. #define IsNull(%1) ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
  17. #define SEM(%0,%1) SendClientMessage(%0, COLOR_SYNTAX_WARNING, %1)
  18.  
  19. GetName(target)
  20. {
  21.     new name[MAX_PLAYER_NAME + 1];
  22.     GetPlayerName(target, name, sizeof name);
  23.     return name;
  24. }
  25.  
  26. enum pinfo
  27. {
  28.     ID,
  29.     Party,
  30.     Level
  31. }
  32. new PlayerInfo[MAX_PLAYERS][pinfo];
  33.  
  34. enum party_info
  35. {
  36.     ID,
  37.     Name[MAX_PARTY_NAME],
  38.     Leader,
  39.     Color
  40. };
  41. new PartyInfo[MAX_PARTIES][party_info];
  42. new PartyInvite[MAX_PLAYERS];
  43. new Group:PlayerParty[MAX_PARTIES];
  44. new Iterator:Parties<MAX_PARTIES>;
  45.  
  46. bool:CreateParty(playerid,name[])
  47. {
  48.     new id = Iter_Free(Parties);
  49.     if(id == -1) return false;
  50.     if(Iter_Contains(Parties,id)) return false;
  51.     PartyInfo[id][ID] = id;
  52.     strmid(PartyInfo[id][Name],name,0,strlen(name),MAX_PARTY_NAME);
  53.     PartyInfo[id][Color] = RGBAToInt(random(256),random(256),random(256),100);
  54.     PartyInfo[id][Leader] = PlayerInfo[playerid][ID];
  55.     PlayerInfo[playerid][Party] = id;
  56.     Iter_Add(Parties,id);
  57.     PlayerParty[id] = Group_Create(PartyInfo[id][Name]);
  58.     Group_SetPlayer(PlayerParty[id],playerid,true);
  59.     SetPlayerColor(playerid,PartyInfo[playerid][Color]);
  60.     return true;
  61. }
  62.  
  63. ResetPlayerParty(playerid)
  64. {
  65.     new partyid = PlayerInfo[playerid][Party];
  66.     PartyInfo[partyid][ID] = 0;
  67.     PartyInfo[partyid][Name] = 0;
  68.     PartyInfo[partyid][Leader] = 0;
  69.     PartyInfo[partyid][Color] = 0;
  70.     return 0;
  71. }
  72.  
  73. SendPartyMessage(partyid,message[])
  74. {
  75.     foreach(new member : GroupMember(PlayerParty[partyid]))
  76.     {
  77.         SendClientMessage(member,PartyInfo[partyid][Color],message);
  78.     }
  79.     return 1;
  80. }
  81.  
  82. Dialog:PartyList(playerid, response, listitem, inputtext[])
  83. {
  84.     if(response)
  85.     {
  86.         if(IsPlayerAdmin(playerid))
  87.         {
  88.             if(Iter_Contains(Parties,listitem))
  89.             {
  90.                 new string[150];
  91.                 format(string,sizeof(string),"Are you sure you want to disband this team?\nParty ID:\t%d\nParty Name:\t%s",listitem,PartyInfo[listitem][Name]);
  92.                 Dialog_Show(playerid,ConfirmDisband,DIALOG_STYLE_MSGBOX,"Party Disband",string,"Sure","Cancel");
  93.             }
  94.             else SEM(playerid,"ERROR: Invalid party id!");
  95.         }
  96.         else SEM(playerid,"ERROR: You don't have privilege to use this command!");
  97.     }
  98.     else
  99.     {
  100.         SendClientMessage(playerid,-1,"You canceled the selection party menu!");
  101.     }
  102.     return 1;
  103. }
  104.  
  105. Dialog:ConfirmDisband(playerid, response, listitem, inputtext[])
  106. {
  107.     if(response)
  108.     {
  109.         foreach(new member : GroupMember(PlayerParty[listitem]))
  110.         {
  111.             new color = RGBAToInt(random(256),random(256),random(256),100);
  112.             PlayerInfo[member][Party] = NO_TEAM;
  113.             SetPlayerColor(member,color);
  114.             new string[150];
  115.             format(string,sizeof(string),"PARTY: {ffffff}Party disbanded by {ff0000}%s{ffffff}, you've been automatically kicked!",GetName(playerid));
  116.             SendClientMessage(member,COLOR_LIGHTBLUE,string);
  117.         }
  118.         Iter_Remove(Parties,listitem);
  119.         Group_Destroy(PlayerParty[listitem]);
  120.         SendClientMessage(playerid,COLOR_LIGHTBLUE,"PARTY: {ffffff}Disbanded!");
  121.     }
  122.     return 1;
  123. }
  124.  
  125. SSCANF:partymenu(string[])
  126. {
  127.     if(!strcmp(string,"create",true)) return 1;
  128.     else if(!strcmp(string,"make",true)) return 1;
  129.     else if(!strcmp(string,"add",true)) return 1;
  130.     else if(!strcmp(string,"color",true)) return 2;
  131.     else if(!strcmp(string,"colour",true)) return 2;
  132.     else if(!strcmp(string,"setcolor",true)) return 2;
  133.     else if(!strcmp(string,"setcolour",true)) return 2;
  134.     else if(!strcmp(string,"invite",true)) return 3;
  135.     else if(!strcmp(string,"setinvite",true)) return 3;
  136.     else if(!strcmp(string,"accept",true)) return 4;
  137.     else if(!strcmp(string,"kick",true)) return 5;
  138.     else if(!strcmp(string,"leader",true)) return 6;
  139.     else if(!strcmp(string,"setleader",true)) return 6;
  140.     else if(!strcmp(string,"disband",true)) return 7;
  141.     else if(!strcmp(string,"ban",true)) return 7;
  142.     else if(!strcmp(string,"list",true)) return 8;
  143.     else if(!strcmp(string,"members",true)) return 9;
  144.     return 0;
  145. }
  146.  
  147. YCMD:party(playerid,params[],help)
  148. {
  149.     new action,string[150];
  150.     if(sscanf(params,"k<partymenu>S()[150]",action,string)) return SEM(playerid,"USAGE: /party [create/color/invite/accept/kick/leader/disband/list/members]");
  151.     else
  152.     {
  153.         switch(action)
  154.         {
  155.             case 1:
  156.             {
  157.                 if(GetPlayerMoney(playerid) >= 30000)
  158.                 {
  159.                     new name[MAX_PARTY_NAME];
  160.                     if(PlayerInfo[playerid][Level] < 5) return SEM(playerid,"ERROR: You must be level 5 or higher to create team party!");
  161.                     if(PlayerInfo[playerid][Party] != NO_TEAM) return SEM(playerid,"ERROR: You are already in a party!");
  162.                     if(IsNull(string)) return SEM(playerid,"USAGE: /party create [name]");
  163.                     strmid(name,string,0,strlen(string),sizeof(name));
  164.                     if(CreateParty(playerid,name))
  165.                     {
  166.                         format(string,sizeof(string),"PARTY: {ffffff}You've created team party {ffff00}%s{ffffff}, you can also invite your friends by using /party invite!",name);
  167.                         SendClientMessage(playerid,COLOR_LIGHTBLUE,string);
  168.                         GivePlayerMoney(playerid,-30000);
  169.                     }
  170.                     else SEM(playerid,"ERROR: No free team party slot available!");
  171.                 }
  172.                 else SEM(playerid,"ERROR: You don't have enough money!");
  173.             }
  174.             case 2:
  175.             {
  176.                 if(GetPlayerMoney(playerid) >= 10000)
  177.                 {
  178.                     new red,green,blue;
  179.                     new partyid = PlayerInfo[playerid][Party];
  180.                     if(PartyInfo[partyid][Leader] != PlayerInfo[playerid][ID]) return SEM(playerid,"ERROR: You are not a party leader!");
  181.                     if(partyid == NO_TEAM) return SEM(playerid,"ERROR: You are not a member of any team party!");
  182.                     if(sscanf(string,"dD(255)D(255)",red,green,blue)) return SEM(playerid,"USAGE: /party color [red] [green] [blue]");
  183.                     SEM(playerid,"HINT: You can find any color RGB at {ffff00}http://jg-gta.com/rgb.html");
  184.                     PartyInfo[partyid][Color] = RGBAToInt(red,green,blue,255);
  185.                     GivePlayerMoney(playerid,-10000);
  186.                     foreach(new member : GroupMember(PlayerParty[partyid]))
  187.                     {
  188.                         SetPlayerColor(member,PartyInfo[partyid][Color]);
  189.                     }
  190.                     SendClientMessage(playerid,COLOR_LIGHTBLUE,"PARTY: {ffffff}You've changed the party colour!");
  191.                 }
  192.                 else SEM(playerid,"ERROR: You don't have enough money!");
  193.             }
  194.             case 3:
  195.             {
  196.                 new target;
  197.                 new partyid = PlayerInfo[playerid][Party];
  198.                 new count = Group_GetCount(PlayerParty[partyid]);
  199.                 if(PartyInfo[partyid][Leader] != PlayerInfo[playerid][ID]) return SEM(playerid,"ERROR: You are not a party leader!");
  200.                 if(sscanf(string,"u",target)) return SEM(playerid,"USAGE: /party invite [playerid/name]");
  201.                 if(target == INVALID_PLAYER_ID) return SEM(playerid,"ERROR: Invalid playerid!");
  202.                 if(partyid == NO_TEAM) return SEM(playerid,"ERROR: You are not a member of any team party!");
  203.                 if(PlayerInfo[target][Party] != NO_TEAM) return SEM(playerid,"ERROR: That player is already in a party!");
  204.                 if(count >= 5) return SEM(playerid,"ERROR: Party is full, you cannot invite more than 5 players!");
  205.                 PartyInvite[target] = partyid;
  206.                 format(string,sizeof(string),"PARTY: {ffffff}You've invited {ffff00}%s {ffffff}to join your team party!",GetName(target));
  207.                 SendClientMessage(playerid,COLOR_LIGHTBLUE,string);
  208.                 format(string,sizeof(string),"PARTY: {ffffff}You've been invited by {ffff00}%s {ffffff}to join {00ff00}%s",GetName(playerid),PartyInfo[partyid][Name]);
  209.                 SendClientMessage(target,COLOR_LIGHTBLUE,string);
  210.                 SendClientMessage(target,COLOR_ADMIN_WARNING,"HINT: {ffffff}Use command {00ffff}/party accept{ffffff} to accept invitation!");
  211.             }
  212.             case 4:
  213.             {
  214.                 new partyid = PartyInvite[playerid];
  215.                 if(partyid == NO_TEAM) return SEM(playerid,"ERROR: You are not invited to any team party!");
  216.                 if(PlayerInfo[playerid][Party] != NO_TEAM) return SEM(playerid,"ERROR: You are already in a party!");
  217.                 PlayerInfo[playerid][Party] = partyid;
  218.                 Group_SetPlayer(PlayerParty[partyid],playerid,true);
  219.                 SetPlayerColor(playerid,PartyInfo[partyid][Color]);
  220.                 format(string,sizeof(string),"PARTY: {ffffff}You've joined team party {00ff00}%s",PartyInfo[partyid][Name]);
  221.                 SendClientMessage(playerid,COLOR_LIGHTBLUE,string);
  222.                 format(string,sizeof(string),"PARTY: {ffff00}%s {ffffff}has joined the team party",GetName(playerid));
  223.                 foreach(new member : GroupMember(PlayerParty[partyid]))
  224.                 {
  225.                     SendClientMessage(member,COLOR_LIGHTBLUE,string);
  226.                 }
  227.             }
  228.             case 5:
  229.             {
  230.                 new target;
  231.                 new partyid = PlayerInfo[playerid][Party];
  232.                 new color = RGBAToInt(random(256),random(256),random(256),100);
  233.                 if(PartyInfo[partyid][Leader] != PlayerInfo[playerid][ID]) return SEM(playerid,"ERROR: You are not a party leader!");
  234.                 if(sscanf(string,"u",target)) return SEM(playerid,"USAGE: /party kick [playerid/name]");
  235.                 if(target == INVALID_PLAYER_ID) return SEM(playerid,"ERROR: Invalid playerid!");
  236.                 if(target == playerid) return SEM(playerid,"ERROR: You cannot kick yourself lol!");
  237.                 if(partyid == NO_TEAM) return SEM(playerid,"ERROR: You are not a member of any team party!");
  238.                 if(PlayerInfo[target][Party] != partyid) return SEM(playerid,"ERROR: That player is already in a party!");
  239.                 PlayerInfo[target][Party] = NO_TEAM;
  240.                 Group_SetPlayer(PlayerParty[partyid],target,false);
  241.                 SetPlayerColor(target,color);
  242.                 format(string,sizeof(string),"PARTY: {ffffff}You've kicked {ffff00}%s {ffffff}from your team party!",GetName(target));
  243.                 SendClientMessage(playerid,COLOR_LIGHTBLUE,string);
  244.                 format(string,sizeof(string),"PARTY: {ffffff}You've been kicked by {ffff00}%s {ffffff}from {00ff00}%s",GetName(playerid),PartyInfo[partyid][Name]);
  245.                 SendClientMessage(target,COLOR_LIGHTBLUE,string);
  246.             }
  247.             case 6:
  248.             {
  249.                 new target;
  250.                 new partyid = PlayerInfo[playerid][Party];
  251.                 if(PartyInfo[partyid][Leader] != PlayerInfo[playerid][ID]) return SEM(playerid,"ERROR: You are not a party leader!");
  252.                 if(sscanf(string,"u",target)) return SEM(playerid,"USAGE: /party leader [playerid/name]");
  253.                 if(target == INVALID_PLAYER_ID) return SEM(playerid,"ERROR: Invalid playerid!");
  254.                 if(partyid == NO_TEAM) return SEM(playerid,"ERROR: You are not a member of any team party!");
  255.                 if(PlayerInfo[target][Party] != partyid) return SEM(playerid,"ERROR: That player is not in the same team party!");
  256.                 PartyInfo[partyid][Leader] = PlayerInfo[target][ID];
  257.                 format(string,sizeof(string),"PARTY: {ffff00}You've set {ffff00}%s {ffffff}as the party leader",GetName(target));
  258.                 SendClientMessage(playerid,COLOR_LIGHTBLUE,string);
  259.                 SendClientMessage(target,COLOR_LIGHTBLUE,"PARTY: {ffffff}You've been promoted to be a party leader!");
  260.             }
  261.             case 7:
  262.             {
  263.                 new partyid = PlayerInfo[playerid][Party];
  264.                 if(PartyInfo[partyid][Leader] != PlayerInfo[playerid][ID]) return SEM(playerid,"ERROR: You are not a party leader!");
  265.                 if(partyid == NO_TEAM) return SEM(playerid,"ERROR: You are not a member of any team party!");
  266.                 if(IsNull(string)||strcmp(string,"confirm",true))
  267.                 {
  268.                     format(string,sizeof(string),"PARTY: {ffffff}You are about to disband your {ffff00}%s",PartyInfo[partyid][Name]);
  269.                     SendClientMessage(playerid,COLOR_LIGHTBLUE,string);
  270.                     SendClientMessage(playerid,COLOR_LIGHTBLUE,"HINT: {ffffff}Use command {ffff00}/party disband confirm{ffffff} to confirm disbanded!");
  271.                 }
  272.                 else
  273.                 {
  274.                     foreach(new member : GroupMember(PlayerParty[partyid]))
  275.                     {
  276.                         new color = RGBAToInt(random(256),random(256),random(256),100);
  277.                         PlayerInfo[member][Party] = NO_TEAM;
  278.                         SetPlayerColor(member,color);
  279.                         SendClientMessage(member,COLOR_LIGHTBLUE,"PARTY: {ffffff}Party disbanded, you've been automatically kicked!");
  280.                     }
  281.                     Iter_Remove(Parties,partyid);
  282.                     Group_Destroy(PlayerParty[partyid]);
  283.                 }
  284.             }
  285.             case 8:
  286.             {
  287.                 strcat(string,"ID\tName",sizeof(string));
  288.                 foreach(new partyid : Parties)
  289.                 {
  290.                     format(string,sizeof(string),"%s\n%d\t%s",string,partyid,PartyInfo[partyid][Name]);
  291.                 }
  292.                 Dialog_Show(playerid,PartyList,DIALOG_STYLE_TABLIST_HEADERS,"Current Team Party",string,"Disband","Close");
  293.             }
  294.             case 9:
  295.             {
  296.                 new partyid = PlayerInfo[playerid][Party];
  297.                 if(partyid == NO_TEAM) return SEM(playerid,"ERROR: You are not a member of any team party!");
  298.                 foreach(new i : Player)
  299.                 {
  300.                     SendClientMessage(playerid,-1,"----- PARTY MEMBERS -----");
  301.                     if(IsPlayerConnected(i) && partyid == PlayerInfo[i][Party])
  302.                     {
  303.                         format(string, sizeof(string), "[id:%d] %s",i,GetName(i));
  304.                         SEM(playerid,string);
  305.                     }
  306.                 }
  307.             }
  308.             default:SEM(playerid,"USAGE: /party [create/color/invite/accept/kick/leader/disband/list/members]");
  309.         }
  310.     }
  311.     return 1;
  312. }
  313.  
  314. YCMD:p(playerid,params[], help)
  315. {
  316.     new message[144],playername[MAX_PLAYER_NAME];
  317.     if(PlayerInfo[playerid][Party] == NO_TEAM) return SEM(playerid,"ERROR: You are not a member of any team party!");
  318.     if(IsNull(params)) return SEM(playerid,"USAGE: /(p)artychat [message]");
  319.     GetPlayerName(playerid,playername,MAX_PLAYER_NAME);
  320.     format(message,sizeof(message),"[PARTY] %s: {ffffff}%s",GetName(playerid),params);
  321.     SendPartyMessage(PlayerInfo[playerid][Party],message);
  322.     return 1;
  323. }
  324.  
  325. public OnPlayerDisconnect(playerid,reason)
  326. {
  327.     new partyid = PlayerInfo[playerid][Party];
  328.     if(PartyInfo[partyid][Leader])
  329.     {
  330.         foreach(new member : GroupMember(PlayerParty[partyid]))
  331.         {
  332.             new color = RGBAToInt(random(256),random(256),random(256),100);
  333.             PlayerInfo[member][Party] = NO_TEAM;
  334.             SetPlayerColor(member,color);
  335.             SendClientMessage(member,COLOR_LIGHTBLUE,"PARTY: {ffffff}Party disbanded, your leader left the server!");
  336.         }
  337.         Iter_Remove(Parties,partyid);
  338.         Group_Destroy(PlayerParty[partyid]);
  339.     }
  340.     else if(partyid)
  341.     {
  342.         partyid = NO_TEAM;
  343.         Group_SetPlayer(PlayerParty[partyid],partyid,false);
  344.     }
  345.     ResetPlayerParty(playerid);
  346.     return 1;
  347. }
  348.  
  349. public OnPlayerConnect(playerid)
  350. {
  351.     PlayerInfo[playerid][Party] = NO_TEAM;
  352.     PartyInvite[playerid] = 0;
  353.     return 1;
  354. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement