25.10.2011, 04:18
Well, first, here is my code:
in the part where it says "%s captured %s" it kinda fails, look:
in the part where it says "%s captured %s" it kinda fails, look:
pawn Код:
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;
case RANDOM: return COLOR_PINK;
}
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 captured %s's Territory!<<<<<<<<<<<<<<<",ZoneInfo,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;
}
}
else // check if somebody is attacking
{
for(new t=0; t < sizeof(Teams); t++) // loop all teams
{
if(GetPlayersInZone(i, Teams[t]) >= MIN_MEMBERS_TO_START_WAR) // if there are enough enemies in the zone
{
} else continue;
if(Teams[t] != ZoneInfo[i][zTeam])
{
ZoneAttacker[i] = Teams[t];
ZoneAttackTime[i] = 0;
GangZoneFlashForAll(ZoneID[i], GetTeamZoneColor(ZoneAttacker[i]));
new string[128];
format(string,sizeof string,">>>>>>>>>>>%s's base is being CAPTURED!<<<<<<<<<<",ZoneInfo[i][zTeam]);
SendClientMessageToAll(0xFFFFFFAA,string);
}
}
}
}
}
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
/*if (PRESSED(KEY_JUMP))
{
new
Float:x,
Float:y,
Float:z;
GetPlayerPos(playerid, x, y, z);
SetPlayerPos(playerid, x, y, z + 10.0);
}*/
return 1;
}
stock GetPlayerZone(playerid)
{
for(new i=0; i < sizeof(ZoneInfo); i++)
{
if(IsPlayerInZone(playerid, i))
{
return i;
}
}
return -1;
}