1
0

PPC_MissionsRoadworker.inc 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. // Forward the function used to repair a camera (when the player entered a racecheckpoint)
  2. forward Roadworker_RepairCamera(playerid);
  3. enum TBrokenVehicleLocation
  4. {
  5. BrokenName[50], // Holds the name of the location where the vehicle is located
  6. Float:BrokenX, // Holds the X coordinate where the vehicle spawns
  7. Float:BrokenY, // Holds the Y coordinate where the vehicle spawns
  8. Float:BrokenZ // Holds the Z coordinate where the vehicle spawns
  9. }
  10. new ABrokenVehicles[][TBrokenVehicleLocation] =
  11. {
  12. {"Shady Creeks", -2047.5, -1882.25, 52.4},
  13. {"Angel Pine", -2072.5, -2407.75, 30.7},
  14. {"Shady Creeks", -1595.25, -2625.0, 52.6},
  15. {"Back O Beyond", -990.25, -2335.5, 66.8},
  16. {"Flint County", 46.5, -2654.25, 40.5},
  17. {"Los Santos Inlet", -313.5, -1959.75, 20.0},
  18. {"Leafy Hollow", -833.0, -1737.25, 80.8},
  19. {"Flint Range", -347.5, -1331.0, 17.1},
  20. {"Flint County", 17.25, -987.75, 28.7},
  21. {"Fallen Tree", -763.0, -621.25, 61.5},
  22. {"Foster Valley", -1885.5, -435.5, 25.2},
  23. {"Missionary Hill", -2451.25, -681.0, 133.6},
  24. {"Garcia", -2371.5, 118.25, 35.3},
  25. {"Downtown", -1781.5, 429.25, 16.6},
  26. {"Palisades", -2905.0, 656.5, 6.3},
  27. {"Paradiso", -2771.25, 1239.5, 22.6}
  28. // {"nnnnnnnnnn", xxxxxxx, yyyyyyyy, zzzzzzz},
  29. };
  30. // This function is called when a roadworker wants to start a job by entering "/work"
  31. Roadworker_StartRandomJob(playerid)
  32. {
  33. // Setup local variables
  34. new vid, trailerid;
  35. // If the player is the driver of the vehicle (GetPlayerVehicleSeat returns -1 if the player is not in a vehicle)
  36. if (GetPlayerVehicleSeat(playerid) == 0)
  37. {
  38. // Get the vehicle-id
  39. vid = GetPlayerVehicleID(playerid);
  40. // Get the trailer-id
  41. trailerid = GetVehicleTrailer(vid);
  42. switch (GetVehicleModel(vid))
  43. {
  44. case VehicleUtilityVan: // With a Utility Van, you're gonna do "repair speedcamera" job-type
  45. {
  46. // Check if the player has a utility trailer attached
  47. if (trailerid != 0)
  48. {
  49. // Check if there is a utility trailer attached
  50. if (GetVehicleModel(trailerid) == VehicleUtilityTrailer)
  51. {
  52. // Setup local variables
  53. new Float:x, Float:y, Float:z, CamID;
  54. // Get a random speedcamera (no previous camera has been fixed yet, so Exception = -1 (invalid camera))
  55. CamID = GetRandomCamera(-1);
  56. // Check if there are no speedcamera's
  57. if (CamID == -1)
  58. {
  59. SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}Unable to start a job, there are no speedcamera's created");
  60. return 1;
  61. }
  62. // Job has started
  63. APlayerData[playerid][JobStarted] = true;
  64. // Set job-type
  65. APlayerData[playerid][JobID] = 1; // Job-type: "repair speedcameras"
  66. // Store the CamID
  67. APlayerData[playerid][JobLoc1] = CamID;
  68. // Set the TextDraw so the player can see it
  69. TextDrawSetString(APlayerData[playerid][MissionText], TXT_RepairSpeedcamera);
  70. // Grab the x, y, z positions for the checkpoint
  71. x = ACameras[CamID][CamX];
  72. y = ACameras[CamID][CamY];
  73. z = ACameras[CamID][CamZ];
  74. // Create a racecheckpoint where the player should repair a speedcamera
  75. SetPlayerRaceCheckpoint(playerid, 1, x, y, z, 0.0, 0.0, 0.0, 2.5);
  76. // Create a checkpoint to indicate the base
  77. SetPlayerCheckpoint(playerid, -1870.0, -1710.0, 21.8, 7.0);
  78. // Store the vehicleID (required to be able to check if the player left his vehicle)
  79. APlayerData[playerid][VehicleID] = vid;
  80. APlayerData[playerid][TrailerID] = trailerid;
  81. // Start a timer that ticks every second to see if the player is still inside his vehicle
  82. APlayerData[playerid][VehicleTimerTime] = Job_TimeToFailMission;
  83. // Inform the player what he must do
  84. SendClientMessage(playerid, 0xFFFFFFFF, "{00FF00}Repair the indicated speedcamera or go back to base to end the mission");
  85. }
  86. else
  87. SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}You need a utility trailer attached to your utility van");
  88. }
  89. else
  90. SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}You need a utility trailer attached to your utility van");
  91. }
  92. case VehicleTowTruck: // With a towtruck, you're gonna do "tow broken vehicle to shredder" job-type
  93. {
  94. // Setup local variables
  95. new Float:x, Float:y, Float:z, RouteText[128];
  96. // Job has started
  97. APlayerData[playerid][JobStarted] = true;
  98. // Set job-type
  99. APlayerData[playerid][JobID] = 2; // Job-type: "tow broken vehicles to shredder"
  100. // Choose a random spawn-location for the vehicle
  101. APlayerData[playerid][JobLoc1] = random(sizeof(ABrokenVehicles));
  102. // Set the job-step to 1 (going to pickup the broken vehicle)
  103. APlayerData[playerid][JobStep] = 1;
  104. // Set the TextDraw so the player can see it
  105. format(RouteText, 128, TXT_TowBrokenVehicle, ABrokenVehicles[APlayerData[playerid][JobLoc1]][BrokenName]);
  106. TextDrawSetString(APlayerData[playerid][MissionText], RouteText);
  107. // Grab the x, y, z positions for the checkpoint where the vehicle will spawn, once the player comes into range (100m)
  108. x = ABrokenVehicles[APlayerData[playerid][JobLoc1]][BrokenX];
  109. y = ABrokenVehicles[APlayerData[playerid][JobLoc1]][BrokenY];
  110. z = ABrokenVehicles[APlayerData[playerid][JobLoc1]][BrokenZ];
  111. // Create a checkpoint to indicate the location of the vehicle
  112. SetPlayerCheckpoint(playerid, x, y, z, 10.0);
  113. // Also create the vehicle inside the checkpoint and store the vehicle's reference as the LoadID
  114. APlayerData[playerid][LoadID] = CreateBrokenVehicle(x, y, z);
  115. // Store the vehicleID (required to be able to check if the player left his vehicle)
  116. APlayerData[playerid][VehicleID] = vid;
  117. // Set the job-fail-time for the global vehicle-timer
  118. APlayerData[playerid][VehicleTimerTime] = Job_TimeToFailMission;
  119. // Inform the player what he must do
  120. SendClientMessage(playerid, 0xFFFFFFFF, "{00FF00}Tow the broken vehicle to the shredder");
  121. }
  122. }
  123. }
  124. return 1;
  125. }
  126. // This function gets executed when the player entered a checkpoint (to tow a broken vehicle to the shredder)
  127. Roadworker_EnterCheckpoint(playerid)
  128. {
  129. // Setup local variables
  130. new RouteText[128];
  131. // Check which job-type you're doing
  132. if (APlayerData[playerid][JobID] == 2) // Job-type: tow broken vehicle to shredder
  133. {
  134. // Check if the player is still inside his towtruck
  135. if (GetPlayerVehicleID(playerid) == APlayerData[playerid][VehicleID])
  136. {
  137. // Select action based on JobStep
  138. switch (APlayerData[playerid][JobStep])
  139. {
  140. case 1: // Going to pickup the broken vehicle
  141. {
  142. // Delete the checkpoint
  143. DisablePlayerCheckpoint(playerid);
  144. // Attach the broken vehicle to your towtruck
  145. AttachTrailerToVehicle(APlayerData[playerid][LoadID], GetPlayerVehicleID(playerid));
  146. // Update the TextDraw so the player can see it
  147. format(RouteText, 128, TXT_DeliverBrokenVehicle, ABrokenVehicles[APlayerData[playerid][JobLoc1]][BrokenName]);
  148. TextDrawSetString(APlayerData[playerid][MissionText], RouteText);
  149. // Create a checkpoint to indicate the location of the shredder
  150. SetPlayerCheckpoint(playerid, -1868.5, -1684.0, 21.8, 10.0);
  151. // Set the next jobstep (2 = going to deliver the broken vehicle to the shredder)
  152. APlayerData[playerid][JobStep] = 2;
  153. // Update the vehicleID AND the id of the broken vehicle as trailer (required to be able to check if the player left his vehicle)
  154. APlayerData[playerid][VehicleID] = GetPlayerVehicleID(playerid);
  155. APlayerData[playerid][TrailerID] = APlayerData[playerid][LoadID];
  156. // Inform the player what he must do
  157. SendClientMessage(playerid, 0xFFFFFFFF, "{00FF00}Tow the broken vehicle to the shredder");
  158. }
  159. case 2: // Going to deliver the broken vehicle to the shredder
  160. {
  161. // Delete the broken vehicle
  162. AVehicleData[APlayerData[playerid][LoadID]][Owned] = false;
  163. DetachTrailerFromVehicle(GetPlayerVehicleID(playerid));
  164. DestroyVehicle(APlayerData[playerid][LoadID]);
  165. APlayerData[playerid][LoadID] = 0;
  166. // End the mission, clearing all data
  167. Roadworker_EndJob(playerid);
  168. // Pay the player for delivering the broken vehicle to the shredder
  169. RewardPlayer(playerid, 3500, 1);
  170. // Let the player know he earned money for delivering the broken vehicle to the shredder
  171. SendClientMessage(playerid, 0xFFFFFFFF, "{00FF00}You've earned {FFFF00}$3500{00FF00} for delivering the broken vehicle to the shredder");
  172. // Also increase the stats
  173. APlayerData[playerid][StatsRoadworkerJobs]++;
  174. // Save the player's account
  175. PlayerFile_Save(playerid);
  176. }
  177. }
  178. }
  179. else
  180. SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}You need to be in your towtruck to proceed");
  181. }
  182. return 1;
  183. }
  184. // This function gets executed when the player entered a race-checkpoint (to repair a speedcamera)
  185. Roadworker_EnterRaceCheckpoint(playerid)
  186. {
  187. // Check which job-type you're doing
  188. if (APlayerData[playerid][JobID] == 1) // Repairing speedcamera's
  189. {
  190. // Check if the player is on foot
  191. if (GetPlayerVehicleSeat(playerid) == -1)
  192. {
  193. // Inform the player that he's repairing the camera
  194. GameTextForPlayer(playerid, "Repairing speedcamera...", 5000, 4);
  195. // Disable the player's actions (he cannot move anymore)
  196. TogglePlayerControllable(playerid, 0);
  197. // Start a timer (Public function "Roadworker_RepairCamera(playerid)" gets called when the timer runs out)
  198. APlayerData[playerid][LoadingTimer] = SetTimerEx("Roadworker_RepairCamera", 5000, false, "d" , playerid);
  199. }
  200. else
  201. SendClientMessage(playerid, 0xFFFFFFFF, TXT_NeedOnFootToProceed);
  202. }
  203. return 1;
  204. }
  205. // Repair the camera, pay the player and choose a new camera to fix
  206. public Roadworker_RepairCamera(playerid)
  207. {
  208. // Setup local variables
  209. new Float:x, Float:y, Float:z, CamID;
  210. // Pay the player for fixing this camera
  211. RewardPlayer(playerid, 2500, 1);
  212. // Let the player know he earned money for fixing this camera
  213. SendClientMessage(playerid, 0xFFFFFFFF, "{00FF00}You've earned {FFFF00}$2500{00FF00} for fixing a speedcamera");
  214. // Also increase the stats
  215. APlayerData[playerid][StatsRoadworkerJobs]++;
  216. // Save the player's account
  217. PlayerFile_Save(playerid);
  218. // Get a random speedcamera (don't allow the function to choose the same camera that just has been fixed)
  219. CamID = GetRandomCamera(APlayerData[playerid][JobLoc1]);
  220. // Store the CamID
  221. APlayerData[playerid][JobLoc1] = CamID;
  222. // Set the mission-TextDraw so the player can see it
  223. TextDrawSetString(APlayerData[playerid][MissionText], TXT_RepairSpeedcamera);
  224. // First delete the racecheckpoint
  225. DisablePlayerRaceCheckpoint(playerid);
  226. // Grab the x, y, z positions for the checkpoint
  227. x = ACameras[CamID][CamX];
  228. y = ACameras[CamID][CamY];
  229. z = ACameras[CamID][CamZ];
  230. // Create a new racecheckpoint where the player should repair a speedcamera
  231. SetPlayerRaceCheckpoint(playerid, 1, x, y, z, 0.0, 0.0, 0.0, 2.5);
  232. // Inform the player what he must do
  233. SendClientMessage(playerid, 0xFFFFFFFF, "{00FF00}Repair the next indicated speedcamera or go back to base to end the mission");
  234. // Enable the player's actions (he can move again)
  235. TogglePlayerControllable(playerid, 1);
  236. }
  237. // This function checks if there are camera's defined and returns a random CamID
  238. GetRandomCamera(Exception)
  239. {
  240. // Setup local variables
  241. new CameraList[100], CamCount = -1, CamID;
  242. // Build the list of camera's
  243. for (CamID = 0; CamID < 100; CamID++)
  244. {
  245. // Check if there is a camera defined at this location
  246. if (ACameras[CamID][CamSpeed] > 0)
  247. {
  248. // Increase the camera-counter to select the next index in the list
  249. CamCount++;
  250. // Store the CamID in the list
  251. CameraList[CamCount] = CamID;
  252. }
  253. }
  254. // If there are no camera's, return -1
  255. if (CamCount == -1)
  256. return -1;
  257. // Get a random CameraID
  258. CamID = CameraList[random(CamCount + 1)];
  259. // Prevent the same camera being chosen as before
  260. while (CamID == Exception)
  261. CamID = CameraList[random(CamCount + 1)];
  262. // Choose a random camera from the list
  263. return CamID;
  264. }
  265. // This function is used to cleanup the current job
  266. Roadworker_EndJob(playerid)
  267. {
  268. if (APlayerData[playerid][JobStarted] == true)
  269. {
  270. // Clear all data about the job from the player, so he can start a new one
  271. APlayerData[playerid][JobStarted] = false;
  272. APlayerData[playerid][JobStep] = 0;
  273. APlayerData[playerid][JobID] = 0;
  274. APlayerData[playerid][VehicleTimerTime] = 0;
  275. APlayerData[playerid][VehicleID] = 0;
  276. APlayerData[playerid][TrailerID] = 0;
  277. APlayerData[playerid][JobLoc1] = 0;
  278. APlayerData[playerid][JobLoc2] = 0;
  279. // If the player was doing the "tow broken vehicle" job-type, check if there was a vehicle created
  280. if (APlayerData[playerid][LoadID] != 0)
  281. {
  282. DestroyVehicle(APlayerData[playerid][LoadID]); // Destroy the vehicle
  283. APlayerData[playerid][LoadID] = 0; // Clear the LoadID
  284. }
  285. // Delete the checkpoints
  286. DisablePlayerCheckpoint(playerid);
  287. DisablePlayerRaceCheckpoint(playerid);
  288. // Reset the missiontext
  289. TextDrawSetString(APlayerData[playerid][MissionText], RoadWorker_NoJobText);
  290. // Kill the LoadingTimer
  291. KillTimer(APlayerData[playerid][LoadingTimer]);
  292. }
  293. return 1;
  294. }
  295. // This function creates a random vehicle, spawns it and damages it and protects it from the /cleanupcars command, so admins cannot
  296. // bug missions by cleaning up the world from spawned cars
  297. CreateBrokenVehicle(Float:x, Float:y, Float:z)
  298. {
  299. // Setup local variables
  300. new vid, panels, doors, lights, tires;
  301. new paramsengine, paramslights, paramsalarm, paramsdoors, paramsbonnet, paramsboot, paramsobjective;
  302. new BrokenVids[] = {400, 401, 402, 404, 405, 409, 410, 411, 412, 415, 419, 420, 421, 424, 426, 429, 434, 436, 438, 439, 442, 445, 451, 458, 466, 467, 474, 475, 477, 479, 480, 489, 490, 491, 492, 494, 495, 496, 500, 502, 503, 504, 505, 506, 507, 516, 517, 518, 526, 527, 528, 529, 533, 534, 535, 536, 540, 541, 542, 543, 545, 546, 547, 549, 550, 551, 552, 554, 555, 558, 559, 560, 561, 562, 565, 566, 567, 568, 575, 576, 579, 580, 582, 585, 587, 588, 589, 596, 597, 598, 599, 600, 602, 603};
  303. // Create the vehicle (choose a random vehicle from the array BrokenVids)
  304. vid = CreateVehicle(BrokenVids[random(sizeof(BrokenVids))], x, y, z, random(360), random(126), random(126), 3600);
  305. // Also set the data to prevent /cleanupcars deleting this vehicle
  306. AVehicleData[vid][Owned] = true;
  307. // Create an arrow above the vehicle to point to it (objective) and lock the doors so nobody can steal it
  308. GetVehicleParamsEx(vid, paramsengine, paramslights, paramsalarm, paramsdoors, paramsbonnet, paramsboot, paramsobjective);
  309. SetVehicleParamsEx(vid, paramsengine, paramslights, paramsalarm, true, paramsbonnet, paramsboot, true);
  310. // Damage all components of the vehicle
  311. tires = encode_tires(1, 1, 1, 1); // All tires popped
  312. panels = encode_panels(3, 3, 3, 3, 3, 3, 3); // All panels broken off
  313. doors = encode_doors(4, 4, 4, 4, 4, 4); // All doors broken
  314. lights = encode_lights(1, 1, 1, 1); // All lights damaged
  315. // Update the damage status of the vehicle
  316. UpdateVehicleDamageStatus(vid, panels, doors, lights, tires);
  317. // Set the vehicle damage quite low (this will make the vehicle smoke)
  318. SetVehicleHealth(vid, 300.0);
  319. return vid;
  320. }
  321. encode_tires(tire1, tire2, tire3, tire4)
  322. {
  323. return tire1 | (tire2 << 1) | (tire3 << 2) | (tire4 << 3);
  324. }
  325. encode_panels(flp, frp, rlp, rrp, windshield, front_bumper, rear_bumper)
  326. {
  327. return flp | (frp << 4) | (rlp << 8) | (rrp << 12) | (windshield << 16) | (front_bumper << 20) | (rear_bumper << 24);
  328. }
  329. encode_doors(bonnet, boot, driver_door, passenger_door, behind_driver_door, behind_passenger_door)
  330. {
  331. #pragma unused behind_driver_door
  332. #pragma unused behind_passenger_door
  333. return bonnet | (boot << 8) | (driver_door << 16) | (passenger_door << 24);
  334. }
  335. encode_lights(light1, light2, light3, light4)
  336. {
  337. return light1 | (light2 << 1) | (light3 << 2) | (light4 << 3);
  338. }