1
0

PPC_MissionsMafia.inc 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. // Forward the function to timer to check players every second to see if they're carrying a mafia-load
  2. forward Mafia_CheckMafiaLoads(playerid);
  3. // Forward the public function used as a timer to load/unload your vehicle
  4. forward Mafia_LoadUnload(playerid);
  5. // This function is called when a mafia wants to start a job by entering "/work"
  6. Mafia_StartRandomJob(playerid)
  7. {
  8. if (APlayerData[playerid][JobStarted] == false)
  9. {
  10. // Setup local variables
  11. new StartLoc[50], EndLoc[50], Load[50], RouteText[255], Float:x, Float:y, Float:z, LoadMsg[128];
  12. // Job has started
  13. APlayerData[playerid][JobStarted] = true;
  14. // Get a random LoadID from the mafia-products
  15. APlayerData[playerid][LoadID] = Product_GetRandom(PCV_MafiaVan);
  16. // Also get a random start-location and end-location
  17. APlayerData[playerid][JobLoc1] = Product_GetRandomStartLoc(APlayerData[playerid][LoadID]);
  18. APlayerData[playerid][JobLoc2] = Product_GetRandomEndLoc(APlayerData[playerid][LoadID]);
  19. // Set jobstep to 1 (going to load the goods)
  20. APlayerData[playerid][JobStep] = 1;
  21. // Get the startlocation, endlocation and the load texts
  22. format(StartLoc, 50, ALocations[APlayerData[playerid][JobLoc1]][LocationName]);
  23. format(EndLoc, 50, ALocations[APlayerData[playerid][JobLoc2]][LocationName]);
  24. format(Load, 50, ALoads[APlayerData[playerid][LoadID]][LoadName]);
  25. // Combine it all into a string for the TextDraw (the player can see this all the time) to describe the mission
  26. format(RouteText, 255, TXT_HaulingCargoFromToPickup, Load, StartLoc, EndLoc);
  27. // Set the TextDraw so the player can see it
  28. TextDrawSetString(APlayerData[playerid][MissionText], RouteText);
  29. // Grab the x, y, z positions for the first location
  30. x = ALocations[APlayerData[playerid][JobLoc1]][LocX];
  31. y = ALocations[APlayerData[playerid][JobLoc1]][LocY];
  32. z = ALocations[APlayerData[playerid][JobLoc1]][LocZ];
  33. // Create a checkpoint where the player should load the goods
  34. SetPlayerCheckpoint(playerid, x, y, z, 7);
  35. // Store the vehicleID (required to be able to check if the player left his vehicle)
  36. APlayerData[playerid][VehicleID] = GetPlayerVehicleID(playerid);
  37. // Set the job-fail-time for the global vehicle-timer
  38. APlayerData[playerid][VehicleTimerTime] = Job_TimeToFailMission;
  39. // Inform the player that he must load his goods
  40. format(LoadMsg, 128, TXT_PickupCargoAt, Load, StartLoc);
  41. SendClientMessage(playerid, 0xFFFFFFFF, LoadMsg);
  42. }
  43. return 1;
  44. }
  45. // This timer is created every time a player changes his class to mafia and is called every second
  46. public Mafia_CheckMafiaLoads(playerid)
  47. {
  48. // Scan through all players
  49. for (new PlayerToCheck; PlayerToCheck < MAX_PLAYERS; PlayerToCheck++)
  50. {
  51. // check if this player is connected
  52. if (IsPlayerConnected(PlayerToCheck))
  53. {
  54. //Check if that player is carrying a mafia-load
  55. if (APlayerData[PlayerToCheck][MafiaLoad] == true)
  56. SetPlayerMarkerForPlayer(playerid, PlayerToCheck, 0xFF0000FF); // Make that player red to the mafia-player
  57. else
  58. if (APlayerData[PlayerToCheck][PlayerClass] == ClassTruckDriver) // Reset the playercolor for truckers (only truckers can carry mafia-loads)
  59. SetPlayerMarkerForPlayer(playerid, PlayerToCheck, ColorClassTruckDriver);
  60. }
  61. }
  62. // If the mafia-player hasn't started a job, check if he has stolen a mafiaload from a trucker
  63. if (APlayerData[playerid][JobStarted] == false)
  64. {
  65. new vehicle = GetPlayerVehicleID(playerid);
  66. new trailer = GetVehicleTrailer(vehicle);
  67. // Check if the mafia-player has hijacked a mafia-load already
  68. if (APlayerData[playerid][MafiaLoadHijacked] == false)
  69. {
  70. // If the mafia-player hasn't hijacked a mafia-load yet, check if he did now (check vehicle and trailer)
  71. if ((AVehicleData[vehicle][MafiaLoad] == true) || (AVehicleData[trailer][MafiaLoad] == true))
  72. {
  73. // Store the vehicleid and trailerid to be able to check if the mafia-player lost his load afterwards
  74. APlayerData[playerid][VehicleID] = vehicle;
  75. APlayerData[playerid][TrailerID] = trailer;
  76. // Now the mafia-player has hijacked a mafia-load
  77. APlayerData[playerid][MafiaLoadHijacked] = true;
  78. // Set the checkpoint where the mafia-player must bring the load
  79. SetPlayerCheckpoint(playerid, 2867, 939, 10.8, 7.0);
  80. // Update the missiontext
  81. TextDrawSetString(APlayerData[playerid][MissionText], TXT_MafiaDeliverStolenLoad);
  82. }
  83. }
  84. // Check if the mafia-player already hijacked a mafia-load
  85. if (APlayerData[playerid][MafiaLoadHijacked] == true)
  86. {
  87. // If the mafia-player has hijacked a mafia-load, check if he still has the load (check vehicle and trailer)
  88. if ((APlayerData[playerid][VehicleID] == vehicle) && (APlayerData[playerid][TrailerID] == trailer))
  89. // Do nothing if vehicle and trailer are the same
  90. return 1;
  91. else
  92. {
  93. // Clear the vehicleid and trailerid
  94. APlayerData[playerid][VehicleID] = 0;
  95. APlayerData[playerid][TrailerID] = 0;
  96. // Now the mafia-player lost his stolen load
  97. APlayerData[playerid][MafiaLoadHijacked] = false;
  98. // Disable the checkpoint where he must bring his load
  99. DisablePlayerCheckpoint(playerid);
  100. // Reset the missiontext
  101. TextDrawSetString(APlayerData[playerid][MissionText], Mafia_NoJobText);
  102. }
  103. }
  104. }
  105. return 1;
  106. }
  107. // This function is called whenever a mafia player enters a checkpoint
  108. Mafia_OnPlayerEnterCheckpoint(playerid)
  109. {
  110. // First check if the mafia player started a job or not
  111. if (APlayerData[playerid][JobStarted] == false) // Mafia player delivered a mafia-load
  112. {
  113. // This code handles stolen mafia-loads
  114. new vehicle = GetPlayerVehicleID(playerid);
  115. new trailer = GetVehicleTrailer(vehicle);
  116. // If the mafia player has a trailer, so detach and respawn the trailer
  117. if (trailer > 0)
  118. {
  119. DetachTrailerFromVehicle(vehicle);
  120. SetVehicleToRespawn(trailer);
  121. }
  122. else // The mafia player has no trailer, so the load is inside the truck -> remove player from vehicle and respawn the vehicle
  123. {
  124. RemovePlayerFromVehicle(playerid);
  125. SetVehicleToRespawn(vehicle);
  126. }
  127. // Reward the mafia player (give cash and points)
  128. RewardPlayer(playerid, 5000, 2);
  129. // Let the player know he succesfully delivered a stolen load to the mafia hideout
  130. SendClientMessage(playerid, 0xFFFFFFFF, TXT_MafiaDeliveredStolenLoad);
  131. // Increase the stats for completing a delivery of a stolen mafiaload
  132. APlayerData[playerid][StatsMafiaStolen]++;
  133. // Also save the data (in case the server crashes, progress would be lost)
  134. PlayerFile_Save(playerid);
  135. // Cleanup
  136. APlayerData[playerid][VehicleID] = 0;
  137. APlayerData[playerid][TrailerID] = 0;
  138. // Disable the checkpoint where he must bring his load
  139. DisablePlayerCheckpoint(playerid);
  140. // Reset the missiontext
  141. TextDrawSetString(APlayerData[playerid][MissionText], Mafia_NoJobText);
  142. }
  143. else // The mafia-player is doing a job
  144. {
  145. // Check if the player is inside his vehicle while entering a checkpoint
  146. if (GetPlayerVehicleID(playerid) == APlayerData[playerid][VehicleID])
  147. {
  148. new LoadMsg[128];
  149. // Check the jobstep
  150. switch (APlayerData[playerid][JobStep])
  151. {
  152. // JobStep is 1 (mafia is loading his goods at the checkpoint)
  153. case 1: format(LoadMsg, 128, TXT_LoadingGoods, ALoads[APlayerData[playerid][LoadID]][LoadName]);
  154. // JobStep is 2 (mafia is unloading his goods at the checkpoint)
  155. case 2: format(LoadMsg, 128, TXT_UnloadingGoods, ALoads[APlayerData[playerid][LoadID]][LoadName]);
  156. }
  157. // Disable the player's actions (he cannot move anymore)
  158. TogglePlayerControllable(playerid, 0);
  159. // Show the message to inform him what he's doing (loading/unloading)
  160. GameTextForPlayer(playerid, LoadMsg, 5000, 5);
  161. // Start a timer (Public function "LoadUnload(playerid)" gets called when the timer runs out)
  162. APlayerData[playerid][LoadingTimer] = SetTimerEx("Mafia_LoadUnload", 5000, false, "d" , playerid);
  163. }
  164. }
  165. return 1;
  166. }
  167. // After a mafia entered a checkpoint, a timer is created. This function is called when the timer runs out
  168. public Mafia_LoadUnload(playerid)
  169. {
  170. // Setup local variables
  171. new Name[24], Msg[128];
  172. // Get the player name
  173. GetPlayerName(playerid, Name, sizeof(Name));
  174. // Check the JobStep
  175. switch (APlayerData[playerid][JobStep])
  176. {
  177. case 1: // Player must load his goods
  178. {
  179. // Setup local variables
  180. new StartLoc[50], EndLoc[50], Load[50], RouteText[255], Float:x, Float:y, Float:z, UnloadMsg[100];
  181. // Set JobStep to 2 (unloading goods)
  182. APlayerData[playerid][JobStep] = 2;
  183. // Delete the loading-checkpoint
  184. DisablePlayerCheckpoint(playerid);
  185. // Get the startlocation, endlocation and the load texts
  186. format(StartLoc, 50, ALocations[APlayerData[playerid][JobLoc1]][LocationName]);
  187. format(EndLoc, 50, ALocations[APlayerData[playerid][JobLoc2]][LocationName]);
  188. format(Load, 50, ALoads[APlayerData[playerid][LoadID]][LoadName]);
  189. // Update the missiontext
  190. format(RouteText, 255, TXT_HaulingCargoFromToDeliver, Load, StartLoc, EndLoc);
  191. // Set the TextDraw so the player can see it
  192. TextDrawSetString(APlayerData[playerid][MissionText], RouteText);
  193. // Grab the x, y, z positions for the second location (to unload the goods)
  194. x = ALocations[APlayerData[playerid][JobLoc2]][LocX];
  195. y = ALocations[APlayerData[playerid][JobLoc2]][LocY];
  196. z = ALocations[APlayerData[playerid][JobLoc2]][LocZ];
  197. // Create a checkpoint where the player should unload the goods
  198. SetPlayerCheckpoint(playerid, x, y, z, 7);
  199. // Add 4 to the player's wanted level
  200. SetPlayerWantedLevel(playerid, GetPlayerWantedLevel(playerid) + 4);
  201. // Inform the police this mafia player is wanted
  202. format(Msg, 128, "{00FF00}Mafia {FFFF00}%s{00FF00} is transporting illegal goods, pursue and fine him", Name);
  203. Police_SendMessage(Msg);
  204. // Inform the player that he must unload his goods
  205. format(UnloadMsg, 100, TXT_DeliverCargoTo, Load, EndLoc);
  206. SendClientMessage(playerid, 0xFFFFFFFF, UnloadMsg);
  207. }
  208. case 2: // Player is delivering his goods
  209. {
  210. // Setup local variables
  211. new StartLoc[50], EndLoc[50], Load[50], Msg1[128], Msg2[128];
  212. // Get the startlocation, endlocation and the load texts
  213. format(StartLoc, 50, ALocations[APlayerData[playerid][JobLoc1]][LocationName]);
  214. format(EndLoc, 50, ALocations[APlayerData[playerid][JobLoc2]][LocationName]);
  215. format(Load, 50, ALoads[APlayerData[playerid][LoadID]][LoadName]);
  216. // Construct the message sent to all players that this player completed a mafia mission
  217. format(Msg1, 128, TXT_PlayerCompletedMafiaJob, Name, Load);
  218. format(Msg2, 128, TXT_PlayerCompletedMafiaJobInfo, StartLoc, EndLoc);
  219. SendClientMessageToAll(0xFFFFFFFF, Msg1);
  220. SendClientMessageToAll(0xFFFFFFFF, Msg2);
  221. // Setup local variables
  222. new Float:x1, Float:y1, Float:x2, Float:y2, Float:Distance, Message[128], Payment;
  223. // Grab the x, y, z positions for the first location (to load the goods)
  224. x1 = ALocations[APlayerData[playerid][JobLoc1]][LocX];
  225. y1 = ALocations[APlayerData[playerid][JobLoc1]][LocY];
  226. // Grab the x, y, z positions for the second location (to unload the goods)
  227. x2 = ALocations[APlayerData[playerid][JobLoc2]][LocX];
  228. y2 = ALocations[APlayerData[playerid][JobLoc2]][LocY];
  229. // Calculate the distance between both points
  230. Distance = floatsqroot(((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)));
  231. // Calculate the payment for the player
  232. Payment = floatround((Distance * ALoads[APlayerData[playerid][LoadID]][PayPerUnit]), floatround_floor);
  233. // Reward the player (give cash and points)
  234. RewardPlayer(playerid, Payment, 2);
  235. // Send a message to let the player know he finished his mission and got paid
  236. format(Message, 128, TXT_RewardJob, Payment);
  237. SendClientMessage(playerid, 0xFFFFFFFF, Message);
  238. // Increase the stats for completing a mafia job
  239. APlayerData[playerid][StatsMafiaJobs]++;
  240. // Also save the data (in case the server crashes, progress would be lost)
  241. PlayerFile_Save(playerid);
  242. // End the current mafia job (clear mission-data)
  243. Mafia_EndJob(playerid);
  244. }
  245. }
  246. // Enable the player again (he can move again)
  247. TogglePlayerControllable(playerid, 1);
  248. return 1;
  249. }
  250. // This function gets called when the mafia player dies (or changes class)
  251. Mafia_EndJob(playerid)
  252. {
  253. // Kill the PlayerCheckTimer
  254. KillTimer(APlayerData[playerid][PlayerCheckTimer]);
  255. // Scan through all players (to reset them to their default colors for the mafia-player)
  256. for (new PlayerToCheck; PlayerToCheck < MAX_PLAYERS; PlayerToCheck++)
  257. {
  258. // Check if this player is connected
  259. if (IsPlayerConnected(PlayerToCheck))
  260. if (APlayerData[PlayerToCheck][PlayerClass] == ClassTruckDriver) // Reset the playercolor for truckers (only truckers can carry mafia-loads)
  261. SetPlayerMarkerForPlayer(playerid, PlayerToCheck, ColorClassTruckDriver);
  262. }
  263. // Check if a job has started
  264. if (APlayerData[playerid][JobStarted] == true)
  265. {
  266. // Clear all data about the job from the player, so he can start a new one
  267. APlayerData[playerid][JobStarted] = false;
  268. APlayerData[playerid][JobID] = 0;
  269. APlayerData[playerid][JobStep] = 0;
  270. APlayerData[playerid][LoadID] = 0;
  271. APlayerData[playerid][JobLoc1] = 0;
  272. APlayerData[playerid][JobLoc2] = 0;
  273. // Reset the missiontext
  274. TextDrawSetString(APlayerData[playerid][MissionText], Mafia_NoJobText);
  275. // Kill the LoadingTimer
  276. KillTimer(APlayerData[playerid][LoadingTimer]);
  277. // Check if the player has a wanted level of 4 or higher
  278. if (GetPlayerWantedLevel(playerid) >= 4)
  279. SetPlayerWantedLevel(playerid, GetPlayerWantedLevel(playerid) - 4); // Reduce the wanted level by 4
  280. else
  281. SetPlayerWantedLevel(playerid, 0); // If the player has a wanted level of less than 4, reset the wanted level to 0
  282. }
  283. // Also cleanup the vehicle and trailer id's
  284. APlayerData[playerid][VehicleID] = 0;
  285. APlayerData[playerid][TrailerID] = 0;
  286. // Disable the checkpoint where he must bring his load
  287. DisablePlayerCheckpoint(playerid);
  288. return 1;
  289. }