Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <easyDialog>
- #include <sscanf2>
- #include <YSI\y_iterate>
- #include <YSI\y_groups>
- #include <YSI\y_commands>
- #define COLOR_SYNTAX_WARNING 0xAFAFAFAA // color _ grey
- #define COLOR_ADMIN_WARNING 0xFFFF0000 // color _ yellow
- #define COLOR_LIGHTBLUE 0x33CCFFAA
- #define MAX_PARTY_NAME 32
- #define MAX_PARTIES 5
- #define RGBAToInt(%0,%1,%2,%3) ((16777216 * (%0)) + (65536 * (%1)) + (256 * (%2)) + (%3))
- #define IsNull(%1) ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
- #define SEM(%0,%1) SendClientMessage(%0, COLOR_SYNTAX_WARNING, %1)
- GetName(target)
- {
- new name[MAX_PLAYER_NAME + 1];
- GetPlayerName(target, name, sizeof name);
- return name;
- }
- enum pinfo
- {
- ID,
- Party,
- Level
- }
- new PlayerInfo[MAX_PLAYERS][pinfo];
- enum party_info
- {
- ID,
- Name[MAX_PARTY_NAME],
- Leader,
- Color
- };
- new PartyInfo[MAX_PARTIES][party_info];
- new PartyInvite[MAX_PLAYERS];
- new Group:PlayerParty[MAX_PARTIES];
- new Iterator:Parties<MAX_PARTIES>;
- bool:CreateParty(playerid,name[])
- {
- new id = Iter_Free(Parties);
- if(id == -1) return false;
- if(Iter_Contains(Parties,id)) return false;
- PartyInfo[id][ID] = id;
- strmid(PartyInfo[id][Name],name,0,strlen(name),MAX_PARTY_NAME);
- PartyInfo[id][Color] = RGBAToInt(random(256),random(256),random(256),100);
- PartyInfo[id][Leader] = PlayerInfo[playerid][ID];
- PlayerInfo[playerid][Party] = id;
- Iter_Add(Parties,id);
- PlayerParty[id] = Group_Create(PartyInfo[id][Name]);
- Group_SetPlayer(PlayerParty[id],playerid,true);
- SetPlayerColor(playerid,PartyInfo[playerid][Color]);
- return true;
- }
- ResetPlayerParty(playerid)
- {
- new partyid = PlayerInfo[playerid][Party];
- PartyInfo[partyid][ID] = 0;
- PartyInfo[partyid][Name] = 0;
- PartyInfo[partyid][Leader] = 0;
- PartyInfo[partyid][Color] = 0;
- return 0;
- }
- SendPartyMessage(partyid,message[])
- {
- foreach(new member : GroupMember(PlayerParty[partyid]))
- {
- SendClientMessage(member,PartyInfo[partyid][Color],message);
- }
- return 1;
- }
- Dialog:PartyList(playerid, response, listitem, inputtext[])
- {
- if(response)
- {
- if(IsPlayerAdmin(playerid))
- {
- if(Iter_Contains(Parties,listitem))
- {
- new string[150];
- 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]);
- Dialog_Show(playerid,ConfirmDisband,DIALOG_STYLE_MSGBOX,"Party Disband",string,"Sure","Cancel");
- }
- else SEM(playerid,"ERROR: Invalid party id!");
- }
- else SEM(playerid,"ERROR: You don't have privilege to use this command!");
- }
- else
- {
- SendClientMessage(playerid,-1,"You canceled the selection party menu!");
- }
- return 1;
- }
- Dialog:ConfirmDisband(playerid, response, listitem, inputtext[])
- {
- if(response)
- {
- foreach(new member : GroupMember(PlayerParty[listitem]))
- {
- new color = RGBAToInt(random(256),random(256),random(256),100);
- PlayerInfo[member][Party] = NO_TEAM;
- SetPlayerColor(member,color);
- new string[150];
- format(string,sizeof(string),"PARTY: {ffffff}Party disbanded by {ff0000}%s{ffffff}, you've been automatically kicked!",GetName(playerid));
- SendClientMessage(member,COLOR_LIGHTBLUE,string);
- }
- Iter_Remove(Parties,listitem);
- Group_Destroy(PlayerParty[listitem]);
- SendClientMessage(playerid,COLOR_LIGHTBLUE,"PARTY: {ffffff}Disbanded!");
- }
- return 1;
- }
- SSCANF:partymenu(string[])
- {
- if(!strcmp(string,"create",true)) return 1;
- else if(!strcmp(string,"make",true)) return 1;
- else if(!strcmp(string,"add",true)) return 1;
- else if(!strcmp(string,"color",true)) return 2;
- else if(!strcmp(string,"colour",true)) return 2;
- else if(!strcmp(string,"setcolor",true)) return 2;
- else if(!strcmp(string,"setcolour",true)) return 2;
- else if(!strcmp(string,"invite",true)) return 3;
- else if(!strcmp(string,"setinvite",true)) return 3;
- else if(!strcmp(string,"accept",true)) return 4;
- else if(!strcmp(string,"kick",true)) return 5;
- else if(!strcmp(string,"leader",true)) return 6;
- else if(!strcmp(string,"setleader",true)) return 6;
- else if(!strcmp(string,"disband",true)) return 7;
- else if(!strcmp(string,"ban",true)) return 7;
- else if(!strcmp(string,"list",true)) return 8;
- else if(!strcmp(string,"members",true)) return 9;
- return 0;
- }
- YCMD:party(playerid,params[],help)
- {
- new action,string[150];
- if(sscanf(params,"k<partymenu>S()[150]",action,string)) return SEM(playerid,"USAGE: /party [create/color/invite/accept/kick/leader/disband/list/members]");
- else
- {
- switch(action)
- {
- case 1:
- {
- if(GetPlayerMoney(playerid) >= 30000)
- {
- new name[MAX_PARTY_NAME];
- if(PlayerInfo[playerid][Level] < 5) return SEM(playerid,"ERROR: You must be level 5 or higher to create team party!");
- if(PlayerInfo[playerid][Party] != NO_TEAM) return SEM(playerid,"ERROR: You are already in a party!");
- if(IsNull(string)) return SEM(playerid,"USAGE: /party create [name]");
- strmid(name,string,0,strlen(string),sizeof(name));
- if(CreateParty(playerid,name))
- {
- 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);
- SendClientMessage(playerid,COLOR_LIGHTBLUE,string);
- GivePlayerMoney(playerid,-30000);
- }
- else SEM(playerid,"ERROR: No free team party slot available!");
- }
- else SEM(playerid,"ERROR: You don't have enough money!");
- }
- case 2:
- {
- if(GetPlayerMoney(playerid) >= 10000)
- {
- new red,green,blue;
- new partyid = PlayerInfo[playerid][Party];
- if(PartyInfo[partyid][Leader] != PlayerInfo[playerid][ID]) return SEM(playerid,"ERROR: You are not a party leader!");
- if(partyid == NO_TEAM) return SEM(playerid,"ERROR: You are not a member of any team party!");
- if(sscanf(string,"dD(255)D(255)",red,green,blue)) return SEM(playerid,"USAGE: /party color [red] [green] [blue]");
- SEM(playerid,"HINT: You can find any color RGB at {ffff00}http://jg-gta.com/rgb.html");
- PartyInfo[partyid][Color] = RGBAToInt(red,green,blue,255);
- GivePlayerMoney(playerid,-10000);
- foreach(new member : GroupMember(PlayerParty[partyid]))
- {
- SetPlayerColor(member,PartyInfo[partyid][Color]);
- }
- SendClientMessage(playerid,COLOR_LIGHTBLUE,"PARTY: {ffffff}You've changed the party colour!");
- }
- else SEM(playerid,"ERROR: You don't have enough money!");
- }
- case 3:
- {
- new target;
- new partyid = PlayerInfo[playerid][Party];
- new count = Group_GetCount(PlayerParty[partyid]);
- if(PartyInfo[partyid][Leader] != PlayerInfo[playerid][ID]) return SEM(playerid,"ERROR: You are not a party leader!");
- if(sscanf(string,"u",target)) return SEM(playerid,"USAGE: /party invite [playerid/name]");
- if(target == INVALID_PLAYER_ID) return SEM(playerid,"ERROR: Invalid playerid!");
- if(partyid == NO_TEAM) return SEM(playerid,"ERROR: You are not a member of any team party!");
- if(PlayerInfo[target][Party] != NO_TEAM) return SEM(playerid,"ERROR: That player is already in a party!");
- if(count >= 5) return SEM(playerid,"ERROR: Party is full, you cannot invite more than 5 players!");
- PartyInvite[target] = partyid;
- format(string,sizeof(string),"PARTY: {ffffff}You've invited {ffff00}%s {ffffff}to join your team party!",GetName(target));
- SendClientMessage(playerid,COLOR_LIGHTBLUE,string);
- format(string,sizeof(string),"PARTY: {ffffff}You've been invited by {ffff00}%s {ffffff}to join {00ff00}%s",GetName(playerid),PartyInfo[partyid][Name]);
- SendClientMessage(target,COLOR_LIGHTBLUE,string);
- SendClientMessage(target,COLOR_ADMIN_WARNING,"HINT: {ffffff}Use command {00ffff}/party accept{ffffff} to accept invitation!");
- }
- case 4:
- {
- new partyid = PartyInvite[playerid];
- if(partyid == NO_TEAM) return SEM(playerid,"ERROR: You are not invited to any team party!");
- if(PlayerInfo[playerid][Party] != NO_TEAM) return SEM(playerid,"ERROR: You are already in a party!");
- PlayerInfo[playerid][Party] = partyid;
- Group_SetPlayer(PlayerParty[partyid],playerid,true);
- SetPlayerColor(playerid,PartyInfo[partyid][Color]);
- format(string,sizeof(string),"PARTY: {ffffff}You've joined team party {00ff00}%s",PartyInfo[partyid][Name]);
- SendClientMessage(playerid,COLOR_LIGHTBLUE,string);
- format(string,sizeof(string),"PARTY: {ffff00}%s {ffffff}has joined the team party",GetName(playerid));
- foreach(new member : GroupMember(PlayerParty[partyid]))
- {
- SendClientMessage(member,COLOR_LIGHTBLUE,string);
- }
- }
- case 5:
- {
- new target;
- new partyid = PlayerInfo[playerid][Party];
- new color = RGBAToInt(random(256),random(256),random(256),100);
- if(PartyInfo[partyid][Leader] != PlayerInfo[playerid][ID]) return SEM(playerid,"ERROR: You are not a party leader!");
- if(sscanf(string,"u",target)) return SEM(playerid,"USAGE: /party kick [playerid/name]");
- if(target == INVALID_PLAYER_ID) return SEM(playerid,"ERROR: Invalid playerid!");
- if(target == playerid) return SEM(playerid,"ERROR: You cannot kick yourself lol!");
- if(partyid == NO_TEAM) return SEM(playerid,"ERROR: You are not a member of any team party!");
- if(PlayerInfo[target][Party] != partyid) return SEM(playerid,"ERROR: That player is already in a party!");
- PlayerInfo[target][Party] = NO_TEAM;
- Group_SetPlayer(PlayerParty[partyid],target,false);
- SetPlayerColor(target,color);
- format(string,sizeof(string),"PARTY: {ffffff}You've kicked {ffff00}%s {ffffff}from your team party!",GetName(target));
- SendClientMessage(playerid,COLOR_LIGHTBLUE,string);
- format(string,sizeof(string),"PARTY: {ffffff}You've been kicked by {ffff00}%s {ffffff}from {00ff00}%s",GetName(playerid),PartyInfo[partyid][Name]);
- SendClientMessage(target,COLOR_LIGHTBLUE,string);
- }
- case 6:
- {
- new target;
- new partyid = PlayerInfo[playerid][Party];
- if(PartyInfo[partyid][Leader] != PlayerInfo[playerid][ID]) return SEM(playerid,"ERROR: You are not a party leader!");
- if(sscanf(string,"u",target)) return SEM(playerid,"USAGE: /party leader [playerid/name]");
- if(target == INVALID_PLAYER_ID) return SEM(playerid,"ERROR: Invalid playerid!");
- if(partyid == NO_TEAM) return SEM(playerid,"ERROR: You are not a member of any team party!");
- if(PlayerInfo[target][Party] != partyid) return SEM(playerid,"ERROR: That player is not in the same team party!");
- PartyInfo[partyid][Leader] = PlayerInfo[target][ID];
- format(string,sizeof(string),"PARTY: {ffff00}You've set {ffff00}%s {ffffff}as the party leader",GetName(target));
- SendClientMessage(playerid,COLOR_LIGHTBLUE,string);
- SendClientMessage(target,COLOR_LIGHTBLUE,"PARTY: {ffffff}You've been promoted to be a party leader!");
- }
- case 7:
- {
- new partyid = PlayerInfo[playerid][Party];
- if(PartyInfo[partyid][Leader] != PlayerInfo[playerid][ID]) return SEM(playerid,"ERROR: You are not a party leader!");
- if(partyid == NO_TEAM) return SEM(playerid,"ERROR: You are not a member of any team party!");
- if(IsNull(string)||strcmp(string,"confirm",true))
- {
- format(string,sizeof(string),"PARTY: {ffffff}You are about to disband your {ffff00}%s",PartyInfo[partyid][Name]);
- SendClientMessage(playerid,COLOR_LIGHTBLUE,string);
- SendClientMessage(playerid,COLOR_LIGHTBLUE,"HINT: {ffffff}Use command {ffff00}/party disband confirm{ffffff} to confirm disbanded!");
- }
- else
- {
- foreach(new member : GroupMember(PlayerParty[partyid]))
- {
- new color = RGBAToInt(random(256),random(256),random(256),100);
- PlayerInfo[member][Party] = NO_TEAM;
- SetPlayerColor(member,color);
- SendClientMessage(member,COLOR_LIGHTBLUE,"PARTY: {ffffff}Party disbanded, you've been automatically kicked!");
- }
- Iter_Remove(Parties,partyid);
- Group_Destroy(PlayerParty[partyid]);
- }
- }
- case 8:
- {
- strcat(string,"ID\tName",sizeof(string));
- foreach(new partyid : Parties)
- {
- format(string,sizeof(string),"%s\n%d\t%s",string,partyid,PartyInfo[partyid][Name]);
- }
- Dialog_Show(playerid,PartyList,DIALOG_STYLE_TABLIST_HEADERS,"Current Team Party",string,"Disband","Close");
- }
- case 9:
- {
- new partyid = PlayerInfo[playerid][Party];
- if(partyid == NO_TEAM) return SEM(playerid,"ERROR: You are not a member of any team party!");
- foreach(new i : Player)
- {
- SendClientMessage(playerid,-1,"----- PARTY MEMBERS -----");
- if(IsPlayerConnected(i) && partyid == PlayerInfo[i][Party])
- {
- format(string, sizeof(string), "[id:%d] %s",i,GetName(i));
- SEM(playerid,string);
- }
- }
- }
- default:SEM(playerid,"USAGE: /party [create/color/invite/accept/kick/leader/disband/list/members]");
- }
- }
- return 1;
- }
- YCMD:p(playerid,params[], help)
- {
- new message[144],playername[MAX_PLAYER_NAME];
- if(PlayerInfo[playerid][Party] == NO_TEAM) return SEM(playerid,"ERROR: You are not a member of any team party!");
- if(IsNull(params)) return SEM(playerid,"USAGE: /(p)artychat [message]");
- GetPlayerName(playerid,playername,MAX_PLAYER_NAME);
- format(message,sizeof(message),"[PARTY] %s: {ffffff}%s",GetName(playerid),params);
- SendPartyMessage(PlayerInfo[playerid][Party],message);
- return 1;
- }
- public OnPlayerDisconnect(playerid,reason)
- {
- new partyid = PlayerInfo[playerid][Party];
- if(PartyInfo[partyid][Leader])
- {
- foreach(new member : GroupMember(PlayerParty[partyid]))
- {
- new color = RGBAToInt(random(256),random(256),random(256),100);
- PlayerInfo[member][Party] = NO_TEAM;
- SetPlayerColor(member,color);
- SendClientMessage(member,COLOR_LIGHTBLUE,"PARTY: {ffffff}Party disbanded, your leader left the server!");
- }
- Iter_Remove(Parties,partyid);
- Group_Destroy(PlayerParty[partyid]);
- }
- else if(partyid)
- {
- partyid = NO_TEAM;
- Group_SetPlayer(PlayerParty[partyid],partyid,false);
- }
- ResetPlayerParty(playerid);
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- PlayerInfo[playerid][Party] = NO_TEAM;
- PartyInvite[playerid] = 0;
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement