Oblivion_UFF

captureflag

Oct 1st, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.97 KB | None | 0 0
  1. new CaptureFlag[MAX_PLAYERS]; // the player time for the capture of he zone.
  2. new CaptureCounter[MAX_PLAYERS]; // the seconds of capturing time.
  3.  
  4. // creating team configuration
  5. enum E_TEAM
  6. {
  7. bool:E_TEAM_VALID,
  8. E_TEAM_NAME[32],
  9. E_TEAM_COLOR
  10. };
  11. new const TEAM[][E_TEAM] =
  12. {
  13. {true, "SWAT", 0xFF0000FF}, // the color's opacity doesn't matter, we will use the function "ALPHA" to change it later
  14. {true, "TERROR", 0x00FF00FF}
  15. };
  16. //------
  17.  
  18.  
  19. //Creating Zone Configuration
  20. enum E_CAPTURE_ZONE
  21. {
  22. E_CAPTURE_ZONE_NAME[64],
  23. Float:E_CAPTURE_ZONE_GANGZONE_OFFSET[4], // the capture zone's gangzone minx/y and maxx/y
  24. Float:E_CAPTURE_ZONE_CP_OFFSET[3], // the x,y,z offset for the checkpoint the players will stay in and capture
  25. E_CAPTURE_ZONE_OWNER,
  26. E_CAPTURE_ZONE_GANGZONE,
  27. E_CAPTURE_ZONE_ATTACKER,
  28. E_CAPTURE_ZONE_CP,
  29. E_CAPTURE_ZONE_AREA
  30. };
  31. new captureZone[][E_CAPTURE_ZONE] =
  32. {
  33. //{"zone name", {minx, miny, maxx, maxy}, {cpx, cpy, cpz}, owner_team_index}
  34. {"Big Ear", {-437.5, 1513.671875, -244.140625, 1636.71875}, {-311.0136, 1542.9733, 75.5625}, 0},
  35. {"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
  36. };
  37.  
  38. //--- So we will not reset the variables under OnGamemodeInit and create the zones
  39. public OnGameModeInit()
  40. {
  41. for (new i; i < sizeof captureZone; i++)
  42. {
  43. captureZone[i][E_CAPTURE_ZONE_ATTACKER] = INVALID_PLAYER_ID; // set the zone attacker to none
  44. // Creating the Gang zone
  45. 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]);
  46. // Creating the rectange area in the zone.
  47. 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]);
  48. // Creating the CP in all zones.
  49. 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);
  50. }
  51. return 1;
  52. }
  53.  
  54.  
  55. //--- Now let's show the gang zones when player spawns.
  56. public OnPlayerSpawn(playerid)
  57. {
  58. for (new i; i < sizeof captureZone; i++)
  59. { // show gangzones
  60. GangZoneShowForPlayer(playerid, captureZone[i][E_CAPTURE_ZONE_GANGZONE], ALPHA(TEAM[captureZone[i][E_CAPTURE_ZONE_OWNER]][E_TEAM_COLOR], 100));
  61.  
  62. // flash gangzone if under attack
  63. if (captureZone[i][E_CAPTURE_ZONE_ATTACKER] != INVALID_PLAYER_ID)
  64. {
  65. GangZoneFlashForPlayer(playerid, captureZone[i][E_CAPTURE_ZONE_GANGZONE], ALPHA(TEAM[GetPlayerTeam(captureZone[i][E_CAPTURE_ZONE_ATTACKER])][E_TEAM_COLOR], 100));
  66. }
  67. }
  68. return 1;
  69. }
  70.  
  71.  
  72. // Wheb Player Enters the Area (Gang Zone)
  73. public OnPlayerEnterDynamicArea(playerid, areaid)
  74. {
  75. for (new i; i < sizeof captureZone; i++)
  76. {
  77. if (areaid == captureZone[i][E_CAPTURE_ZONE_AREA]) // matches the player area to the gangzone area
  78. {
  79. new string[64 + 3];
  80. format(string, sizeof string, "~w~%s", captureZone[i][E_CAPTURE_ZONE_NAME]);
  81. GameTextForPlayer(playerid, string, 5000, 6);
  82. return 1;
  83. }
  84. }
  85. return 1;
  86. }
  87.  
  88.  
  89. public OnPlayerEnterDynamicCP(playerid, checkpointid) // When Player Enter the CheckPoint.
  90. {
  91. for (new i; i < sizeof captureZone; i++)
  92. {
  93. if(checkpointid == captureZone[i][E_CAPTURE_ZONE_CP]) // matches the player area to the gangzone area
  94. {
  95. 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!
  96. {
  97. 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
  98. {
  99. // Don't forgot to check player's team.
  100. captureZone[i][E_CAPTURE_ZONE_ATTACKER] = playerid;
  101. GangZoneFlashForAll(captureZone[i][E_CAPTURE_ZONE_GANGZONE], ALPHA(TEAM[GetPlayerTeam(playerid)][E_TEAM_COLOR], 100));
  102. CaptureCounter[playerid] = 20; // Captueing time 20 seconds.
  103. CaptureFlag[playerid] = SetTimerEx("UpdatePlayerProgress", 1000, 1, "i", playerid);
  104. GameTextForPlayer(playerid, "~W~Wait ~Y~20 ~W~Seconds~n~In the CP", 1000, 3);
  105. }
  106. else return 1;
  107. }
  108. }
  109. }
  110. return 1;
  111. }
  112.  
  113.  
  114. forward UpdatePlayerProgress(playerid);
  115. public UpdatePlayerProgress(playerid)
  116. {
  117. CaptureCounter[playerid]--; // capturing time reduces 1 second every 1 second accoeding to CaptureFlag[playerid].
  118. new string[58];
  119. format(string, sizeof(string), "~W~Wait ~Y~%d ~W~Seconds", CaptureCounter[playerid]);
  120. GameTextForPlayer(playerid, string, 1000, 3);
  121.  
  122. if(CaptureCounter[playerid] == 0)
  123. {
  124. // Setting the attacker team as the zone owner and flash the zone for all or new owner.
  125. captureZone[zoneid][E_CAPTURE_ZONE_OWNER] = GetPlayerTeam(captureZone[zoneid][E_CAPTURE_ZONE_ATTACKER]);
  126. captureZone[zoneid][E_CAPTURE_ZONE_ATTACKER] = INVALID_PLAYER_ID;
  127. KillTimer(CaptureFlag[playerid]);
  128. GangZoneStopFlashForAll(captureZone[zoneid][E_CAPTURE_ZONE_GANGZONE]);
  129. GangZoneShowForAll(captureZone[zoneid][E_CAPTURE_ZONE_GANGZONE], ALPHA(TEAM[captureZone[zoneid][E_CAPTURE_ZONE_OWNER]][E_TEAM_COLOR], 100));
  130. }
  131. return 1;
  132. }
  133.  
  134. public OnPlayerLeaveDynamicCP(playerid, checkpointid)
  135. {
  136. if(CaptureCounter[playerid] < 20)
  137. {
  138. for (new i; i < sizeof captureZone; i++)
  139. {
  140. if (checkpointid == captureZone[i][E_CAPTURE_ZONE_CP])
  141. {
  142. if (captureZone[i][E_CAPTURE_ZONE_ATTACKER] != INVALID_PLAYER_ID)
  143. {
  144. if(GetPlayerTeam(playerid) == GetPlayerTeam(captureZone[i][E_CAPTURE_ZONE_ATTACKER]))
  145. {
  146. KillTimer(CaptureFlag[playerid]);
  147. GameTextForPlayer(playerid, "Failed! Please Stay~n~In The Checkpoint", 3000, 3);
  148. }
  149. }
  150. }
  151. }
  152. return 1;
  153. }
  154.  
  155. public OnPlayerDisconnect(playerid, reason)
  156. {
  157. KillTimer(CaptureFlag[playerid]);
  158. CaptureCounter[playerid] = 0;
  159. return 1;
  160. }
  161.  
  162. public OnGameModeExit()
  163. {
  164. for (new i; i < sizeof captureZone; i++)
  165. {
  166. GangZoneDestroy(captureZone[i][E_CAPTURE_ZONE_GANGZONE]);
  167. DestroyDynamicCP(captureZone[i][E_CAPTURE_ZONE_CP]);
  168. DestroyDynamicArea(captureZone[i][E_CAPTURE_ZONE_AREA]);
  169. }
  170. return 1;
  171. }
Add Comment
Please, Sign In to add comment