Oblivion_UFF

capture flag 2

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