PPC_MissionsPolice.inc 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. // Forward the function to timer to check players every second to see if they're wanted
  2. forward Police_CheckWantedPlayers(playerid);
  3. forward UnjailPlayer(playerid);
  4. // This timer is created every time a player changes his class to police
  5. public Police_CheckWantedPlayers(playerid)
  6. {
  7. // Scan through all players
  8. for (new PlayerToCheck; PlayerToCheck < MAX_PLAYERS; PlayerToCheck++)
  9. {
  10. // check if this player is connected
  11. if (IsPlayerConnected(PlayerToCheck))
  12. {
  13. //Check if that player is wanted
  14. if (GetPlayerWantedLevel(PlayerToCheck) > 0)
  15. SetPlayerMarkerForPlayer(playerid, PlayerToCheck, 0xFF0000FF); // Make that player red to the police-player
  16. else
  17. {
  18. // Reset the playercolor based on the player's class
  19. switch (APlayerData[PlayerToCheck][PlayerClass])
  20. {
  21. case ClassTruckDriver: SetPlayerMarkerForPlayer(playerid, PlayerToCheck, ColorClassTruckDriver);
  22. case ClassBusDriver: SetPlayerMarkerForPlayer(playerid, PlayerToCheck, ColorClassBusDriver);
  23. case ClassPilot: SetPlayerMarkerForPlayer(playerid, PlayerToCheck, ColorClassPilot);
  24. case ClassPolice: SetPlayerMarkerForPlayer(playerid, PlayerToCheck, ColorClassPolice);
  25. case ClassMafia: SetPlayerMarkerForPlayer(playerid, PlayerToCheck, ColorClassMafia);
  26. case ClassCourier: SetPlayerMarkerForPlayer(playerid, PlayerToCheck, ColorClassCourier);
  27. case ClassAssistance: SetPlayerMarkerForPlayer(playerid, PlayerToCheck, ColorClassAssistance);
  28. }
  29. }
  30. }
  31. }
  32. }
  33. // This function gets called when a police player presses the SECUNDAIRY FIRE button (to warn nearby wanted players)
  34. Police_WarnNearbyPlayers(playerid)
  35. {
  36. // Setup local variables
  37. new Float:x, Float:y, Float:z, Name[24], Msg[128];
  38. // Scan through all players
  39. for (new PlayerToCheck; PlayerToCheck < MAX_PLAYERS; PlayerToCheck++)
  40. {
  41. // check if this player is connected
  42. if (IsPlayerConnected(PlayerToCheck))
  43. {
  44. // Check if the current player is wanted
  45. if (GetPlayerWantedLevel(PlayerToCheck) > 0)
  46. {
  47. // Get the position of this player
  48. GetPlayerPos(PlayerToCheck, x, y, z);
  49. // Check if the police-player is in range of the player
  50. if (IsPlayerInRangeOfPoint(playerid, 50.0, x, y, z))
  51. {
  52. GameTextForPlayer(PlayerToCheck, TXT_PoliceWarnPlayer, 3000, 4); // Warn the player
  53. // Also start a timer which gives the player a chance to stop and get a fine
  54. // If he doesn't stop, the player will be sent to jail when he gets fined
  55. if (APlayerData[PlayerToCheck][PoliceWarnedMe] == false)
  56. {
  57. APlayerData[PlayerToCheck][PoliceWarnedMe] = true;
  58. APlayerData[PlayerToCheck][Value_PoliceCanJailMe] = 60;
  59. APlayerData[PlayerToCheck][Timer_PoliceCanJailMe] = SetTimerEx("Timer_PoliceCanJailPlayer", 5000, true, "i", PlayerToCheck);
  60. }
  61. // Let the police player know that he warned the player
  62. GetPlayerName(PlayerToCheck, Name, sizeof(Name));
  63. format(Msg, 128, "{00FF00}You've warned {FFFF00}%s", Name);
  64. SendClientMessage(playerid, 0xFFFFFFFF, Msg);
  65. }
  66. }
  67. }
  68. }
  69. return 1;
  70. }
  71. // This function gets called when a police player presses the FIRE key (to fine nearby wanted players) when he's on foot
  72. Police_FineNearbyPlayers(playerid)
  73. {
  74. // Setup local variables
  75. new Float:x, Float:y, Float:z;
  76. // Scan through all players
  77. for (new PlayerToCheck; PlayerToCheck < MAX_PLAYERS; PlayerToCheck++)
  78. {
  79. // check if this player is connected
  80. if (IsPlayerConnected(PlayerToCheck))
  81. {
  82. // Check if the other player isn't the same police player
  83. if (PlayerToCheck != playerid)
  84. {
  85. // Check if the current player is wanted and the wanted player is driving slowly (below 30 kph)
  86. if ((GetPlayerWantedLevel(PlayerToCheck) > 0) && (APlayerData[PlayerToCheck][PlayerSpeed] < 30))
  87. {
  88. // Get the position of this player
  89. GetPlayerPos(PlayerToCheck, x, y, z);
  90. // Check if the police-player is in range of the player (police player and wanted player must be within 10 meters of eachother)
  91. if (IsPlayerInRangeOfPoint(playerid, 10.0, x, y, z))
  92. {
  93. // Fine the player
  94. Police_PayFine(playerid, PlayerToCheck);
  95. // Exit the function
  96. return 1;
  97. }
  98. // Check if the police-player is in range of the player (he can be inside his vehicle or on foot)
  99. if (IsPlayerInRangeOfPoint(playerid, 50.0, x, y, z))
  100. {
  101. GameTextForPlayer(PlayerToCheck, TXT_PoliceWarnPlayer, 3000, 4); // Warn the player
  102. // Also start a timer which gives the player a chance to stop and get a fine
  103. // If he doesn't stop, the player will be sent to jail when he gets fined
  104. if (APlayerData[PlayerToCheck][PoliceWarnedMe] == false)
  105. {
  106. APlayerData[PlayerToCheck][PoliceWarnedMe] = true;
  107. APlayerData[PlayerToCheck][Value_PoliceCanJailMe] = DefaultWarnTimeBeforeJail;
  108. APlayerData[PlayerToCheck][Timer_PoliceCanJailMe] = SetTimerEx("Timer_PoliceCanJailPlayer", 5000, true, "i", PlayerToCheck);
  109. }
  110. }
  111. }
  112. }
  113. }
  114. }
  115. return 1;
  116. }
  117. // Pay the police player and fine the player
  118. Police_PayFine(playerid, PlayerToFine)
  119. {
  120. // Setup local variables
  121. new PoliceName[24], FinedPlayerName[24], PoliceMsg[200], PlayerMsg[200], JailTime, Fine;
  122. // Get the names of the police player and the wanted player
  123. GetPlayerName(playerid, PoliceName, 24);
  124. GetPlayerName(PlayerToFine, FinedPlayerName, 24);
  125. // Check if the wanted player's timer hasn't ran out yet
  126. if (APlayerData[PlayerToFine][PoliceCanJailMe] == false)
  127. {
  128. // Calculate the fine
  129. Fine = GetPlayerWantedLevel(PlayerToFine) * DefaultFinePerStar;
  130. // Reward the police player (give cash and points)
  131. RewardPlayer(playerid, Fine, GetPlayerWantedLevel(PlayerToFine));
  132. // Let the police player know that he fined the player
  133. format(PoliceMsg, 200, TXT_PoliceFinedPlayerReward, FinedPlayerName, Fine);
  134. SendClientMessage(playerid, 0xFFFFFFFF, PoliceMsg);
  135. // Let the wanted player pay the fine
  136. RewardPlayer(PlayerToFine, -Fine, 0);
  137. format(PlayerMsg, 200, TXT_PlayerGotFinedByPolice, PoliceName, Fine);
  138. SendClientMessage(PlayerToFine, 0xFFFFFFFF, PlayerMsg);
  139. // Let the other players know that the police player has fined the wanted player
  140. format(PoliceMsg, 200, TXT_PoliceFinedPlayer, PoliceName, FinedPlayerName);
  141. SendClientMessageToAll(0xFFFFFFFF, PoliceMsg);
  142. // Increase the stats for fining a player
  143. APlayerData[playerid][StatsPoliceFined]++;
  144. }
  145. else // The wanted player didn't pull over, now the police player has the right to send him to jail and double the fine
  146. {
  147. // Set jailtime
  148. JailTime = DefaultJailTime;
  149. // Calculate the fine (double the normal fine)
  150. Fine = GetPlayerWantedLevel(PlayerToFine) * DefaultFinePerStar * 2;
  151. // Reward the police player (give cash and points)
  152. RewardPlayer(playerid, Fine, GetPlayerWantedLevel(PlayerToFine));
  153. // Let the police player know that he jailed the wanted player
  154. format(PoliceMsg, 200, TXT_PoliceJailedPlayerReward, FinedPlayerName, Fine);
  155. SendClientMessage(playerid, 0xFFFFFFFF, PoliceMsg);
  156. // Let the wanted player pay a double fine
  157. RewardPlayer(PlayerToFine, -Fine, 0);
  158. // Let the player know he's been jailed and for how long
  159. format(PlayerMsg, 200, TXT_PlayerGotJailedByPolice, PoliceName, (JailTime / 60));
  160. SendClientMessage(PlayerToFine, 0xFFFFFFFF, PlayerMsg);
  161. // Let the other players know that the police player has jailed the wanted player
  162. format(PoliceMsg, 200, TXT_PoliceJailedPlayer, PoliceName, FinedPlayerName, (JailTime / 60));
  163. SendClientMessageToAll(0xFFFFFFFF, PoliceMsg);
  164. // Teleport the player to jail
  165. Police_JailPlayer(PlayerToFine, JailTime);
  166. // Increase the stats for jailing a player
  167. APlayerData[playerid][StatsPoliceJailed]++;
  168. }
  169. // Clear the wanted player's wanted status (the speedometer will automatically clear all data and kill the timer)
  170. SetPlayerWantedLevel(PlayerToFine, 0);
  171. // Also save the data (in case the server crashes, progress would be lost)
  172. PlayerFile_Save(playerid);
  173. PlayerFile_Save(PlayerToFine);
  174. return 1;
  175. }
  176. // This function ports the player inside the jail and sets a timer to get him back out
  177. Police_JailPlayer(playerid, JailTime)
  178. {
  179. // First remove the player from his vehicle
  180. RemovePlayerFromVehicle(playerid);
  181. // Set the player in the virtual world of the jail (so other players cannot see the jailed players on their radar)
  182. SetPlayerVirtualWorld(playerid, WORLD_JAIL);
  183. // Set player interior to the police station in San Fierro
  184. SetPlayerInterior(playerid, 10);
  185. // Put the player inside the jail
  186. SetPlayerPos(playerid, 220.0, 110.0, 999.1);
  187. // Store the jailtime for this player
  188. APlayerData[playerid][PlayerJailed] = JailTime;
  189. // Start the jailtimer, which checks every second if the player is allowed to get out
  190. KillTimer(APlayerData[playerid][PlayerJailedTimer]);
  191. APlayerData[playerid][PlayerJailedTimer] = SetTimerEx("UnjailPlayer", 1000, true, "i", playerid);
  192. // If the player started a job, let it fail
  193. if (APlayerData[playerid][JobStarted] == true)
  194. {
  195. // Stop any job that may have started
  196. switch (APlayerData[playerid][PlayerClass])
  197. {
  198. case ClassTruckDriver: Trucker_EndJob(playerid);
  199. case ClassBusDriver: BusDriver_EndJob(playerid);
  200. case ClassPilot: Pilot_EndJob(playerid);
  201. case ClassPolice: Police_EndJob(playerid);
  202. case ClassMafia: Mafia_EndJob(playerid);
  203. case ClassCourier: Courier_EndJob(playerid);
  204. case ClassAssistance: Assistance_EndJob(playerid);
  205. }
  206. // Inform the player that he failed the mission
  207. GameTextForPlayer(playerid, TXT_FailedMission, 5000, 4);
  208. // Reduce the player's cash by 1000
  209. RewardPlayer(playerid, -1000, 0);
  210. }
  211. return 1;
  212. }
  213. // This is the timer that runs for every player who's in jail
  214. public UnjailPlayer(playerid)
  215. {
  216. new JailMsg[20];
  217. // Check if the player is allowed to leave yet
  218. if (APlayerData[playerid][PlayerJailed] == 0)
  219. {
  220. // Set the player in the normal world
  221. SetPlayerVirtualWorld(playerid, 0);
  222. // Set player interior to the outside
  223. SetPlayerInterior(playerid, 0);
  224. // Put the player outside the jail (he should spawn at the location where he spawned after login or after choosing a rescue-point)
  225. SpawnPlayer(playerid);
  226. // Also, kill the jailtimer
  227. KillTimer(APlayerData[playerid][PlayerJailedTimer]);
  228. }
  229. else
  230. {
  231. // Show the remaining jailtime (only if the remaining time is below 60 seconds)
  232. if (APlayerData[playerid][PlayerJailed] < 60)
  233. {
  234. format(JailMsg, 20, TXT_JailTimer, APlayerData[playerid][PlayerJailed]);
  235. GameTextForPlayer(playerid, JailMsg, 750, 4);
  236. }
  237. // Decrease the jailtime by 1 second
  238. APlayerData[playerid][PlayerJailed] = APlayerData[playerid][PlayerJailed] - 1;
  239. }
  240. }
  241. // This function gets called when the police player dies (or changes class)
  242. Police_EndJob(playerid)
  243. {
  244. // Kill the PlayerCheckTimer
  245. KillTimer(APlayerData[playerid][PlayerCheckTimer]);
  246. // Scan through all players (to reset them to their default colors for the police-player)
  247. for (new PlayerToCheck; PlayerToCheck < MAX_PLAYERS; PlayerToCheck++)
  248. {
  249. // check if this player is connected
  250. if (IsPlayerConnected(PlayerToCheck))
  251. {
  252. // Reset the playercolor based on the player's class
  253. switch (APlayerData[PlayerToCheck][PlayerClass])
  254. {
  255. case ClassTruckDriver: SetPlayerMarkerForPlayer(playerid, PlayerToCheck, ColorClassTruckDriver);
  256. case ClassBusDriver: SetPlayerMarkerForPlayer(playerid, PlayerToCheck, ColorClassBusDriver);
  257. case ClassPilot: SetPlayerMarkerForPlayer(playerid, PlayerToCheck, ColorClassPilot);
  258. case ClassPolice: SetPlayerMarkerForPlayer(playerid, PlayerToCheck, ColorClassPolice);
  259. case ClassMafia: SetPlayerMarkerForPlayer(playerid, PlayerToCheck, ColorClassMafia);
  260. case ClassCourier: SetPlayerMarkerForPlayer(playerid, PlayerToCheck, ColorClassCourier);
  261. case ClassAssistance: SetPlayerMarkerForPlayer(playerid, PlayerToCheck, ColorClassAssistance);
  262. }
  263. }
  264. }
  265. return 1;
  266. }
  267. // This timer is started when a wanted player was warned by a police player
  268. forward Timer_PoliceCanJailPlayer(playerid);
  269. public Timer_PoliceCanJailPlayer(playerid)
  270. {
  271. // Setup local variables
  272. new Msg[128];
  273. // Let the player know how much time he has left to pull over
  274. format(Msg, 128, "{FF0000}You have %i seconds to pull over and stop", APlayerData[playerid][Value_PoliceCanJailMe]);
  275. SendClientMessage(playerid, 0xFFFFFFFF, Msg);
  276. // Check if the timer has ran out
  277. if (APlayerData[playerid][Value_PoliceCanJailMe] == 0)
  278. {
  279. // Set a switch that indicates that this player didn't stop when he got the warning from the police player
  280. // When the police can catch him now, he'll be sent to jail and the fine is doubled
  281. APlayerData[playerid][PoliceCanJailMe] = true;
  282. // Also kill the timer, as it's not needed anymore
  283. KillTimer(APlayerData[playerid][Timer_PoliceCanJailMe]);
  284. // Let the player know what consequences it will have by not stopping
  285. format(Msg, 128, "{FF0000}You didn't pull-over and stop, now the police can send you to jail immediately");
  286. SendClientMessage(playerid, 0xFFFFFFFF, Msg);
  287. format(Msg, 128, "{FF0000}Your fines will be doubled as well");
  288. SendClientMessage(playerid, 0xFFFFFFFF, Msg);
  289. }
  290. // Reduce the remaining time by 5 seconds
  291. APlayerData[playerid][Value_PoliceCanJailMe] = APlayerData[playerid][Value_PoliceCanJailMe] - 5;
  292. return 1;
  293. }
  294. // This function creates a spikestrip when the player is standing
  295. SpikeStrip_Create(playerid)
  296. {
  297. // Setup local variables
  298. new StripIndex = -1, Float:x, Float:y, Float:z, Float:rot;
  299. // Check if a spikestrip can be created
  300. for (new i; i < MAX_SPIKESTRIPS; i++)
  301. {
  302. if (ASpikeStrips[i][SpikeTime] == 0)
  303. {
  304. StripIndex = i;
  305. break;
  306. }
  307. }
  308. // Check if a free index has been found
  309. if (StripIndex != -1)
  310. {
  311. // Get the position of the player
  312. GetPlayerPos(playerid, x, y, z);
  313. GetPlayerFacingAngle(playerid, rot);
  314. // Create a new spike-strip object at the location of the player and store the coordinates of the spikestrip
  315. ASpikeStrips[StripIndex][SpikeObject] = CreateObject(2892, x, y, z - 1.0, 0.0, 0.0, rot + 90.0);
  316. ASpikeStrips[StripIndex][SpikeX] = x;
  317. ASpikeStrips[StripIndex][SpikeY] = y;
  318. ASpikeStrips[StripIndex][SpikeZ] = z;
  319. // Set the time for this timer to 1 minute
  320. ASpikeStrips[StripIndex][SpikeTime] = 600;
  321. // Create a timer that checks all players in range to see if they run over the spikestrip
  322. ASpikeStrips[StripIndex][SpikeTimer] = SetTimerEx("CheckSpikeStrip", 100, true, "i", StripIndex);
  323. // Let the player know he created a spikestrip
  324. SendClientMessage(playerid, 0xFFFFFFFF, "{00FF00}You've placed a spikestrip");
  325. }
  326. else
  327. SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}The maximum number of spikestrips have been created, try again later");
  328. }
  329. // This timer checks the spikestrips that have been planted (they automatically disappear after one minute)
  330. forward CheckSpikeStrip(StripIndex);
  331. public CheckSpikeStrip(StripIndex)
  332. {
  333. // Setup local variables
  334. new vid, panels, doors, lights, tires;
  335. // Decrease the time left for the spikestrip
  336. ASpikeStrips[StripIndex][SpikeTime]--;
  337. // Check if the spikestrip is still allowed to exist
  338. if (ASpikeStrips[StripIndex][SpikeTime] > 0)
  339. {
  340. // Loop through all players
  341. for (new playerid; playerid < MAX_PLAYERS; playerid++)
  342. {
  343. // Check if the player is connected
  344. if (APlayerData[playerid][LoggedIn] == true)
  345. {
  346. // Check if the player is the driver of a vehicle
  347. if (GetPlayerVehicleSeat(playerid) == 0)
  348. {
  349. // Get the vehicleid
  350. vid = GetPlayerVehicleID(playerid);
  351. // Check if the player is near the spikestrip object
  352. if (IsPlayerInRangeOfPoint(playerid, 7.0, ASpikeStrips[StripIndex][SpikeX], ASpikeStrips[StripIndex][SpikeY], ASpikeStrips[StripIndex][SpikeZ]))
  353. {
  354. // Pop all the tires of the player's vehicle
  355. GetVehicleDamageStatus(vid, panels, doors, lights, tires);
  356. UpdateVehicleDamageStatus(vid, panels, doors, lights, 15);
  357. }
  358. }
  359. }
  360. }
  361. }
  362. else
  363. {
  364. // Kill the timer and destroy the spikestrip object
  365. DestroyObject(ASpikeStrips[StripIndex][SpikeObject]);
  366. KillTimer(ASpikeStrips[StripIndex][SpikeTimer]);
  367. }
  368. return 1;
  369. }
  370. // This function sends the given message to all police players
  371. Police_SendMessage(PoliceMessage[])
  372. {
  373. for (new PoliceID; PoliceID < MAX_PLAYERS; PoliceID++) // Loop through all players
  374. if (APlayerData[PoliceID][LoggedIn] == true) // Check if this player has logged in
  375. if (APlayerData[PoliceID][PlayerClass] == ClassPolice) // Check if this player is a police player
  376. SendClientMessage(PoliceID, 0xFFFFFFFF, PoliceMessage); // Send the message to the police player
  377. }