17.10.2011, 21:39
Well, Basically I follow the tutorial, and I just want to add something:
when someone fails or wins the territory, send a message like
Team_USA Captured TEAM_CHINA's Territory!
Or
Team_USA Failed on Capturing TEAM_CHINA's Territory!
when someone fails or wins the territory, send a message like
Team_USA Captured TEAM_CHINA's Territory!
Or
Team_USA Failed on Capturing TEAM_CHINA's Territory!
pawn Код:
///////////////////////////////////
//GANG SYSTEM
//////////////////////////////////
#define TEAM_USA 1
#define TEAM_CHINA 2
#define TEAM_RUSSIA 3
#define TEAM_JAPAN 4
#define TEAM_IRAQ 5
enum eZone
{
Float:zMinX,
Float:zMinY,
Float:zMaxX,
Float:zMaxY,
zTeam
}
new ZoneInfo[][eZone] = {
{443.3192,2405.9543,113.3581,2609.3821,TEAM_USA}, //
{87.0319,1792.8086,398.4910,2090.4434,TEAM_CHINA},//
{2590.2043,-1808.8383,2842.3,-1610.3673,TEAM_RUSSIA},
{996.3851,2474.0288,1165.1940,2289.9304,TEAM_JAPAN},//
{4790.2043,-1808.8383,2842.3,-1880.4444,TEAM_IRAQ}
};
new ZoneAttackTime[sizeof(ZoneInfo)];
stock GetTeamZoneColor(teamid)
{
switch(teamid)
{
case TEAM_USA: return COLOR_BLUE;
case TEAM_CHINA: return COLOR_RED;
case TEAM_RUSSIA: return COLOR_GREEN;
case TEAM_JAPAN: return COLOR_WHITE;
case TEAM_IRAQ: return COLOR_YELLOW;
}
return -1;
}
new ZoneID[sizeof(ZoneInfo)];
new ZoneAttacker[sizeof(ZoneInfo)] = {-1, ...};
#define MIN_MEMBERS_TO_START_WAR 1 // how many team members needed in a zone to start a war
#define TAKEOVER_TIME 4 // how many seconds needed to take over the zone
#define MIN_DEATHS_TO_START_WAR 0 // how many team members must be killed in a zone to start a war
new Teams[] = {
TEAM_USA,
TEAM_CHINA,
TEAM_RUSSIA,
TEAM_JAPAN,
TEAM_IRAQ
};
stock IsPlayerInZone(playerid, zoneid)
{
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
return (x > ZoneInfo[zoneid][zMinX] && x < ZoneInfo[zoneid][zMaxX] && y > ZoneInfo[zoneid][zMinY] && y < ZoneInfo[zoneid][zMaxY]);
}
stock GetPlayersInZone(zoneid, teamid)
{
new count;
for(new i=0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i) && GetPlayerTeam(i) == teamid && IsPlayerInZone(i, zoneid))
{
count++;
}
}
return count;
}
forward ZoneTimer();
public ZoneTimer()
{
for(new i=0; i < sizeof(ZoneInfo); i++) // loop all zones
{
if(ZoneAttacker[i] != -1) // zone is being attacked
{
if(GetPlayersInZone(i, ZoneAttacker[i]) >= MIN_MEMBERS_TO_START_WAR) // team has enough members in the zone
{
ZoneAttackTime[i]++;
if(ZoneAttackTime[i] == TAKEOVER_TIME) // zone has been under attack for enough time and attackers take over the zone
{
new string[64];
format(string,sizeof string,"%s is attacking the territory of %s!",GetPlayerTeam(i),ZoneInfo[i][zTeam]);
SendClientMessageToAll(0xFFFFFFAA,string);
GangZoneStopFlashForAll(ZoneID[i]);
ZoneInfo[i][zTeam] = ZoneAttacker[i];
GangZoneShowForAll(ZoneID[i], GetTeamZoneColor(ZoneInfo[i][zTeam])); // update the zone color for new team
ZoneAttacker[i] = -1;
}
}
else // attackers failed to take over the zone
{
GangZoneStopFlashForAll(ZoneID[i]);
ZoneAttacker[i] = -1;
new string[64];
format(string,sizeof string,"%s failed capturing %s!",Teams,ZoneInfo[i][zTeam]);
SendClientMessageToAll(0xFFFFFFAA,string);
}
}
else // check if somebody is attacking
{
for(new t=0; t < sizeof(Teams); t++) // loop all teams
{
if(Teams[t] != ZoneInfo[i][zTeam] && GetPlayersInZone(i, Teams[t]) >= MIN_MEMBERS_TO_START_WAR) // if there are enough enemies in the zone
{
ZoneAttacker[i] = Teams[t];
ZoneAttackTime[i] = 0;
GangZoneFlashForAll(ZoneID[i], GetTeamZoneColor(ZoneAttacker[i]));
}
}
}
}
}
stock GetPlayerZone(playerid)
{
for(new i=0; i < sizeof(ZoneInfo); i++)
{
if(IsPlayerInZone(playerid, i))
{
return i;
}
}
return -1;
}