1
0

PPC_MissionsBus.inc 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. // Setup a custom type that holds all data about a bus route
  2. enum TBusRoute
  3. {
  4. HomeDepot, // The ID of the home-depot
  5. LineNumber, // The number of the busroute
  6. Score, // Determines the score the player gets when he reaches the end of the busroute
  7. RouteDescription[100], // The description of the busroute
  8. Locations[30] // The Location-IDs where the player must load/unload passengers (up to 30 busstops per route)
  9. }
  10. // Setup an array that holds all busroute data
  11. new ABusRoutes[][TBusRoute] =
  12. {
  13. // HomeDepot, LineNumber, array of BusLocations (location "-1" states the end of the route -> start over from the first location)
  14. {64, 101, 2, "SomeStart1 - SomeStop1", {65, 67, 94, 99, 69, 75, 76, 65, -1}},
  15. {64, 102, 1, "SomeStart2 - SomeStop2", {94, 96, 99, 100, 71, 94, -1}},
  16. {64, 201, 3, "SomeStart3 - SomeStop3", {92, 93, 91, 89, 88, 86, 84, 85, 79, 73, 72, 92, -1}},
  17. {64, 301, 2, "Las Barrancas - Bayside", {108, 107, 105, 103, 104, 108, -1}},
  18. {64, 302, 2, "Bayside - Las Payasdas", {103, 104, 106, 109, 105, 103, -1}},
  19. {64, 303, 2, "Fort Carson - El Quebrados", {112, 108, 105, 106, 108, 111, 112, -1}},
  20. {64, 401, 2, "Palomino Creek - Dillimore", {116, 117, 120, 118, 115, 116, -1}}
  21. };
  22. // Forward the function to Load or Unload passengers during missions (used by a timer)
  23. forward BusDriver_LoadUnload(playerid, PassengersOnBusStop);
  24. // This function is called when a busdriver enters a checkpoint
  25. Bus_EnterRaceCheckpoint(playerid)
  26. {
  27. // Check if the player is inside his vehicle while entering a checkpoint
  28. if (GetPlayerVehicleID(playerid) == APlayerData[playerid][VehicleID])
  29. {
  30. // Setup local variables
  31. new LineNr, Description[100], PassengersOnBus, PassengersOnBusStop, Job, RouteText[255];
  32. // Show that the player is loading and unloading passengers
  33. // GameTextForPlayer(playerid, "Loading/unloading passengers... Please wait", 5000, 4);
  34. // Disable the player's actions (he cannot move anymore)
  35. TogglePlayerControllable(playerid, 0);
  36. // Get the JobID
  37. Job = APlayerData[playerid][JobID];
  38. // Get the data to construct the textdraw
  39. LineNr = ABusRoutes[Job][LineNumber];
  40. format(Description, 100, "%s", ABusRoutes[Job][RouteDescription]);
  41. PassengersOnBus = APlayerData[playerid][Passengers];
  42. // Determine a random number of passengers on the busstop (between 10 and 30 passengers can be waiting at the busstop)
  43. PassengersOnBusStop = random(20) + 10;
  44. // Limit the number of passengers to 100
  45. // if ((APlayerData[playerid][Passengers] + PassengersOnBusStop) > 100)
  46. // PassengersOnBusStop = 100 - APlayerData[playerid][Passengers];
  47. // Combine it all into a string for the TextDraw (the player can see this all the time) to describe the mission
  48. format(RouteText, 255, TXT_BusDriverBusStopInfo, LineNr, Description, PassengersOnBus, PassengersOnBusStop);
  49. // Set the TextDraw so the player can see it
  50. TextDrawSetString(APlayerData[playerid][MissionText], RouteText);
  51. // Start a timer (Public function "BusDriver_LoadUnload(playerid)" gets called when the timer runs out)
  52. APlayerData[playerid][LoadingTimer] = SetTimerEx("BusDriver_LoadUnload", 5000, false, "di" , playerid, PassengersOnBusStop);
  53. }
  54. return 1;
  55. }
  56. // After a truckdriver entered a checkpoint, a timer is created. This function is called when the timer runs out
  57. public BusDriver_LoadUnload(playerid, PassengersOnBusStop)
  58. {
  59. // Setup local variables
  60. new RouteText[255], Float:x, Float:y, Float:z, Job, NextLoc, NextStep, Depot, Msg[128];
  61. new PassengersOnBus, PassengersGettingOff, LineNr, Description[100], Payment;
  62. new Float:xn, Float: yn, Float:zn;
  63. // Also delete any race-checkpoint (at the location of the homedepot)
  64. DisablePlayerCheckpoint(playerid);
  65. // Delete the checkpoint where the player just loaded/unloaded passengers
  66. DisablePlayerRaceCheckpoint(playerid);
  67. // Get the JobID
  68. Job = APlayerData[playerid][JobID];
  69. // Select the next location (jobstep)
  70. APlayerData[playerid][JobStep]++;
  71. NextStep = APlayerData[playerid][JobStep];
  72. // Determine a random number of passengers leaving the bus and let them leave (if there are any)
  73. if (APlayerData[playerid][Passengers] > 0)
  74. PassengersGettingOff = random(APlayerData[playerid][Passengers]);
  75. APlayerData[playerid][Passengers] = APlayerData[playerid][Passengers] - PassengersGettingOff;
  76. // Also let the passengers, that are waiting at the busstop, get on the bus
  77. APlayerData[playerid][Passengers] = APlayerData[playerid][Passengers] + PassengersOnBusStop;
  78. // Grab the next locationID
  79. NextLoc = ABusRoutes[Job][Locations][NextStep];
  80. // If the end of the route is reached, restart it from location 0 (also add a racecheckpoint at the busdepot to end the mission)
  81. if (NextLoc == -1)
  82. {
  83. // Setup local variables
  84. new MissionMsg[128], Name[24];
  85. // Get the player name
  86. GetPlayerName(playerid, Name, sizeof(Name));
  87. // Construct the message sent to all players that this player completed a mafia mission
  88. format(MissionMsg, 128, TXT_PlayerCompletedBusLine, Name, ABusRoutes[Job][LineNumber]);
  89. SendClientMessageToAll(0xFFFFFFFF, MissionMsg);
  90. // Start the route again from the first location
  91. NextStep = 1;
  92. APlayerData[playerid][JobStep] = NextStep;
  93. // Grab the locationID of this busstop
  94. NextLoc = ABusRoutes[Job][Locations][NextStep];
  95. // Get the homedepot locationID
  96. Depot = ABusRoutes[Job][HomeDepot];
  97. // Grab the coordinates of the homedepot
  98. x = ALocations[Depot][LocX];
  99. y = ALocations[Depot][LocY];
  100. z = ALocations[Depot][LocZ];
  101. // Create a checkpoint at the coordinates of the homedepot
  102. SetPlayerCheckpoint(playerid, x, y, z, 7);
  103. // Reward the player with a score for completing a busroute
  104. RewardPlayer(playerid, 0, ABusRoutes[Job][Score]);
  105. // Increase the stats for completing a bus-route
  106. APlayerData[playerid][StatsBusDriverJobs]++;
  107. // Also save the data (in case the server crashes, progress would be lost)
  108. PlayerFile_Save(playerid);
  109. }
  110. // Get the data to construct the textdraw
  111. LineNr = ABusRoutes[Job][LineNumber];
  112. format(Description, 100, "%s", ABusRoutes[Job][RouteDescription]);
  113. PassengersOnBus = APlayerData[playerid][Passengers];
  114. // Combine it all into a string for the TextDraw (the player can see this all the time) to describe the mission
  115. format(RouteText, 255, TXT_BusDriverJobInfo, LineNr, Description, PassengersOnBus);
  116. // Set the TextDraw so the player can see it
  117. TextDrawSetString(APlayerData[playerid][MissionText], RouteText);
  118. // Grab the coordinates of the next location
  119. x = ALocations[NextLoc][LocX];
  120. y = ALocations[NextLoc][LocY];
  121. z = ALocations[NextLoc][LocZ];
  122. // Create a new checkpoint where the player should load/unload the passengers
  123. SetPlayerRaceCheckpoint(playerid, 2, x, y, z, xn, yn, zn, 7);
  124. // Enable the player again (he can move again)
  125. TogglePlayerControllable(playerid, 1);
  126. // Reward the player (every passengers that left the bus pays $9) and let him know about it
  127. if (PassengersGettingOff != 0)
  128. {
  129. // Reward the player (give cash and points)
  130. Payment = PassengersGettingOff * 9;
  131. RewardPlayer(playerid, Payment, 0);
  132. format(Msg, 128, TXT_BusDriverReward, Payment);
  133. GameTextForPlayer(playerid, Msg, 3000, 4);
  134. }
  135. return 1;
  136. }
  137. // This function starts the busdriver job
  138. BusDriver_StartJob(playerid, Job)
  139. {
  140. new Vehicle = GetPlayerVehicleID(playerid), StartLoc;
  141. new Float:xn, Float: yn, Float:zn;
  142. // Setup local variables
  143. new RouteText[255], Float:x, Float:y, Float:z, LineNr, Description[100], PassengersOnBus;
  144. // Job has started
  145. APlayerData[playerid][JobStarted] = true;
  146. // Store VehicleID
  147. APlayerData[playerid][VehicleID] = Vehicle;
  148. // Store the busroute busroute
  149. APlayerData[playerid][JobID] = Job;
  150. // Set jobstep to 0 (going to the first busstop)
  151. APlayerData[playerid][JobStep] = 0;
  152. // Get the data to construct the textdraw
  153. LineNr = ABusRoutes[Job][LineNumber];
  154. format(Description, 100, "%s", ABusRoutes[Job][RouteDescription]);
  155. PassengersOnBus = 0;
  156. APlayerData[playerid][Passengers] = PassengersOnBus;
  157. // Combine it all into a string for the TextDraw (the player can see this all the time) to describe the mission
  158. format(RouteText, 255, TXT_BusDriverJobInfo, LineNr, Description, PassengersOnBus);
  159. // Set the TextDraw so the player can see it
  160. TextDrawSetString(APlayerData[playerid][MissionText], RouteText);
  161. // Grab the x, y, z positions for the first location
  162. StartLoc = ABusRoutes[Job][Locations][0];
  163. x = ALocations[StartLoc][LocX];
  164. y = ALocations[StartLoc][LocY];
  165. z = ALocations[StartLoc][LocZ];
  166. // Create a race-checkpoint where the player should load/unload passengers
  167. SetPlayerRaceCheckpoint(playerid, 2, x, y, z, xn, yn, zn, 7);
  168. // Set the job-fail-time for the global vehicle-timer
  169. APlayerData[playerid][VehicleTimerTime] = Job_TimeToFailMission;
  170. return 1;
  171. }
  172. // This function is used to cleanup the current job
  173. BusDriver_EndJob(playerid)
  174. {
  175. if (APlayerData[playerid][JobStarted] == true)
  176. {
  177. // Clear all data about the job from the player, so he can start a new one
  178. APlayerData[playerid][JobStarted] = false;
  179. APlayerData[playerid][JobStep] = 0;
  180. APlayerData[playerid][JobID] = 0;
  181. APlayerData[playerid][Passengers] = 0;
  182. APlayerData[playerid][VehicleTimerTime] = 0;
  183. APlayerData[playerid][VehicleID] = 0;
  184. // Delete the checkpoint
  185. DisablePlayerCheckpoint(playerid);
  186. // Also delete any race-checkpoint (at the location of the homedepot)
  187. DisablePlayerRaceCheckpoint(playerid);
  188. // Reset the missiontext
  189. TextDrawSetString(APlayerData[playerid][MissionText], BusDriver_NoJobText);
  190. }
  191. return 1;
  192. }