1
0

PPC_MissionsCourier.inc 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. // This function gets called whenever a courier player enters "/work"
  2. Courier_StartJob(playerid)
  3. {
  4. // Setup local variables
  5. new HouseCounter, HousesInRange[200], DialogList[200];
  6. // First clear the house-list
  7. for (new i; i < 11; i++)
  8. APlayerData[playerid][CourierHouses][i] = 0;
  9. // Count how many owned houses are in range of the player
  10. for (new HouseID = 1; HouseID < MAX_HOUSES; HouseID++)
  11. {
  12. // Check if the house is owned
  13. if (AHouseData[HouseID][Owned] == true)
  14. {
  15. // Check if the house is in range of the player
  16. if (IsPlayerInRangeOfPoint(playerid, CourierJobRange, AHouseData[HouseID][HouseX], AHouseData[HouseID][HouseY], AHouseData[HouseID][HouseZ]))
  17. {
  18. // Check if there aren't 200 in-range houses have been found yet
  19. if (HouseCounter < 200)
  20. {
  21. HousesInRange[HouseCounter] = HouseID; // Store the HouseID in the list of in-range houses
  22. HouseCounter++; // Increase the number of owned houses in range of the player (range = 1000 meters)
  23. }
  24. else
  25. {
  26. break; // Stop searching for more houses (200 is the maximum)
  27. }
  28. }
  29. }
  30. }
  31. // Abort the mission if there are less than 2 houses in range and inform the player
  32. if (HouseCounter < 2)
  33. {
  34. SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}Not enough owned houses in range to deliver packages, try some other spot");
  35. return 0;
  36. }
  37. // Try to add the 3 lines to the dialog-list
  38. if (HouseCounter >= 2)
  39. {
  40. format(DialogList, sizeof(DialogList), "Deliver 2 packages\n"); // Add the line to the dialog
  41. APlayerData[playerid][CourierMaxStep] = 2; // Set the number of houses for the job to 2
  42. }
  43. if (HouseCounter >= 5)
  44. {
  45. format(DialogList, sizeof(DialogList), "%sDeliver 5 packages\n", DialogList); // Add the line to the dialog
  46. APlayerData[playerid][CourierMaxStep] = 5; // Set the number of houses for the job to 5
  47. }
  48. if (HouseCounter >= 10)
  49. {
  50. format(DialogList, sizeof(DialogList), "%sDeliver 10 packages\n", DialogList); // Add the line to the dialog
  51. APlayerData[playerid][CourierMaxStep] = 10; // Set the number of houses for the job to 10
  52. }
  53. // Choose a random house for the first house to visit
  54. APlayerData[playerid][CourierHouses][1] = HousesInRange[random(HouseCounter)];
  55. // Now choose as many houses randomly as allowed, starting from the second
  56. for (new i = 2; i <= APlayerData[playerid][CourierMaxStep]; i++)
  57. {
  58. // Copy a random HouseID from the prepared list on in-range houses to the job-list
  59. APlayerData[playerid][CourierHouses][i] = HousesInRange[random(HouseCounter)];
  60. // If the HouseID is the same as the previous HouseID (the player would visit the same house twice in a row)
  61. while (APlayerData[playerid][CourierHouses][i - 1] == APlayerData[playerid][CourierHouses][i])
  62. APlayerData[playerid][CourierHouses][i] = HousesInRange[random(HouseCounter)]; // Get a new random HouseID as long as the HouseID is the same as the previous one
  63. }
  64. // Let the player choose how many packages he wants to deliver
  65. ShowPlayerDialog(playerid, DialogCourierSelectQuant, DIALOG_STYLE_LIST, "Choose how many packages you want to deliver", DialogList, TXT_DialogButtonSelect, TXT_DialogButtonCancel);
  66. return 1;
  67. }
  68. // This function is called when the player has chosen how many packages he wants to deliver
  69. Courier_BeginJob(playerid)
  70. {
  71. // Setup local variables
  72. new RouteText[128], Step, HouseID, Float:x, Float:y, Float:z;
  73. // Job has started
  74. APlayerData[playerid][JobStarted] = true;
  75. // Store the vehicleID (required to be able to check if the player left his vehicle)
  76. APlayerData[playerid][VehicleID] = GetPlayerVehicleID(playerid);
  77. // Set jobstep to 1 (going to the first house)
  78. Step = 1;
  79. APlayerData[playerid][JobStep] = Step;
  80. // Get the HouseID of the house where the mission starts (the first house in the list of in-range owned house)
  81. HouseID = APlayerData[playerid][CourierHouses][Step];
  82. // Set the TextDraw so the player can see it
  83. format(RouteText, 255, "~w~Deliver package ~b~%i/%i~w~ to: ~r~%s", Step, APlayerData[playerid][CourierMaxStep], AHouseData[HouseID][HouseName]);
  84. TextDrawSetString(APlayerData[playerid][MissionText], RouteText);
  85. // Grab the x, y, z positions for the first location
  86. x = AHouseData[HouseID][HouseX];
  87. y = AHouseData[HouseID][HouseY];
  88. z = AHouseData[HouseID][HouseZ];
  89. // Create a checkpoint where the player should deliver his package
  90. SetPlayerCheckpoint(playerid, x, y, z, 3);
  91. // Set the job-fail-time for the global vehicle-timer
  92. APlayerData[playerid][VehicleTimerTime] = Job_TimeToFailMission;
  93. // Send the player a message to inform him that the mission has started
  94. SendClientMessage(playerid, 0xFFFFFFFF, "{00FF00}Deliver packages to player's houses");
  95. return 1;
  96. }
  97. // This function is called when a courier enters a checkpoint
  98. Courier_OnPlayerEnterCheckpoint(playerid)
  99. {
  100. // Setup local variables
  101. new RouteText[128], Step, HouseID, Float:x, Float:y, Float:z, Name[24], Msg[128], Payment;
  102. // Check if the player is outside his vehicle while entering a checkpoint
  103. if (GetPlayerVehicleSeat(playerid) == -1)
  104. {
  105. // Check if all the packages haven't been delivered
  106. if (APlayerData[playerid][CourierMaxStep] != APlayerData[playerid][JobStep])
  107. {
  108. // First disable the current checkpoint
  109. DisablePlayerCheckpoint(playerid);
  110. // Let the player know he delivered a package
  111. GameTextForPlayer(playerid, TXT_PackageDeliveredGameText, 5000, 4);
  112. SendClientMessage(playerid, 0xFFFFFFFF, TXT_PackageDeliveredMessage);
  113. // Set next JobStep (next house)
  114. APlayerData[playerid][JobStep]++;
  115. Step = APlayerData[playerid][JobStep];
  116. // Get the HouseID of the house where the mission starts (the first house in the list of in-range owned house)
  117. HouseID = APlayerData[playerid][CourierHouses][Step];
  118. // Set the TextDraw so the player can see it
  119. format(RouteText, 255, "~w~Deliver package ~b~%i/%i~w~ to: ~r~%s", Step, APlayerData[playerid][CourierMaxStep], AHouseData[HouseID][HouseName]);
  120. TextDrawSetString(APlayerData[playerid][MissionText], RouteText);
  121. // Grab the x, y, z positions for the first location
  122. x = AHouseData[HouseID][HouseX];
  123. y = AHouseData[HouseID][HouseY];
  124. z = AHouseData[HouseID][HouseZ];
  125. // Create a checkpoint where the player should deliver his package
  126. SetPlayerCheckpoint(playerid, x, y, z, 3);
  127. }
  128. else // All packages have been delivered, the player has to get paid now
  129. {
  130. // Get the player name
  131. GetPlayerName(playerid, Name, sizeof(Name));
  132. // Send a message to all players to inform them that this player completed a courier-job
  133. format(Msg, 128, TXT_PlayerCompletedCourierJob, Name, APlayerData[playerid][CourierMaxStep]);
  134. SendClientMessageToAll(0xFFFFFFFF, Msg);
  135. // Set a payment based on the number of packages
  136. Payment = APlayerData[playerid][CourierMaxStep] * PaymentPerPackage;
  137. // Pay the player money and give scorepoints, both based on the number of packages delivered
  138. RewardPlayer(playerid, Payment, APlayerData[playerid][CourierMaxStep]);
  139. // Send a message to let the player know he finished his mission and got paid
  140. format(Msg, 128, TXT_RewardJob, Payment);
  141. SendClientMessage(playerid, 0xFFFFFFFF, Msg);
  142. // Increase the stats for completing a courier job
  143. APlayerData[playerid][StatsCourierJobs]++;
  144. // End the current trucker job (clear mission-data)
  145. Courier_EndJob(playerid);
  146. // Also save the data (in case the server crashes, progress would be lost)
  147. PlayerFile_Save(playerid);
  148. }
  149. }
  150. else
  151. SendClientMessage(playerid, 0xFFFFFFFF, TXT_NeedOnFootToProceed);
  152. return 1;
  153. }
  154. // This function is used to stop any Courier-mission that has been started
  155. Courier_EndJob(playerid)
  156. {
  157. if (APlayerData[playerid][JobStarted] == true)
  158. {
  159. // Clear all data about the job from the player, so he can start a new one
  160. APlayerData[playerid][JobStarted] = false;
  161. APlayerData[playerid][JobStep] = 0;
  162. APlayerData[playerid][VehicleTimerTime] = 0;
  163. APlayerData[playerid][VehicleID] = 0;
  164. APlayerData[playerid][CourierMaxStep] = 0;
  165. // Clear the list of houses-in-range
  166. for (new i; i < 11; i++)
  167. APlayerData[playerid][CourierHouses][i] = 0;
  168. // Delete the checkpoint
  169. DisablePlayerCheckpoint(playerid);
  170. // Reset the missiontext
  171. TextDrawSetString(APlayerData[playerid][MissionText], Courier_NoJobText);
  172. }
  173. return 1;
  174. }