Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- new CaptureFlag[MAX_PLAYERS]; // the player time for the capture of he zone.
- new CaptureCounter[MAX_PLAYERS]; // the seconds of capturing time.
- // creating team configuration
- enum E_TEAM
- {
- bool:E_TEAM_VALID,
- E_TEAM_NAME[32],
- E_TEAM_COLOR
- };
- new const TEAM[][E_TEAM] =
- {
- {true, "SWAT", 0xFF0000FF}, // the color's opacity doesn't matter, we will use the function "ALPHA" to change it later
- {true, "TERROR", 0x00FF00FF}
- };
- //------
- //Creating Zone Configuration
- enum E_CAPTURE_ZONE
- {
- E_CAPTURE_ZONE_NAME[64],
- Float:E_CAPTURE_ZONE_GANGZONE_OFFSET[4], // the capture zone's gangzone minx/y and maxx/y
- Float:E_CAPTURE_ZONE_CP_OFFSET[3], // the x,y,z offset for the checkpoint the players will stay in and capture
- E_CAPTURE_ZONE_OWNER,
- E_CAPTURE_ZONE_GANGZONE,
- E_CAPTURE_ZONE_ATTACKER,
- E_CAPTURE_ZONE_CP,
- E_CAPTURE_ZONE_AREA
- };
- new captureZone[][E_CAPTURE_ZONE] =
- {
- //{"zone name", {minx, miny, maxx, maxy}, {cpx, cpy, cpz}, owner_team_index}
- {"Big Ear", {-437.5, 1513.671875, -244.140625, 1636.71875}, {-311.0136, 1542.9733, 75.5625}, 0},
- {"Area 51", {-46.875, 1697.265625, 423.828125, 2115.234375}, {254.4592, 1802.8997, 7.4285}, 1} // "1" means the zone owner will be "Terror", notice the number relates to array "TEAM"'s indexes
- };
- //--- So we will not reset the variables under OnGamemodeInit and create the zones
- public OnGameModeInit()
- {
- for (new i; i < sizeof captureZone; i++)
- {
- captureZone[i][E_CAPTURE_ZONE_ATTACKER] = INVALID_PLAYER_ID; // set the zone attacker to none
- // Creating the Gang zone
- captureZone[i][E_CAPTURE_ZONE_GANGZONE] = GangZoneCreate(captureZone[i][E_CAPTURE_ZONE_GANGZONE_OFFSET][0], captureZone[i][E_CAPTURE_ZONE_GANGZONE_OFFSET][1], captureZone[i][E_CAPTURE_ZONE_GANGZONE_OFFSET][2], captureZone[i][E_CAPTURE_ZONE_GANGZONE_OFFSET][3]);
- // Creating the rectange area in the zone.
- captureZone[i][E_CAPTURE_ZONE_AREA] = CreateDynamicRectangle(captureZone[i][E_CAPTURE_ZONE_GANGZONE_OFFSET][0], captureZone[i][E_CAPTURE_ZONE_GANGZONE_OFFSET][1], captureZone[i][E_CAPTURE_ZONE_GANGZONE_OFFSET][2], captureZone[i][E_CAPTURE_ZONE_GANGZONE_OFFSET][3]);
- // Creating the CP in all zones.
- captureZone[i][E_CAPTURE_ZONE_CP] = CreateDynamicCP(captureZone[i][E_CAPTURE_ZONE_CP_OFFSET][0], captureZone[i][E_CAPTURE_ZONE_CP_OFFSET][1], captureZone[i][E_CAPTURE_ZONE_CP_OFFSET][2], 1.0);
- }
- return 1;
- }
- //--- Now let's show the gang zones when player spawns.
- public OnPlayerSpawn(playerid)
- {
- for (new i; i < sizeof captureZone; i++)
- { // show gangzones
- GangZoneShowForPlayer(playerid, captureZone[i][E_CAPTURE_ZONE_GANGZONE], ALPHA(TEAM[captureZone[i][E_CAPTURE_ZONE_OWNER]][E_TEAM_COLOR], 100));
- // flash gangzone if under attack
- if (captureZone[i][E_CAPTURE_ZONE_ATTACKER] != INVALID_PLAYER_ID)
- {
- GangZoneFlashForPlayer(playerid, captureZone[i][E_CAPTURE_ZONE_GANGZONE], ALPHA(TEAM[GetPlayerTeam(captureZone[i][E_CAPTURE_ZONE_ATTACKER])][E_TEAM_COLOR], 100));
- }
- }
- return 1;
- }
- // Wheb Player Enters the Area (Gang Zone)
- public OnPlayerEnterDynamicArea(playerid, areaid)
- {
- for (new i; i < sizeof captureZone; i++)
- {
- if (areaid == captureZone[i][E_CAPTURE_ZONE_AREA]) // matches the player area to the gangzone area
- {
- new string[64 + 3];
- format(string, sizeof string, "~w~%s", captureZone[i][E_CAPTURE_ZONE_NAME]);
- GameTextForPlayer(playerid, string, 5000, 6);
- return 1;
- }
- }
- return 1;
- }
- public OnPlayerEnterDynamicCP(playerid, checkpointid) // When Player Enter the CheckPoint.
- {
- for (new i; i < sizeof captureZone; i++)
- {
- if(checkpointid == captureZone[i][E_CAPTURE_ZONE_CP]) // matches the player area to the gangzone area
- {
- if(captureZone[i][E_CAPTURE_ZONE_ATTACKER] == INVALID_PLAYER_ID) // this check tells us that gangzone is not under attack so we can proceed with start attacking here!
- {
- if ((GetPlayerTeam(playerid) >= 0 && GetPlayerTeam(playerid) < sizeof TEAM) && TEAM[GetPlayerTeam(playerid)][E_TEAM_VALID] && GetPlayerTeam(playerid) != captureZone[i][E_CAPTURE_ZONE_OWNER]) // here the team ids play its role, we check the index is valid - The second part is if whether the player isn't of team that zone owner is
- {
- // Don't forgot to check player's team.
- captureZone[i][E_CAPTURE_ZONE_ATTACKER] = playerid;
- GangZoneFlashForAll(captureZone[i][E_CAPTURE_ZONE_GANGZONE], ALPHA(TEAM[GetPlayerTeam(playerid)][E_TEAM_COLOR], 100));
- CaptureCounter[playerid] = 20; // Captueing time 20 seconds.
- CaptureFlag[playerid] = SetTimerEx("UpdatePlayerProgress", 1000, 1, "i", playerid);
- GameTextForPlayer(playerid, "~W~Wait ~Y~20 ~W~Seconds~n~In the CP", 1000, 3);
- }
- else return 1;
- }
- }
- }
- return 1;
- }
- forward UpdatePlayerProgress(playerid);
- public UpdatePlayerProgress(playerid)
- {
- CaptureCounter[playerid]--; // capturing time reduces 1 second every 1 second accoeding to CaptureFlag[playerid].
- new string[58];
- format(string, sizeof(string), "~W~Wait ~Y~%d ~W~Seconds", CaptureCounter[playerid]);
- GameTextForPlayer(playerid, string, 1000, 3);
- if(CaptureCounter[playerid] == 0)
- {
- // Setting the attacker team as the zone owner and flash the zone for all or new owner.
- captureZone[zoneid][E_CAPTURE_ZONE_OWNER] = GetPlayerTeam(captureZone[zoneid][E_CAPTURE_ZONE_ATTACKER]);
- captureZone[zoneid][E_CAPTURE_ZONE_ATTACKER] = INVALID_PLAYER_ID;
- KillTimer(CaptureFlag[playerid]);
- GangZoneStopFlashForAll(captureZone[zoneid][E_CAPTURE_ZONE_GANGZONE]);
- GangZoneShowForAll(captureZone[zoneid][E_CAPTURE_ZONE_GANGZONE], ALPHA(TEAM[captureZone[zoneid][E_CAPTURE_ZONE_OWNER]][E_TEAM_COLOR], 100));
- }
- return 1;
- }
- public OnPlayerLeaveDynamicCP(playerid, checkpointid)
- {
- if(CaptureCounter[playerid] < 20)
- {
- for (new i; i < sizeof captureZone; i++)
- {
- if (checkpointid == captureZone[i][E_CAPTURE_ZONE_CP])
- {
- if (captureZone[i][E_CAPTURE_ZONE_ATTACKER] != INVALID_PLAYER_ID)
- {
- if(GetPlayerTeam(playerid) == GetPlayerTeam(captureZone[i][E_CAPTURE_ZONE_ATTACKER]))
- {
- KillTimer(CaptureFlag[playerid]);
- GameTextForPlayer(playerid, "Failed! Please Stay~n~In The Checkpoint", 3000, 3);
- }
- }
- }
- }
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- KillTimer(CaptureFlag[playerid]);
- CaptureCounter[playerid] = 0;
- return 1;
- }
- public OnGameModeExit()
- {
- for (new i; i < sizeof captureZone; i++)
- {
- GangZoneDestroy(captureZone[i][E_CAPTURE_ZONE_GANGZONE]);
- DestroyDynamicCP(captureZone[i][E_CAPTURE_ZONE_CP]);
- DestroyDynamicArea(captureZone[i][E_CAPTURE_ZONE_AREA]);
- }
- return 1;
- }
Add Comment
Please, Sign In to add comment