Oblivion_UFF

Capture flag

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