PPC_GlobalTimer.inc 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. // This global timer runs every second and checks if a player is about to fail his mission (by getting out of his vehicle during a job)
  2. forward GlobalTimer();
  3. public GlobalTimer()
  4. {
  5. // Setup local variables
  6. new OldVehicleID, NewVehicleID, OldTrailerID, NewTrailerID;
  7. // Loop through all players
  8. for (new playerid; playerid < MAX_PLAYERS; playerid++)
  9. {
  10. // Check if this player is logged in
  11. if (APlayerData[playerid][LoggedIn] == true)
  12. {
  13. // Get the vehicle-id's from this player
  14. OldVehicleID = APlayerData[playerid][VehicleID];
  15. NewVehicleID = GetPlayerVehicleID(playerid);
  16. OldTrailerID = APlayerData[playerid][TrailerID];
  17. NewTrailerID = GetVehicleTrailer(GetPlayerVehicleID(playerid));
  18. // Check the class of the player
  19. switch (APlayerData[playerid][PlayerClass])
  20. {
  21. case ClassTruckDriver:
  22. {
  23. // Check if the trucker has a job
  24. if (APlayerData[playerid][JobStarted] == true)
  25. {
  26. // Check if the vehicletimer didn't run out yet
  27. if (APlayerData[playerid][VehicleTimerTime] != 0)
  28. {
  29. // If VehicleID and TrailerID are still the same as when the player accepted the job
  30. if ((OldVehicleID == NewVehicleID) && (OldTrailerID == NewTrailerID))
  31. APlayerData[playerid][VehicleTimerTime] = Job_TimeToFailMission; // Reset the time before the mission fails
  32. else // One (or both) aren't still the same (player lost his trailer or vehicle)
  33. PlayerLeftVehicle(playerid); // Inform the player that he left his vehicle and that he must re-enter it
  34. }
  35. else // Time left has reached 0
  36. FailJob(playerid);
  37. }
  38. }
  39. case ClassBusDriver:
  40. {
  41. // Check if the busdriver has a job
  42. if (APlayerData[playerid][JobStarted] == true)
  43. {
  44. if (APlayerData[playerid][VehicleTimerTime] != 0)
  45. {
  46. // If VehicleID is still the same as when the player accepted the job
  47. if (OldVehicleID == NewVehicleID)
  48. APlayerData[playerid][VehicleTimerTime] = Job_TimeToFailMission; // Reset the time before the mission fails
  49. else // Player got out of his bus
  50. PlayerLeftVehicle(playerid); // Inform the player that he left his vehicle and that he must re-enter it
  51. }
  52. else // Time left has reached 0
  53. FailJob(playerid);
  54. }
  55. }
  56. case ClassMafia:
  57. {
  58. // Check if the mafia has a job
  59. if (APlayerData[playerid][JobStarted] == true)
  60. {
  61. if (APlayerData[playerid][VehicleTimerTime] != 0)
  62. {
  63. // If VehicleID is still the same as when the player accepted the job
  64. if (OldVehicleID == NewVehicleID)
  65. APlayerData[playerid][VehicleTimerTime] = Job_TimeToFailMission; // Reset the time before the mission fails
  66. else // Player left his vehicle
  67. PlayerLeftVehicle(playerid); // Inform the player that he left his vehicle and that he must re-enter it
  68. }
  69. else // Time left has reached 0
  70. FailJob(playerid);
  71. }
  72. }
  73. case ClassCourier:
  74. {
  75. // Check if the courier has a job
  76. if (APlayerData[playerid][JobStarted] == true)
  77. {
  78. if (APlayerData[playerid][VehicleTimerTime] != 0)
  79. {
  80. // If VehicleID and TrailerID are still the same as when the player accepted the job
  81. if (OldVehicleID == NewVehicleID)
  82. APlayerData[playerid][VehicleTimerTime] = Job_TimeToFailMission; // Reset the time before the mission fails
  83. else // Player stepped out of his vehicle
  84. PlayerLeftVehicle(playerid); // Inform the player that he left his vehicle and that he must re-enter it
  85. }
  86. else // Time left has reached 0
  87. FailJob(playerid);
  88. }
  89. }
  90. case ClassRoadWorker:
  91. {
  92. // Check if the roadworker has a job
  93. if (APlayerData[playerid][JobStarted] == true)
  94. {
  95. // Check if the vehicletimer didn't run out yet
  96. if (APlayerData[playerid][VehicleTimerTime] != 0)
  97. {
  98. // If VehicleID and TrailerID are still the same as when the player accepted the job
  99. // In case of the "tow broken vehicle" jobtype, the mission starts without a trailer (so it's 0),
  100. // but gets updated when the player enters the checkpoint to set the broken vehicle as trailer
  101. if ((OldVehicleID == NewVehicleID) && (OldTrailerID == NewTrailerID))
  102. APlayerData[playerid][VehicleTimerTime] = Job_TimeToFailMission; // Reset the time before the mission fails
  103. else // VehicleID isn't still the same (player lost his vehicle or trailer)
  104. PlayerLeftVehicle(playerid); // Inform the player that he left his vehicle and that he must re-enter it
  105. }
  106. else // Time left has reached 0
  107. FailJob(playerid);
  108. }
  109. }
  110. }
  111. }
  112. }
  113. return 1;
  114. }
  115. // This function is called by the global vehicletimer to fail a job
  116. FailJob(playerid)
  117. {
  118. // Check the class of the player
  119. switch (APlayerData[playerid][PlayerClass])
  120. {
  121. case ClassTruckDriver:
  122. {
  123. // End the player's job
  124. Trucker_EndJob(playerid);
  125. // If the player is part of a convoy, kick him from it (as he failed his mission, the rest of the convoy would be stuck)
  126. Convoy_Leave(playerid);
  127. }
  128. case ClassBusDriver:
  129. {
  130. // End the player's job
  131. BusDriver_EndJob(playerid);
  132. }
  133. case ClassMafia:
  134. {
  135. // End the player's job
  136. Mafia_EndJob(playerid);
  137. }
  138. case ClassCourier:
  139. {
  140. // End the player's job
  141. Courier_EndJob(playerid);
  142. }
  143. case ClassRoadWorker:
  144. {
  145. // End the player's job
  146. Roadworker_EndJob(playerid);
  147. }
  148. }
  149. // Inform the player that he failed the mission
  150. GameTextForPlayer(playerid, TXT_FailedMission, 5000, 4);
  151. // Reduce the player's cash by 1000
  152. RewardPlayer(playerid, -1000, 0);
  153. }
  154. // This function is used by the global vehicletimer and informs the player that he left his vehicle and must re-enter it
  155. PlayerLeftVehicle(playerid)
  156. {
  157. // Setup local variables
  158. new TimeLeft[5];
  159. // Reduce the time left by 1
  160. APlayerData[playerid][VehicleTimerTime] = APlayerData[playerid][VehicleTimerTime] - 1;
  161. // Convert the time left to a string for displaying
  162. valstr(TimeLeft, APlayerData[playerid][VehicleTimerTime]);
  163. // Display the time left
  164. GameTextForPlayer(playerid, TimeLeft, 1000, 4);
  165. // Send only one message to inform the player what he must do
  166. if (APlayerData[playerid][VehicleTimerTime] == (Job_TimeToFailMission - 1))
  167. {
  168. // Check the class of the player and inform them what to do
  169. switch (APlayerData[playerid][PlayerClass])
  170. {
  171. case ClassTruckDriver:
  172. SendClientMessage(playerid, 0xFFFFFFFF, TXT_TruckerMustEnterVehicle);
  173. case ClassBusDriver:
  174. SendClientMessage(playerid, 0xFFFFFFFF, TXT_BusDriverMustEnterBus);
  175. case ClassMafia:
  176. SendClientMessage(playerid, 0xFFFFFFFF, TXT_MafiaMustEnterVehicle);
  177. case ClassCourier:
  178. SendClientMessage(playerid, 0xFFFFFFFF, TXT_CourierMustEnterVehicle);
  179. case ClassRoadWorker:
  180. SendClientMessage(playerid, 0xFFFFFFFF, TXT_RoadworkerMustEnterVehicle);
  181. }
  182. }
  183. }