PPC_MissionsPilot.inc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. // Forward the public function used as a timer to load/unload your vehicle
  2. forward Pilot_Plane_LoadUnload(playerid);
  3. // This function is called when a pilot wants to start a job by entering "/work"
  4. Pilot_StartRandomJob(playerid)
  5. {
  6. // Setup local variables
  7. new PilotJobSet;
  8. // Check the vehicle-model of the player to decide which job the player can get
  9. switch (GetVehicleModel(GetPlayerVehicleID(playerid)))
  10. {
  11. case VehicleShamal, VehicleNevada: // Select a random job for planes
  12. PilotJobSet = Pilot_Plane_SetRandomJob(playerid);
  13. case VehicleMaverick, VehicleCargobob: // Select a random job for helicopters
  14. PilotJobSet = Pilot_Heli_SetRandomJob(playerid);
  15. }
  16. // Check if a job was set correctly
  17. switch (PilotJobSet)
  18. {
  19. case 1, 2:
  20. {
  21. // Setup local variables
  22. new StartLoc[50], EndLoc[50], Load[50], RouteText[255], Float:x, Float:y, Float:z, LoadMsg[128];
  23. // Job has started
  24. APlayerData[playerid][JobStarted] = true;
  25. // Set jobstep to 1 (going to load the goods)
  26. APlayerData[playerid][JobStep] = 1;
  27. // Get the startlocation, endlocation and the load texts
  28. format(StartLoc, 50, ALocations[APlayerData[playerid][JobLoc1]][LocationName]);
  29. format(EndLoc, 50, ALocations[APlayerData[playerid][JobLoc2]][LocationName]);
  30. format(Load, 50, ALoads[APlayerData[playerid][LoadID]][LoadName]);
  31. // Combine it all into a string for the TextDraw (the player can see this all the time) to describe the mission
  32. format(RouteText, 255, TXT_TransportingFromToPickup, Load, StartLoc, EndLoc);
  33. // Set the TextDraw so the player can see it
  34. TextDrawSetString(APlayerData[playerid][MissionText], RouteText);
  35. // Grab the x, y, z positions for the first location
  36. x = ALocations[APlayerData[playerid][JobLoc1]][LocX];
  37. y = ALocations[APlayerData[playerid][JobLoc1]][LocY];
  38. z = ALocations[APlayerData[playerid][JobLoc1]][LocZ];
  39. // Create a checkpoint where the player should load the goods
  40. SetPlayerCheckpoint(playerid, x, y, z, 7);
  41. // Inform the player that he must load his goods
  42. format(LoadMsg, 128, TXT_PickupCargoAt, Load, StartLoc);
  43. SendClientMessage(playerid, 0xFFFFFFFF, LoadMsg);
  44. }
  45. }
  46. return 1;
  47. }
  48. // This function sets a random job for a plane vehicle and returns 1 if a job has been set
  49. // The function returns 0 if a job couldn't be set (if the player is driving an invalid vehicle to start piloting-jobs)
  50. Pilot_Plane_SetRandomJob(playerid)
  51. {
  52. // If the player is the driver of the vehicle (GetPlayerVehicleSeat returns -1 if the player is not in a vehicle)
  53. if (GetPlayerVehicleSeat(playerid) == 0)
  54. {
  55. // Check the vehicle-model of the player to decide which job the player can get
  56. switch (GetVehicleModel(GetPlayerVehicleID(playerid)))
  57. {
  58. case VehicleShamal, VehicleNevada:
  59. {
  60. // Get a random LoadID from the pilot-products (only the planes)
  61. APlayerData[playerid][LoadID] = Product_GetRandom(PCV_PilotPlane);
  62. // Also get a random start-location and end-location
  63. APlayerData[playerid][JobLoc1] = Product_GetRandomStartLoc(APlayerData[playerid][LoadID]);
  64. APlayerData[playerid][JobLoc2] = Product_GetRandomEndLoc(APlayerData[playerid][LoadID]);
  65. // Make sure the destination is not closeby (pilot-locations are ALL includes in the array)
  66. while (Locations_CheckDistance(APlayerData[playerid][JobLoc1], APlayerData[playerid][JobLoc2], 1000.0) == 0)
  67. {
  68. // If both locations are too close together, keep searching for a random delivery-location that's further away
  69. APlayerData[playerid][JobLoc2] = Product_GetRandomEndLoc(APlayerData[playerid][LoadID]);
  70. }
  71. // Return 1 to indicate that a job has been set correctly
  72. return 1;
  73. }
  74. }
  75. }
  76. // If no job could be set correctly, return 0
  77. return 0;
  78. }
  79. // This function sets a random job for a helicopter vehicle and returns 2 if a job has been set
  80. // The function returns 0 if a job couldn't be set (if the player is driving an invalid vehicle to start piloting-jobs)
  81. Pilot_Heli_SetRandomJob(playerid)
  82. {
  83. // If the player is the driver of the vehicle (GetPlayerVehicleSeat returns -1 if the player is not in a vehicle)
  84. if (GetPlayerVehicleSeat(playerid) == 0)
  85. {
  86. // Check the vehicle-model of the player to decide which job the player can get
  87. switch (GetVehicleModel(GetPlayerVehicleID(playerid)))
  88. {
  89. case VehicleMaverick, VehicleCargobob:
  90. {
  91. // Get a random LoadID from the pilot-products (only the helicopters)
  92. APlayerData[playerid][LoadID] = Product_GetRandom(PCV_PilotHelicopter);
  93. // Also get a random start-location and end-location
  94. APlayerData[playerid][JobLoc1] = Product_GetRandomStartLoc(APlayerData[playerid][LoadID]);
  95. APlayerData[playerid][JobLoc2] = Product_GetRandomEndLoc(APlayerData[playerid][LoadID]);
  96. // Make sure the destination is not closeby (pilot-locations are ALL includes in the array)
  97. while (Locations_CheckDistance(APlayerData[playerid][JobLoc1], APlayerData[playerid][JobLoc2], 1000.0) == 0)
  98. {
  99. // If both locations are too close together, keep searching for a random delivery-location that's further away
  100. APlayerData[playerid][JobLoc2] = Product_GetRandomEndLoc(APlayerData[playerid][LoadID]);
  101. }
  102. // Return 2 to indicate that a job has been set correctly
  103. return 2;
  104. }
  105. }
  106. }
  107. // If no job could be set correctly, return 0
  108. return 0;
  109. }
  110. // This function is called when a pilot enters a checkpoint
  111. Pilot_OnPlayerEnterCheckpoint(playerid)
  112. {
  113. new LoadMsg[128];
  114. // Check the jobstep
  115. switch (APlayerData[playerid][JobStep])
  116. {
  117. // JobStep is 1 (pilot is loading his goods at the checkpoint)
  118. case 1: format(LoadMsg, 128, TXT_LoadingGoods, ALoads[APlayerData[playerid][LoadID]][LoadName]);
  119. // JobStep is 2 (pilot is unloading his goods at the checkpoint)
  120. case 2: format(LoadMsg, 128, TXT_UnloadingGoods, ALoads[APlayerData[playerid][LoadID]][LoadName]);
  121. }
  122. // Disable the player's actions (he cannot move anymore)
  123. TogglePlayerControllable(playerid, 0);
  124. // Check the vehiclemodel of the player
  125. new vehicleid = GetPlayerVehicleID(playerid);
  126. switch (GetVehicleModel(vehicleid))
  127. {
  128. case VehicleShamal, VehicleNevada: // A plane needs 5 seconds to load/unload
  129. {
  130. // Show the message to inform him what he's doing (loading/unloading)
  131. GameTextForPlayer(playerid, LoadMsg, 5000, 5);
  132. // Start a timer (Public function "LoadUnload(playerid)" gets called when the timer runs out)
  133. APlayerData[playerid][LoadingTimer] = SetTimerEx("Pilot_Plane_LoadUnload", 5000, false, "d" , playerid);
  134. }
  135. case VehicleMaverick, VehicleCargobob: // A helicopter only needs 3 seconds to load/unload
  136. {
  137. // Show the message to inform him what he's doing (loading/unloading)
  138. GameTextForPlayer(playerid, LoadMsg, 3000, 3);
  139. // Start a timer (Public function "LoadUnload(playerid)" gets called when the timer runs out)
  140. APlayerData[playerid][LoadingTimer] = SetTimerEx("Pilot_Plane_LoadUnload", 3000, false, "d" , playerid);
  141. // When in a helicopter, turn off the engine so the helicopter lands and doesn't drift away with the wind
  142. new engine,lights,alarm,doors,bonnet,boot,objective;
  143. GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
  144. SetVehicleParamsEx(vehicleid, 0, lights, alarm, doors, bonnet, boot, objective);
  145. }
  146. }
  147. return 1;
  148. }
  149. // After a pilot entered a checkpoint, a timer is created. This function is called when the timer runs out
  150. public Pilot_Plane_LoadUnload(playerid)
  151. {
  152. // Check the JobStep
  153. switch (APlayerData[playerid][JobStep])
  154. {
  155. case 1: // Player must load his goods
  156. {
  157. // Setup local variables
  158. new StartLoc[50], EndLoc[50], Load[50], RouteText[255], Float:x, Float:y, Float:z, UnloadMsg[100];
  159. // Set JobStep to 2 (unloading goods)
  160. APlayerData[playerid][JobStep] = 2;
  161. // Delete the loading-checkpoint
  162. DisablePlayerCheckpoint(playerid);
  163. // Get the startlocation, endlocation and the load texts
  164. format(StartLoc, 50, ALocations[APlayerData[playerid][JobLoc1]][LocationName]);
  165. format(EndLoc, 50, ALocations[APlayerData[playerid][JobLoc2]][LocationName]);
  166. format(Load, 50, ALoads[APlayerData[playerid][LoadID]][LoadName]);
  167. // Update the missiontext
  168. format(RouteText, 255, TXT_TransportingFromToDeliver, Load, StartLoc, EndLoc);
  169. // Set the TextDraw so the player can see it
  170. TextDrawSetString(APlayerData[playerid][MissionText], RouteText);
  171. // Grab the x, y, z positions for the second location (to unload the goods)
  172. x = ALocations[APlayerData[playerid][JobLoc2]][LocX];
  173. y = ALocations[APlayerData[playerid][JobLoc2]][LocY];
  174. z = ALocations[APlayerData[playerid][JobLoc2]][LocZ];
  175. // Create a checkpoint where the player should unload the goods
  176. SetPlayerCheckpoint(playerid, x, y, z, 7);
  177. // Inform the player that he must unload his goods
  178. format(UnloadMsg, 100, TXT_DeliverCargoTo, Load, EndLoc);
  179. SendClientMessage(playerid, 0xFFFFFFFF, UnloadMsg);
  180. }
  181. case 2: // Player is delivering his goods
  182. {
  183. // Setup local variables
  184. new StartLoc[50], EndLoc[50], Load[50], Msg1[128], Msg2[128], Name[24];
  185. // Get the player name
  186. GetPlayerName(playerid, Name, sizeof(Name));
  187. // Get the startlocation, endlocation and the load texts
  188. format(StartLoc, 50, ALocations[APlayerData[playerid][JobLoc1]][LocationName]);
  189. format(EndLoc, 50, ALocations[APlayerData[playerid][JobLoc2]][LocationName]);
  190. format(Load, 50, ALoads[APlayerData[playerid][LoadID]][LoadName]);
  191. // Construct the message sent to all players that this player completed a pilot mission
  192. format(Msg1, 128, TXT_PlayerCompletedPilotJob, Name, Load);
  193. format(Msg2, 128, TXT_PlayerCompletedPilotJobInfo, StartLoc, EndLoc);
  194. SendClientMessageToAll(0xFFFFFFFF, Msg1);
  195. SendClientMessageToAll(0xFFFFFFFF, Msg2);
  196. // Setup local variables
  197. new Float:x1, Float:y1, Float:x2, Float:y2, Float:Distance, Message[128], Payment;
  198. // Grab the x, y, z positions for the first location (to load the goods)
  199. x1 = ALocations[APlayerData[playerid][JobLoc1]][LocX];
  200. y1 = ALocations[APlayerData[playerid][JobLoc1]][LocY];
  201. // Grab the x, y, z positions for the second location (to unload the goods)
  202. x2 = ALocations[APlayerData[playerid][JobLoc2]][LocX];
  203. y2 = ALocations[APlayerData[playerid][JobLoc2]][LocY];
  204. // Calculate the distance between both points
  205. Distance = floatsqroot(((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)));
  206. // Calculate the payment for the player
  207. Payment = floatround((Distance * ALoads[APlayerData[playerid][LoadID]][PayPerUnit]), floatround_floor);
  208. // Pay the player based on the distance between the loading-point and unloading-point
  209. RewardPlayer(playerid, Payment, 1);
  210. // Send a message to let the player know he finished his mission and got paid
  211. format(Message, 128, TXT_RewardJob, Payment);
  212. SendClientMessage(playerid, 0xFFFFFFFF, Message);
  213. // Increase the stats for completing a pilot job
  214. APlayerData[playerid][StatsPilotJobs]++;
  215. // Also save the data (in case the server crashes, progress would be lost)
  216. PlayerFile_Save(playerid);
  217. // End the current pilot job (clear mission-data)
  218. Pilot_EndJob(playerid);
  219. }
  220. }
  221. // Enable the player again (he can move again)
  222. TogglePlayerControllable(playerid, 1);
  223. // Start the engine again (in case the vehicle was a helicopter, where the engine was turned off by entering a checkpoint)
  224. new vehicleid = GetPlayerVehicleID(playerid);
  225. new engine,lights,alarm,doors,bonnet,boot,objective;
  226. GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
  227. SetVehicleParamsEx(vehicleid, 1, lights, alarm, doors, bonnet, boot, objective);
  228. return 1;
  229. }
  230. // This function is used to cleanup the current job
  231. Pilot_EndJob(playerid)
  232. {
  233. // Check if a job has started
  234. if (APlayerData[playerid][JobStarted] == true)
  235. {
  236. // Clear all data about the job from the player, so he can start a new one
  237. APlayerData[playerid][JobStarted] = false;
  238. APlayerData[playerid][JobStep] = 0;
  239. APlayerData[playerid][LoadID] = 0;
  240. APlayerData[playerid][JobLoc1] = 0;
  241. APlayerData[playerid][JobLoc2] = 0;
  242. // Delete the checkpoint
  243. DisablePlayerCheckpoint(playerid);
  244. // Reset the missiontext
  245. TextDrawSetString(APlayerData[playerid][MissionText], Pilot_NoJobText);
  246. // Kill the LoadingTimer
  247. KillTimer(APlayerData[playerid][LoadingTimer]);
  248. }
  249. return 1;
  250. }