1
0

PPC_Speedometer.inc 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. // Forward the function needed to update the speedometer (used by a timer)
  2. forward Speedometer_Update(playerid);
  3. forward RefuelVehicle(playerid);
  4. // This function sets up the speedometer for the given player
  5. Speedometer_Setup(playerid)
  6. {
  7. // Setup the speedometer for the player
  8. APlayerData[playerid][SpeedometerText] = TextDrawCreate(500.0, 395.0, " ");
  9. APlayerData[playerid][FuelGauge] = TextDrawCreate(500.0, 410.0, " ");
  10. // Enable the TextDraw for this player
  11. TextDrawShowForPlayer(playerid, APlayerData[playerid][SpeedometerText]);
  12. TextDrawShowForPlayer(playerid, APlayerData[playerid][FuelGauge]);
  13. // Start the speedometer timer
  14. APlayerData[playerid][SpeedometerTimer] = SetTimerEx("Speedometer_Update", 500, true, "i", playerid);
  15. return 1;
  16. }
  17. // This function cleans up the speedometer for the given player
  18. Speedometer_Cleanup(playerid)
  19. {
  20. // Destroy the speedometer textdraw
  21. TextDrawDestroy(APlayerData[playerid][SpeedometerText]);
  22. TextDrawDestroy(APlayerData[playerid][FuelGauge]);
  23. // Kill the speedometer timer
  24. KillTimer(APlayerData[playerid][SpeedometerTimer]);
  25. // Set player speed to 0
  26. APlayerData[playerid][PlayerSpeed] = 0;
  27. return 1;
  28. }
  29. // This function gets called by a timer which runs every 500ms to display and update the speedometer
  30. public Speedometer_Update(playerid)
  31. {
  32. // Setup local variables
  33. new vehicleid, Float:speed_x, Float:speed_y, Float:speed_z, Float:final_speed, speed_string[50], final_speed_int, Float:vehiclehealth;
  34. new FuelString[50], FuelStatus[20];
  35. new Msg[128], Name[24];
  36. // Get the ID of the player's vehicle
  37. vehicleid = GetPlayerVehicleID(playerid);
  38. //******************************************************************************************************************************
  39. // Anti-hack stuff
  40. //******************************************************************************************************************************
  41. AntiHack(playerid);
  42. //******************************************************************************************************************************
  43. // End of anti-hack stuff
  44. //******************************************************************************************************************************
  45. // Check and toggle spectate-mode when needed (when target player entered or exited his vehicle)
  46. if (GetPlayerState(playerid) == PLAYER_STATE_SPECTATING)
  47. {
  48. // Get the target player's ID and name
  49. new OtherPlayer = APlayerData[playerid][SpectateID];
  50. GetPlayerName(OtherPlayer, Name, sizeof(Name));
  51. // Use the same worldid and interiorid as the OtherPlayer
  52. SetPlayerVirtualWorld(playerid, GetPlayerVirtualWorld(OtherPlayer));
  53. SetPlayerInterior(playerid, GetPlayerInterior(OtherPlayer));
  54. // Check if the player is spectating a player
  55. if (APlayerData[playerid][SpectateType] == ADMIN_SPEC_TYPE_PLAYER)
  56. {
  57. // Check if the target player has entered a vehicle
  58. if (GetPlayerVehicleSeat(OtherPlayer) != -1)
  59. {
  60. // Change spectate mode to vehicle
  61. PlayerSpectateVehicle(playerid, GetPlayerVehicleID(OtherPlayer));
  62. APlayerData[playerid][SpectateID] = OtherPlayer;
  63. APlayerData[playerid][SpectateVehicle] = GetPlayerVehicleID(OtherPlayer);
  64. APlayerData[playerid][SpectateType] = ADMIN_SPEC_TYPE_VEHICLE;
  65. format(Msg, 128, "{00FF00}Player {FFFF00}%s{00FF00} has entered a vehicle, changing spectate mode to match", Name);
  66. SendClientMessage(playerid, 0xFFFFFFFF, Msg);
  67. }
  68. }
  69. else // The player is spectating a vehicle
  70. {
  71. // Check if the target player has exited a vehicle
  72. if (GetPlayerVehicleSeat(OtherPlayer) == -1)
  73. {
  74. // Change spectate mode to player
  75. PlayerSpectatePlayer(playerid, OtherPlayer);
  76. SetPlayerInterior(playerid, GetPlayerInterior(OtherPlayer));
  77. APlayerData[playerid][SpectateID] = OtherPlayer;
  78. APlayerData[playerid][SpectateType] = ADMIN_SPEC_TYPE_PLAYER;
  79. format(Msg, 128, "{00FF00}Player {FFFF00}%s{00FF00} has exited a vehicle, changing spectate mode to match", Name);
  80. SendClientMessage(playerid, 0xFFFFFFFF, Msg);
  81. }
  82. }
  83. }
  84. // When the player got a wanted level and a police player warned him to stop, a timer is started and a variable is set to "true"
  85. // Check if this variable has been set
  86. if (APlayerData[playerid][PoliceWarnedMe] == true)
  87. {
  88. // Check if the player has no wanted level anymore (after finishing a overloaded mission, player got fined, ...)
  89. if (GetPlayerWantedLevel(playerid) == 0)
  90. {
  91. APlayerData[playerid][PoliceCanJailMe] = false; // Clear the variable
  92. APlayerData[playerid][PoliceWarnedMe] = false; // Clear the variable
  93. APlayerData[playerid][Value_PoliceCanJailMe] = 0; // Clear the remaining time for the timer
  94. KillTimer(APlayerData[playerid][Timer_PoliceCanJailMe]); // Kill the timer
  95. }
  96. }
  97. // If the player is inside a vehicle
  98. if(vehicleid != 0)
  99. {
  100. // Get the vehicles velocity
  101. GetVehicleVelocity(vehicleid, speed_x, speed_y, speed_z);
  102. // Calculate the speed (in kph)
  103. final_speed = floatsqroot(((speed_x * speed_x) + (speed_y * speed_y)) + (speed_z * speed_z)) * 158.179;
  104. // Convert the float value to an int value
  105. final_speed_int = floatround(final_speed, floatround_round);
  106. // Also save the speed for the player
  107. APlayerData[playerid][PlayerSpeed] = final_speed_int;
  108. // Setup the string to display for the player and display it
  109. format(speed_string, 50, TXT_SpeedometerSpeed, final_speed_int);
  110. TextDrawSetString(APlayerData[playerid][SpeedometerText], speed_string);
  111. // Add the speed to the stats (this will be the meters driven in total)
  112. APlayerData[playerid][StatsMetersDriven] = APlayerData[playerid][StatsMetersDriven] + (final_speed / 7.2);
  113. // Also display the vehicle's health through the player-health bar
  114. GetVehicleHealth(vehicleid, vehiclehealth);
  115. SetPlayerHealth(playerid, vehiclehealth / 10.0);
  116. // Check if the speed is above 10kph and the fuel of the vehicle isn't empty yet
  117. if ((final_speed_int > 10) && (AVehicleData[vehicleid][Fuel] > 0))
  118. AVehicleData[vehicleid][Fuel] = AVehicleData[vehicleid][Fuel] - 1; // Decrease the fuel for this vehicle every time the timer is run
  119. // Construct the fuelgauge
  120. if ((AVehicleData[vehicleid][Fuel] > 0) && (AVehicleData[vehicleid][Fuel] < 100000))
  121. format(FuelStatus, 20, "~g~%s~r~%s", "I", "IIIIIIIII"); // Fuel is between 0% and 10% full
  122. if ((AVehicleData[vehicleid][Fuel] >= ((MaxFuel / 10) * 1)) && (AVehicleData[vehicleid][Fuel] < ((MaxFuel / 10) * 2)))
  123. format(FuelStatus, 20, "~g~%s~r~%s", "II", "IIIIIIII"); // Fuel is between 10% and 20% full
  124. if ((AVehicleData[vehicleid][Fuel] >= ((MaxFuel / 10) * 2)) && (AVehicleData[vehicleid][Fuel] < ((MaxFuel / 10) * 3)))
  125. format(FuelStatus, 20, "~g~%s~r~%s", "III", "IIIIIII"); // Fuel is between 20% and 30% full
  126. if ((AVehicleData[vehicleid][Fuel] >= ((MaxFuel / 10) * 3)) && (AVehicleData[vehicleid][Fuel] < ((MaxFuel / 10) * 4)))
  127. format(FuelStatus, 20, "~g~%s~r~%s", "IIII", "IIIIII"); // Fuel is between 30% and 40% full
  128. if ((AVehicleData[vehicleid][Fuel] >= ((MaxFuel / 10) * 4)) && (AVehicleData[vehicleid][Fuel] < ((MaxFuel / 10) * 5)))
  129. format(FuelStatus, 20, "~g~%s~r~%s", "IIIII", "IIIII"); // Fuel is between 40% and 50% full
  130. if ((AVehicleData[vehicleid][Fuel] >= ((MaxFuel / 10) * 5)) && (AVehicleData[vehicleid][Fuel] < ((MaxFuel / 10) * 6)))
  131. format(FuelStatus, 20, "~g~%s~r~%s", "IIIIII", "IIII"); // Fuel is between 50% and 60% full
  132. if ((AVehicleData[vehicleid][Fuel] >= ((MaxFuel / 10) * 6)) && (AVehicleData[vehicleid][Fuel] < ((MaxFuel / 10) * 7)))
  133. format(FuelStatus, 20, "~g~%s~r~%s", "IIIIIII", "III"); // Fuel is between 60% and 70% full
  134. if ((AVehicleData[vehicleid][Fuel] >= ((MaxFuel / 10) * 7)) && (AVehicleData[vehicleid][Fuel] < ((MaxFuel / 10) * 8)))
  135. format(FuelStatus, 20, "~g~%s~r~%s", "IIIIIIII", "II"); // Fuel is between 70% and 80% full
  136. if ((AVehicleData[vehicleid][Fuel] >= ((MaxFuel / 10) * 8)) && (AVehicleData[vehicleid][Fuel] < ((MaxFuel / 10) * 9)))
  137. format(FuelStatus, 20, "~g~%s~r~%s", "IIIIIIIII", "I"); // Fuel is between 80% and 90% full
  138. if ((AVehicleData[vehicleid][Fuel] >= ((MaxFuel / 10) * 9)) && (AVehicleData[vehicleid][Fuel] <= MaxFuel))
  139. format(FuelStatus, 20, "~g~%s", "IIIIIIIIII"); // Fuel is between 90% and 100% full (all bars are green)
  140. if (AVehicleData[vehicleid][Fuel] == 0)
  141. format(FuelStatus, 20, "~r~%s", "IIIIIIIIII"); // Fuel is empty (all bars are red)
  142. // Format the final fuel-gauge readout
  143. format(FuelString, 50, TXT_SpeedometerFuel, FuelStatus);
  144. // Display the fuel-gauge
  145. TextDrawSetString(APlayerData[playerid][FuelGauge], FuelString);
  146. // Check if the vehicle is out of fuel
  147. if (AVehicleData[vehicleid][Fuel] == 0)
  148. {
  149. // Stop the engine and turn off the lights
  150. new engine,lights,alarm,doors,bonnet,boot,objective;
  151. GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
  152. SetVehicleParamsEx(vehicleid, 0, 0, alarm, doors, bonnet, boot, objective);
  153. }
  154. // Check if the player is not in any plane or helicopter (those cannot be caught by speedcamera's)
  155. if (IsVehicleAirVehicle(vehicleid) == 0)
  156. if (APlayerData[playerid][PlayerClass] != ClassPolice) // Check if the player isn't speeding (cops won't get caught)
  157. CheckPlayerSpeeding(playerid);
  158. }
  159. else
  160. {
  161. // If the player is not inside a vehicle, display an empty string (looks like the speedometer is gone)
  162. TextDrawSetString(APlayerData[playerid][SpeedometerText], " ");
  163. TextDrawSetString(APlayerData[playerid][FuelGauge], " ");
  164. // Set the speed of the player to 0
  165. APlayerData[playerid][PlayerSpeed] = 0;
  166. }
  167. }
  168. // This timer-function is called when a player picks up a refuelpickup
  169. public RefuelVehicle(playerid)
  170. {
  171. new RefuelMsg[128];
  172. // Get the vehicle-id of the player's vehicle
  173. new vID = GetPlayerVehicleID(playerid);
  174. // Calculate the amount of fuel that needs to be refuelled
  175. new Amount = MaxFuel - AVehicleData[vID][Fuel];
  176. // Calculate the price to refuel
  177. new RefuelPrice = (Amount * RefuelMaxPrice) / MaxFuel;
  178. // Check if the player has enough cash
  179. if (APlayerData[playerid][PlayerMoney] >= RefuelPrice)
  180. {
  181. // Refuel the vehicle
  182. AVehicleData[vID][Fuel] = MaxFuel;
  183. // Withdraw the money from the player
  184. RewardPlayer(playerid, -RefuelPrice, 0);
  185. // Let the player know he refuelled his vehicle
  186. format(RefuelMsg, 128, TXT_RefuelledVehicle, RefuelPrice);
  187. SendClientMessage(playerid, 0xFFFFFFFF, RefuelMsg);
  188. }
  189. else
  190. SendClientMessage(playerid, 0xFFFFFFFF, TXT_CannotRefuelVehicle);
  191. // Allow the player to move again
  192. TogglePlayerControllable(playerid, 1);
  193. return 1;
  194. }
  195. // This function checks if the player is speeding near a speedcamera
  196. CheckPlayerSpeeding(playerid)
  197. {
  198. // Setup local variables
  199. new Name[24], Msg[128];
  200. // Check if the player hasn't been caught speeding recently
  201. if (APlayerData[playerid][PlayerCaughtSpeeding] == 0)
  202. {
  203. // Loop through all speedcameras
  204. for (new CamID; CamID < MAX_CAMERAS; CamID++)
  205. {
  206. // Check if this camera has been created
  207. if (ACameras[CamID][CamSpeed] != 0)
  208. {
  209. // Check if the player is the driver of the vehicle
  210. if (GetPlayerVehicleSeat(playerid) == 0)
  211. {
  212. // Check if the player's speed is greater than the speed allowed by this camera (no need to process a distance-check if not speeding)
  213. if (APlayerData[playerid][PlayerSpeed] > ACameras[CamID][CamSpeed])
  214. {
  215. // Check if the player is near the camera
  216. if (IsPlayerInRangeOfPoint(playerid, 50.0, ACameras[CamID][CamX], ACameras[CamID][CamY], ACameras[CamID][CamZ]))
  217. {
  218. // Prevent the player being caught multiple times by the same speed-camera
  219. APlayerData[playerid][PlayerCaughtSpeeding] = 20;
  220. // Increase the wanted-level of this player by 1 star
  221. SetPlayerWantedLevel(playerid, GetPlayerWantedLevel(playerid) + 1);
  222. // Let the player know he's been caught speeding
  223. SendClientMessage(playerid, 0xFFFFFFFF, TXT_PlayerCaughtSpeeding);
  224. // Get the name of the player
  225. GetPlayerName(playerid, Name, sizeof(Name));
  226. // Also inform all police players that this player is caught speeding
  227. format(Msg, 128, "{00FF00}Player {FFFF00}%s{00FF00} is caught speeding, pursue and fine him", Name);
  228. Police_SendMessage(Msg);
  229. }
  230. }
  231. }
  232. }
  233. }
  234. }
  235. else // If the player has been caught before, reduce the value until it's 0 again, then he can be caught again
  236. APlayerData[playerid][PlayerCaughtSpeeding]--;
  237. }
  238. // This function processes anti-hack stuff
  239. stock AntiHack(playerid)
  240. {
  241. // Setup local variables
  242. new Float:Armour;
  243. // Skip checking for hacks used by the player if he was reported by the Anti-Hack system already
  244. if (APlayerData[playerid][AutoReportTime] > 0)
  245. {
  246. // Reduce the time so the player can be reported again soon if he doesn't stop using hacks
  247. APlayerData[playerid][AutoReportTime]--;
  248. // Exit the function, this skips the hack-checks until the AutoReportTime has reached 0
  249. // Otherwise the player is reported every half a second until he stops using hacks
  250. return 1;
  251. }
  252. // Check if a filterscript gave some money (or took it) to the player
  253. if (GetPVarInt(playerid, "PVarMoney") != 0)
  254. {
  255. // Add the money to the players account
  256. APlayerData[playerid][PlayerMoney] = APlayerData[playerid][PlayerMoney] + GetPVarInt(playerid, "PVarMoney");
  257. // Clear the PVar
  258. SetPVarInt(playerid, "PVarMoney", 0);
  259. }
  260. if (GetPVarInt(playerid, "PVarScore") != 0)
  261. {
  262. // Add the money to the players account
  263. APlayerData[playerid][PlayerScore] = APlayerData[playerid][PlayerScore] + GetPVarInt(playerid, "PVarScore");
  264. // Clear the PVar
  265. SetPVarInt(playerid, "PVarScore", 0);
  266. }
  267. // Reset the player's money and set it to the stored value in the player's account (do the same for scorepoints)
  268. ResetPlayerMoney(playerid);
  269. GivePlayerMoney(playerid, APlayerData[playerid][PlayerMoney]);
  270. SetPlayerScore(playerid, APlayerData[playerid][PlayerScore]);
  271. // Limit the cash that the player can have
  272. if (APlayerData[playerid][PlayerMoney] > 999000000)
  273. APlayerData[playerid][PlayerMoney] = 999000000;
  274. // Limit the cash that the player can have below 0
  275. if (APlayerData[playerid][PlayerMoney] < -1000000)
  276. APlayerData[playerid][PlayerMoney] = -1000000;
  277. // Port anyone out of the area who is not an admin and inside the area 69
  278. Player_PortOutAdminZone(playerid, 106.0, 1805.0, -50.0, 285.0, 1940.0, 40.0, 15.0, 1732.0, 25.0);
  279. // Weapon hacks are also neutralized here, except for police players (if they are allowed to have weapons)
  280. if ((PoliceGetsWeapons == true) && (APlayerData[playerid][PlayerClass] == ClassPolice))
  281. {
  282. // Do nothing
  283. }
  284. else
  285. ResetPlayerWeapons(playerid); // Remove all weapons from the player
  286. // Check if the player got any armour (= health-hack)
  287. GetPlayerArmour(playerid, Armour);
  288. // Send an automated report to the admins so they're informed about it and can take action
  289. if (Armour > 1.0)
  290. SendReportToAdmins(playerid, "Health-hack", true);
  291. // Check if the speed is higher than 300 (kick player if it is)
  292. // Send an automated report to the admins so they're informed about it and can take action
  293. if (APlayerData[playerid][PlayerSpeed] > 300)
  294. SendReportToAdmins(playerid, "Speed-hack", true);
  295. // Check if the player is not allowed to have a jetpack (admins lvl 3 and higher can use /fly, so they will be excluded)
  296. if (APlayerData[playerid][PlayerLevel] < 3)
  297. {
  298. // Check if the player is using a jetpack
  299. // Send an automated report to the admins so they're informed about it and can take action
  300. if (GetPlayerSpecialAction(playerid) == 2)
  301. SendReportToAdmins(playerid, "Jetpack-hack", true);
  302. }
  303. // Detect airbreak hack
  304. if (GetPlayerVehicleSeat(playerid) == 0)
  305. {
  306. // Check if the player is nearly standing still
  307. if (APlayerData[playerid][PlayerSpeed] < 10)
  308. {
  309. // Check if the player switched interior-id's
  310. if (GetPlayerInterior(playerid) != APlayerData[playerid][PreviousInt])
  311. {
  312. // Check if the new interior is the normal world or any mod-shop
  313. switch (GetPlayerInterior(playerid))
  314. {
  315. case 0, 1, 2, 3: // Check interiors 0, 1, 2 and 3 (normal world and all mod-shops)
  316. {
  317. // Store the player's current location and interior-id for the next iteration
  318. GetPlayerPos(playerid, APlayerData[playerid][PreviousX], APlayerData[playerid][PreviousY], APlayerData[playerid][PreviousZ]);
  319. APlayerData[playerid][PreviousInt] = GetPlayerInterior(playerid);
  320. // Exit the function
  321. return 1;
  322. }
  323. }
  324. }
  325. // Check if the player is still near the same place he was half a second ago
  326. if (IsPlayerInRangeOfPoint(playerid, 7.5, APlayerData[playerid][PreviousX], APlayerData[playerid][PreviousY], APlayerData[playerid][PreviousZ]))
  327. {
  328. }
  329. else // Send an automated report to the admins so they're informed about it and can take action
  330. SendReportToAdmins(playerid, "Airbreak-hack", true);
  331. }
  332. }
  333. // Store the player's current location and interior-id for the next iteration
  334. GetPlayerPos(playerid, APlayerData[playerid][PreviousX], APlayerData[playerid][PreviousY], APlayerData[playerid][PreviousZ]);
  335. APlayerData[playerid][PreviousInt] = GetPlayerInterior(playerid);
  336. return 1;
  337. }