#include <a_samp>
#pragma tabsize 0
#define COLOR_WHITE 0xFFFFFFAA
#define COLOR_RED 0xAA3333AA
#define COLOR_GREEN 0x33AA33AA
#define COLOR_ORANGE 0xFF9900AA
#define COLOR_YELLOW 0xFFFF00AA
#define MAX_GANGS 32
#define MAX_GANG_NAME 16
#define MAX_GANG_MEMBERS 6
new gangNames[MAX_GANGS][MAX_GANG_NAME];
new gangInfo[MAX_GANGS][3]; //0-created,1-members,2-color
new playerGang[MAX_PLAYERS];
new gangMembers[MAX_GANGS][MAX_GANG_MEMBERS];
new gangInvite[MAX_PLAYERS];
new playerColors[100] = {
0xFF8C13FF,0xC715FFFF,0x20B2AAFF,0xDC143CFF,0x6495EDFF,0xf0e68cFF,0x778899FF,0xFF1493FF,0xF4A460FF,0xEE82EEFF,0xFFD720FF,
0x8b4513FF,0x4949A0FF,0x148b8bFF,0x14ff7fFF,0x556b2fFF,0x0FD9FAFF,0x10DC29FF,0x534081FF,0x0495CDFF,0xEF6CE8FF,0xBD34DAFF,
0x247C1BFF,0x0C8E5DFF,0x635B03FF,0xCB7ED3FF,0x65ADEBFF,0x5C1ACCFF,0xF2F853FF,0x11F891FF,0x7B39AAFF,0x53EB10FF,0x54137DFF,
0x275222FF,0xF09F5BFF,0x3D0A4FFF,0x22F767FF,0xD63034FF,0x9A6980FF,0xDFB935FF,0x3793FAFF,0x90239DFF,0xE9AB2FFF,0xAF2FF3FF,
0x057F94FF,0xB98519FF,0x388EEAFF,0x028151FF,0xA55043FF,0x0DE018FF,0x93AB1CFF,0x95BAF0FF,0x369976FF,0x18F71FFF,0x4B8987FF,
0x491B9EFF,0x829DC7FF,0xBCE635FF,0xCEA6DFFF,0x20D4ADFF,0x2D74FDFF,0x3C1C0DFF,0x12D6D4FF,0x48C000FF,0x2A51E2FF,0xE3AC12FF,
0xFC42A8FF,0x2FC827FF,0x1A30BFFF,0xB740C2FF,0x42ACF5FF,0x2FD9DEFF,0xFAFB71FF,0x05D1CDFF,0xC471BDFF,0x94436EFF,0xC1F7ECFF,
0xCE79EEFF,0xBD1EF2FF,0x93B7E4FF,0x3214AAFF,0x184D3BFF,0xAE4B99FF,0x7E49D7FF,0x4C436EFF,0xFA24CCFF,0xCE76BEFF,0xA04E0AFF,
0x9F945CFF,0xDCDE3DFF,0x10C9C5FF,0x70524DFF,0x0BE472FF,0x8A2CD7FF,0x6152C2FF,0xCF72A9FF,0xE59338FF,0xEEDC2DFF,0xD8C762FF,
0x3FE65CFF
};
forward PlayerLeaveGang(playerid);
public OnFilterScriptInit()
{
print(\"\\n--------------------------------------\");
print(\" GangInvite Filterscript By Nate660 (2007)\");
print(\"--------------------------------------\\n\");
return 1;
}
public OnFilterScriptExit()
{
return 1;
}
public PlayerLeaveGang(playerid) {
new string[256];
new playername[MAX_PLAYER_NAME];
new gangnum = playerGang[playerid];
if(gangnum > 0) {
for(new i = 0; i < gangInfo[gangnum][1]; i++) {
if(gangMembers[gangnum]==playerid) {
//One less gang member
gangInfo[gangnum][1]--;
for(new j = i; j < gangInfo[gangnum][1]; j++)
{
gangMembers[gangnum][j]=gangMembers[gangnum][j+1];
}
//Disband gang if no more members
if(gangInfo[gangnum][1]<1) {
gangInfo[gangnum][0]=0;
gangInfo[gangnum][1]=0;
}
//Notify other members
for(new j = 0; j < gangInfo[gangnum][1]; j++) {
GetPlayerName(playerid, playername, MAX_PLAYER_NAME);
format(string, sizeof(string),\"%s has quit your gang.\", playername);
SendClientMessage(gangMembers[gangnum][j], COLOR_ORANGE, string);
}
format(string, sizeof(string),\"You have quit the gang \'%s\' (id: %d)\", gangNames[gangnum], gangnum);
SendClientMessage(playerid, COLOR_ORANGE, string);
playerGang[playerid]=0;
return;
}
}
} else {
SendClientMessage(playerid, COLOR_RED, \"You are not in a gang.\");
}
}
public OnPlayerCommandText(playerid,cmdtext[])
{
new string[256];
// Define the senders name string
new sendername[MAX_PLAYER_NAME];
// Define the targets name string
new giveplayer[MAX_PLAYER_NAME];
// Define the command string
new cmd[256];
// Deifine the temp string
new tmp[256];
// Define misc variables
new giveplayerid,idx;
// Command equals to command text at the index of the idx variable
cmd = strtok(cmdtext, idx);
if(strcmp(cmd, \"/gang\", true) == 0) {
new gangcmd, gangnum;
tmp = strtok(cmdtext, idx);
if(!strlen(tmp)) {
SendClientMessage(playerid, COLOR_WHITE, \"USAGE: /gang [create/join/quit] [name/number]\");
return 1;
}
giveplayerid = strval(tmp);
if(strcmp(tmp, \"create\", true)==0)
gangcmd = 1;
else if(strcmp(tmp, \"join\", true)==0)
gangcmd = 2;
else if(strcmp(tmp, \"invite\", true)==0)
gangcmd = 3;
else if(strcmp(tmp, \"quit\", true)==0)
gangcmd = 4;
tmp = strtok(cmdtext, idx);
if(gangcmd < 4 && !strlen(tmp)) {
if(gangcmd==0)
SendClientMessage(playerid, COLOR_WHITE, \"USAGE: /gang [create/join/invite/quit] [name/number]\");
else if(gangcmd==1)
SendClientMessage(playerid, COLOR_WHITE, \"USAGE: /gang [create] [name]\");
else if(gangcmd==2)
SendClientMessage(playerid, COLOR_WHITE, \"USAGE: /gang [join] [number]\");
else if(gangcmd==3)
SendClientMessage(playerid, COLOR_WHITE, \"USAGE: /gang [invite] [playerID]\");
return 1;
}
//Create Gang//
if(gangcmd==1) {
if(playerGang[playerid]>0) {
SendClientMessage(playerid, COLOR_RED, \"You are already in a gang!\");
return 1;
}
for(new i = 1; i < MAX_GANGS; i++) {
if(gangInfo[0]==0) {
//name gang
format(gangNames, MAX_GANG_NAME, \"%s\", tmp);
//Gang exists
gangInfo[0]=1;
//There is one member
gangInfo[1]=1;
//Gang color is player\'s color
gangInfo[2]=playerColors[playerid];
//Player is the first gang member
gangMembers[0] = playerid;
format(string, sizeof(string),\"You have created the gang \'%s\' (id: %d)\", gangNames, i);
SendClientMessage(playerid, COLOR_GREEN, string);
playerGang[playerid]=i;
return 1;
}
}
return 1;
//Join Gang//
} else if (gangcmd==2) {
gangnum = strval(tmp);
// if(playerGang[playerid]>0) {
// SendClientMessage(playerid, COLOR_RED, \"You are already in a gang!\");
// return 1;
// }
if(gangInfo[gangnum][0]==0) {
SendClientMessage(playerid, COLOR_RED, \"No such gang exists!\");
return 1;
}
if(gangInvite[playerid]!=gangnum) {
SendClientMessage(playerid, COLOR_RED, \"You need to be invited to the gang to join.\");
return 1;
}
// for(new i = 0; i < MAX_GANG_MEMBERS; i++) {
// if(gangMembers[gangnum] > 0) {
if(gangInfo[gangnum][1] < MAX_GANG_MEMBERS) {
new i = gangInfo[gangnum][1];
gangMembers[gangnum] = playerid;
GetPlayerName(playerid, sendername, MAX_PLAYER_NAME);
for(new j = 0; j < gangInfo[gangnum][1]; j++) {
format(string, sizeof(string),\"%s has joined your gang.\", sendername);
SendClientMessage(gangMembers[gangnum][j], COLOR_ORANGE, string);
}
gangInfo[gangnum][1]++;
playerGang[playerid] = gangnum;
SetPlayerColor(playerid,gangInfo[gangnum][2]);
format(string, sizeof(string),\"You have joined the gang \'%s\' (id: %d)\", gangNames[gangnum], gangnum);
SendClientMessage(playerid, COLOR_GREEN, string);
return 1;
}
// }
SendClientMessage(playerid, COLOR_RED, \"That gang is full.\");
return 1;
//Invite to Gang//
} else if (gangcmd==3) {
giveplayerid = strval(tmp);
if(playerGang[playerid]==0) {
SendClientMessage(playerid, COLOR_RED, \"You are not in a gang!\");
return 1;
}
// if(gangMembers[playerGang[playerid]][0]!=playerid) {
// SendClientMessage(playerid, COLOR_RED, \"You need to be the gang leader to send an invite.\");
// return 1;
// }
if(IsPlayerConnected(giveplayerid)) {
GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
GetPlayerName(playerid, sendername, sizeof(sendername));
format(string, sizeof(string),\"You have sent a gang invite to %s.\", giveplayer);
SendClientMessage(playerid, COLOR_GREEN, string);
format(string, sizeof(string),\"You have recieved a gang invite from %s to \'%s\' (id: %d)\", sendername, gangNames[playerGang[playerid]],playerGang[playerid]);
SendClientMessage(giveplayerid, COLOR_GREEN, string);
gangInvite[giveplayerid]=playerGang[playerid];
} else
SendClientMessage(playerid, COLOR_RED, \"No such player exists!\");
//Leave Gang//
} else if (gangcmd==4) {
PlayerLeaveGang(playerid);
}
return 1;
}
//------------------- /ganginfo
if(strcmp(cmd, \"/ganginfo\", true) == 0) {
new gangnum;
tmp = strtok(cmdtext, idx);
if(!strlen(tmp) && playerGang[playerid]==0) {
SendClientMessage(playerid, COLOR_WHITE, \"USAGE: /ganginfo [number]\");
return 1;
} else if (!strlen(tmp))
gangnum = playerGang[playerid];
else
gangnum = strval(tmp);
if(gangInfo[gangnum][0]==0) {
SendClientMessage(playerid, COLOR_RED, \"No such gang exists!\");
return 1;
}
format(string, sizeof(string),\"\'%s\' Gang Members (id: %d)\", gangNames[gangnum], gangnum);
SendClientMessage(playerid, COLOR_GREEN, string);
for(new i = 0; i < gangInfo[gangnum][1]; i++) {
GetPlayerName(gangMembers[gangnum], giveplayer, sizeof(giveplayer));
format(string, sizeof(string),\"%s (%d)\", giveplayer, gangMembers[gangnum]);
SendClientMessage(playerid, COLOR_YELLOW, string);
}
return 1;
}
//------------------- /gangs
if(strcmp(cmd, \"/gangs\", true) == 0)
{
new x;
SendClientMessage(playerid, COLOR_GREEN, \"Current Gangs:\");
for(new i=0; i < MAX_GANGS; i++) {
if(gangInfo[0]==1) {
format(string, sizeof(string), \"%s%s(%d) - %d members\", string,gangNames,i,gangInfo[1]);
x++;
if(x > 2) {
SendClientMessage(playerid, COLOR_YELLOW, string);
x = 0;
format(string, sizeof(string), \"\");
} else {
format(string, sizeof(string), \"%s, \", string);
}
}
}
if(x <= 2 && x > 0) {
string[strlen(string)-2] = \'.\';
SendClientMessage(playerid, COLOR_YELLOW, string);
}
return 1;
}
return 0;
}
strtok(const string[], &index)
{
new length = strlen(string);
while ((index < length) && (string[index] <= \' \'))
{
index++;
}
new offset = index;
new result[20];
while ((index < length) && (string[index] > \' \') && ((index - offset) < (sizeof(result) - 1)))
{
result[index - offset] = string[index];
index++;
}
result[index - offset] = EOS;
return result;
}