PHP код:
CMD:gang(playerid,params[]) {
new tmp[256], tmp2[256], Index; tmp = strtok(params,Index), tmp2 = strtok(params,Index);
if(!strlen(tmp)) return SendClientMessage(playerid, PlayerColors[random(200)], "USE: /gang [create/invite/join/leave/stats/list]");
//---- Create a Gang
if(strcmp(tmp, "create", true) == 0)
{
if(!strlen(tmp2)) return SendClientMessage(playerid, PlayerColors[random(200)], "USE: /gang create [GangName]");
if(strlen(tmp2) < 3 || strlen(tmp2) > 15) {
return SendClientMessage(playerid, PlayerColors[random(200)], "Gang name must be between 3 and 15 characters");
}
if(PlayerInfo[playerid][gang] != 0)
{
return SendClientMessage(playerid, PlayerColors[random(200)], "You must leave your gang before make a new one. /gang leave");
}
//Remove Inactive Gangs
if(GANG_NUMBER >= MAX_GANG)
{
new string[128];
new file[30];
new name[MAX_PLAYER_NAME];
for(new i = 0; i <= GANG_NUMBER; i++)
{
format(file, sizeof(file), GANG_FILE, i);
if(dini_Exists(file) && dini_Int(file,"GANG_MEMBERS") <= 1)
{
dini_Remove(file);
format(string, sizeof(string), "Gang Removed: ID:%d, Members: %d, Name: %s", i, GangInfo[i][GANG_MEMBERS], GangInfo[i][GANG_NAME]);
SendClientMessage(playerid, PlayerColors[random(200)], string);
format(string, sizeof(string), "The gang %s has been removed", GangInfo[i][GANG_NAME]);
SendClientMessageToAll(PlayerColors[random(200)], string);
for(new p; p < MAX_PLAYERS; p++)
{
if(PlayerInfo[p][gang] == i && IsPlayerConnected(p))
{
GetPlayerName(p, name, sizeof(name));
DOF2_SetInt(DOF2_File(name), "Gang", 0);
PlayerInfo[p][gang] = 0;
}
}
}
}
}
new gangid = 0;
for(new i; i < GANG_NUMBER; i++)
{
new file[100];
format(file, sizeof(file), GANG_FILE, i);
if(dini_Exists(file))
{
new gname[15];
strcat(gname, dini_Get(file, "GANG_NAME"),15);
if(strfind(tmp2, gname, true) == 0)
{
return SendClientMessage(playerid, PlayerColors[random(200)], "There is already a gang with the same name");
}
}
else if(!dini_Exists(file) && i != 0) gangid = i;
}
if(gangid == 0) {
GANG_NUMBER++;
gangid = GANG_NUMBER;
}
dini_IntSet(CFG,"GANG_NUMBER",GANG_NUMBER);
new gfile[100];
format(gfile, sizeof(gfile), GANG_FILE, gangid);
dini_Create(gfile);
format(GangInfo[gangid][GANG_NAME], sizeof(tmp2), "%s", tmp2);
dini_Set(gfile, "GANG_NAME", GangInfo[gangid][GANG_NAME]);
dini_IntSet(gfile, "GANG_ID", gangid);
dini_IntSet(gfile,"GANG_MEMBERS",0);
GangInfo[gangid][GANG_ID] = gangid;
GangInfo[gangid][GANG_MEMBERS] = 0;
GangInfo[gangid][GANG_COLOR] = PlayerColors[gangid];
new string[128];
format(string, sizeof(string), "Gang Created. Name: %s, ID: %d", GangInfo[gangid][GANG_NAME], GangInfo[gangid][GANG_ID]);
SendClientMessage(playerid, PlayerColors[random(200)], string);
JoinGang(playerid, gangid);
return 1;
}
//---- Invite
if(strcmp(tmp, "invite", true) == 0)
{
if(!strlen(tmp2)) return SendClientMessage(playerid, PlayerColors[random(200)], "USE: /gang invite [ID]");
if(PlayerInfo[playerid][gang] == 0)
{
return SendClientMessage(playerid, PlayerColors[random(200)], "You are not in a gang");
}
if(GangInfo[PlayerInfo[playerid][gang]][GANG_MEMBERS] > 14)
{
return SendClientMessage(playerid, PlayerColors[random(200)], "Has reached the maximum number of members (15) for this gang");
}
new id = strval(tmp2);
if(!IsPlayerConnected(id)) return SendClientMessage(playerid, PlayerColors[random(200)], "Invalid ID");
new name[MAX_PLAYER_NAME];
new name1[MAX_PLAYER_NAME];
GetPlayerName(id, name, sizeof(name));
GetPlayerName(playerid, name1, sizeof(name1));
invited[id] = PlayerInfo[playerid][gang];
new string[256];
format(string, sizeof(string), "You have been invited by %s to join in the gang %s. /gang join", name1, GangInfo[PlayerInfo[playerid][gang]][GANG_NAME]);
SendClientMessage(id, PlayerColors[random(200)], string);
format(string, sizeof(string), "You invited %s to join in your gang", name);
SendClientMessage(playerid, PlayerColors[random(200)], string);
return 1;
}
//---- Join Gang
if(strcmp(tmp, "join", true) == 0)
{
if(PlayerInfo[playerid][gang] != 0) return SendClientMessage(playerid, PlayerColors[random(200)], "You are already in a gang.");
if(invited[playerid] == 0) return SendClientMessage(playerid, PlayerColors[random(200)], "You have not been invited to join that gang.");
JoinGang(playerid, invited[playerid]);
return 1;
}
//---- Leave Gang
if(strcmp(tmp, "leave", true) == 0)
{
if(PlayerInfo[playerid][gang] == 1){
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
DOF2_SetInt(DOF2_File(name), "Gang", 0);
PlayerInfo[playerid][gang] = 0;
if(PlayerInfo[playerid][gang] == 0)
{
return SendClientMessage(playerid, PlayerColors[random(200)], "You are not in a gang");
}
}
LeaveGang(playerid, PlayerInfo[playerid][gang]);
return 1;
}
//---- List
if(strcmp(tmp, "list", true) == 0)
{
new string[256];
new file[100];
new string2[256];
format(string, sizeof(string), "");
for(new i = 0; i <= GANG_NUMBER; i++)
{
format(file, sizeof(file), GANG_FILE, i);
if(dini_Exists(file)) {
format(string2, sizeof(string2), "%s,", GangInfo[i][GANG_NAME]);
format(string, sizeof(string), "%s %s", string, string2);
}
}
SendClientMessage(playerid, PlayerColors[random(200)], string);
return 1;
}
//---- Stats
if(strcmp(tmp, "stats", true) == 0)
{
if(PlayerInfo[playerid][gang] == 0)
{
return SendClientMessage(playerid, PlayerColors[random(200)], "You are not in a gang");
}
new gangid = PlayerInfo[playerid][gang];
new string[128];
GangInfo[gangid][GANG_NZONE] = 0;
for(new i = 0; i <= ZONE_NUMBER; i++)
{
new SplitDiv[99][MAX_ZONE];
new tmp3[256];
new zoneids[5];
valstr(zoneids,i);
tmp3 = dini_Get(ZONE_FILE,zoneids);
split(tmp3, SplitDiv, ',');
if(dini_Exists(ZONE_FILE) && GangInfo[gangid][GANG_ID] == strval(SplitDiv[0])) GangInfo[gangid][GANG_NZONE]++;
}
format(string, sizeof(string), "ID: %d", gangid);
SendClientMessage(playerid, PlayerColors[random(200)], string);
format(string, sizeof(string), "Gang Name: %s", GangInfo[gangid][GANG_NAME]);
SendClientMessage(playerid, PlayerColors[random(200)], string);
format(string, sizeof(string), "Members: %d", GangInfo[gangid][GANG_MEMBERS]);
SendClientMessage(playerid, PlayerColors[random(200)], string);
format(string, sizeof(string), "Number of Gang Zones: %d", GangInfo[gangid][GANG_NZONE]);
SendClientMessage(playerid, PlayerColors[random(200)], string);
return 1;
}
//---- Delete Inactive
if(strcmp(tmp, "di", true) == 0)
{
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, PlayerColors[random(200)], "You must be rcon admin to do this!");
new file[30];
new name[MAX_PLAYER_NAME];
for(new gm = 0; gm <= GANG_NUMBER; gm++)
{
format(file, sizeof(file), GANG_FILE, gm);
if(dini_Exists(file) && dini_Int(file,"GANG_MEMBERS") <= 1)
{
dini_Remove(file);
format(string, sizeof(string), "Gang Removed: ID:%d, Members: %d, Name: %s", gm, GangInfo[gm][GANG_MEMBERS], GangInfo[gm][GANG_NAME]);
SendClientMessage(playerid, PlayerColors[random(200)], string);
for(new p; p < MAX_PLAYERS; p++)
{
if(PlayerInfo[p][gang] == gm && IsPlayerConnected(p))
{
GetPlayerName(p, name, sizeof(name));
DOF2_SetInt(DOF2_File(name), "Gang", 0);
PlayerInfo[p][gang] = 0;
}
}
}
}
return 1;
}
//---- Help
if(strcmp(tmp, "ganghelp", true) == 0)
{
SendClientMessage(playerid, PlayerColors[random(200)], "Use: /Gang create to create gang");
SendClientMessage(playerid, PlayerColors[random(200)], "Use: /Gang invite for invite a player in your gang");
SendClientMessage(playerid, PlayerColors[random(200)], "Use: /Gang join for join a gang if you are invited");
SendClientMessage(playerid, PlayerColors[random(200)], "Use: /Gang leave for leave a gang");
SendClientMessage(playerid, PlayerColors[random(200)], "Use: /Gang stats for gang statistics");
SendClientMessage(playerid, PlayerColors[random(200)], "Use: /Gang list for a list of all gangs");
SendClientMessage(playerid, PlayerColors[random(200)],"! (prefix text for gang-chat)");
SendClientMessage(playerid, PlayerColors[random(200)], "To attack a gang zone 3 members of your gang must stay there for 2 minutes");
SendClientMessage(playerid, PlayerColors[random(200)], "When the 3 members invade the gangzone, it will flash until it is taken");
return 1;
}
else SendClientMessage(playerid, PlayerColors[random(200)], "USE: /gang [create/invite/join/leave/stats/list]");
return 1;
}
//---- Join Gang
public JoinGang(playerid, gangid)
{
new name[MAX_PLAYER_NAME];
new gfile[100];
format(gfile, sizeof(gfile), GANG_FILE, gangid);
GetPlayerName(playerid, name, sizeof(name));
DOF2_SetInt(DOF2_File(name), "Gang", gangid);
new string[128];
PlayerInfo[playerid][gang] = gangid;
GangInfo[gangid][GANG_MEMBERS]++;
format(string, sizeof(string), "You joined the gang %s, Members: %d", GangInfo[gangid][GANG_NAME], GangInfo[gangid][GANG_MEMBERS]);
SendClientMessage(playerid, PlayerColors[random(200)], string);
format(string, sizeof(string), "%s Has joined the gang %s", name , GangInfo[gangid][GANG_NAME]);
SendClientMessageToAll(PlayerColors[random(200)], string);
SetPlayerColor(playerid, GangInfo[gangid][GANG_COLOR]);
dini_IntSet(gfile, "GANG_MEMBERS", GangInfo[gangid][GANG_MEMBERS]);
return 1;
}
//---- Leave Gang
public LeaveGang(playerid, gangid)
{
new name[MAX_PLAYER_NAME];
new gfile[100];
format(gfile, sizeof(gfile), GANG_FILE, gangid);
GetPlayerName(playerid, name, sizeof(name));
DOF2_SetInt(DOF2_File(name), "Gang", 0);
new string[128];
format(string, sizeof(string), "You left the gang %s", GangInfo[gangid][GANG_NAME]);
SendClientMessage(playerid, PlayerColors[random(200)], string);
format(string, sizeof(string), "%s has left gang %s", name , GangInfo[gangid][GANG_NAME]);
SendClientMessageToAll(PlayerColors[random(200)], string);
PlayerInfo[playerid][gang] = 0;
GangInfo[gangid][GANG_MEMBERS]--;
SetPlayerColor(playerid, PlayerColors[random(200)]);
if(GangInfo[gangid][GANG_MEMBERS] == 0) {
format(string, sizeof(string), "The gang %s was abandoned", GangInfo[gangid][GANG_NAME]);
SendClientMessageToAll(PlayerColors[random(200)], string);
return dini_Remove(gfile);
}
dini_IntSet(gfile, "GANG_MEMBERS", GangInfo[gangid][GANG_MEMBERS]);
return 1;
}