Guest User

PPC_Trucking sebesség mérő fordította: Shifty

a guest
Mar 23rd, 2013
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 39.21 KB | None | 0 0
  1. // Make sure you don't get warnings about tabsize
  2. #pragma tabsize 0
  3.  
  4. // Includék
  5. #include <a_samp>
  6. #include <sscanf2>
  7. #include <streamer>
  8. #include <zcmd>
  9.  
  10.  
  11.  
  12. // ******************************************************************************************************************************
  13. // Settings that can be changed
  14. // ******************************************************************************************************************************
  15.  
  16. // Define where the Camera-file is located (all camera's are stored in one file) and the max amount of speedcamera's
  17. #define CameraFile "PPC_Speedometer/Cameras.ini"
  18. #define MAX_CAMERAS 100
  19.  
  20.  
  21.  
  22. // Define maximum fuel amount (default: 2400)
  23. // Changing MaxFuel changes how fast a vehicle will run without fuel
  24. // 1 fuel is consumed every half a second, that's 2 fuel per second
  25. // A value of 2400 allows you to drive 2400/2 = 1200 seconds (or 1200/60 = 20 minutes) without refuelling
  26. new MaxFuel = 2400;
  27. // RefuelMaxPrice is the price you pay for a total refuel (when the vehicle has no more fuel), the price to pay is calculated
  28. // by the amount of fuel to refuel (pay 50% of RefuelMaxPrice when vehicle has half a fuel-tank left)
  29. new RefuelMaxPrice = 1000;
  30.  
  31. // An extra setting to disable the shadows for the speedometer and fuel textdraws (shadows enabled by default)
  32. new bool:DisableShadows = false;
  33.  
  34.  
  35.  
  36. // ******************************************************************************************************************************
  37. // Enums and the array-setups that use them
  38. // ******************************************************************************************************************************
  39.  
  40. // Setup a custom type that holds all data about a speedcamera
  41. enum TSpeedCamera
  42. {
  43. Float:CamX, // Holds the X-coordinate of the camera
  44. Float:CamY, // Holds the Y-coordinate of the camera
  45. Float:CamZ, // Holds the Z-coordinate of the camera
  46. Float:CamAngle, // Holds the Angle of the camera
  47. CamSpeed, // Holds the maximum speed allowed to pass this camera without being caught
  48. CamObj1, // Holds the reference to the first camera object
  49. CamObj2 // Holds the reference to the second camera object
  50. }
  51. new ACameras[MAX_CAMERAS][TSpeedCamera];
  52.  
  53. // Setup a custom type that holds the data of pickups
  54. enum TPickupData
  55. {
  56. Float:pux, // Holds the x-position of the refuel-pickup
  57. Float:puy, // Holds the y-position of the refuel-pickup
  58. Float:puz, // Holds the z-position of the refuel-pickup
  59. PickupID // Holds the PickupID of the refuel-pickup
  60. }
  61. // Holds the data for pickups for refuelling (maximum 50 refuel-pickups)
  62. new ARefuelPickups[50][TPickupData];
  63.  
  64. // Setup a custom type to hold all data about a vehicle
  65. enum TVehicleData
  66. {
  67. Fuel // Holds the amount of fuel for this vehicle
  68. }
  69. // Setup an array which holds all data for every vehicleid, max 2000 vehicles (server limit)
  70. new AVehicleData[2000][TVehicleData];
  71.  
  72. // Setup all the fields required for the player data (Speedometer TextDraw, current job, ...)
  73. enum TPlayerData
  74. {
  75. Text:SpeedometerText, // The TextDraw of the speedometer for this player
  76. Text:FuelGauge, // The textdraw of the fuel-gauge for this player
  77. SpeedometerTimer, // Holds the reference to the speedometer timer for this player
  78. PlayerSpeed, // Holds the speed of the player
  79. PlayerCaughtSpeeding // This holds a value to prevent being caught multiple times by the same speedcamera
  80. }
  81. // Create an array to hold the playerdata for every player
  82. new APlayerData[MAX_PLAYERS][TPlayerData];
  83.  
  84.  
  85.  
  86. // These variables are used when starting the script and debugging purposes
  87. new TotalRefuelStations, TotalCameras;
  88.  
  89.  
  90.  
  91. // ******************************************************************************************************************************
  92. // Callbacks
  93. // ******************************************************************************************************************************
  94.  
  95. // The main function (used only once when the server loads)
  96. main()
  97. {
  98. }
  99.  
  100. // This callback gets called when the server initializes the filterscript
  101. public OnFilterScriptInit()
  102. {
  103. // Loop through all vehicles
  104. for (new vid; vid < 2000; vid++)
  105. {
  106. // If this vehicle belongs to the PPC_Housing script, don't refuel it, as the housing script manages the fuel for this vehicle
  107. // by using remote calls to this script
  108. if (CallRemoteFunction("Housing_IsVehicleOwned", "i", vid) == 1)
  109. {
  110. // The vehicle is owned by a player in the housing script, so do nothing, the housing script manages this vehicle's fuel
  111. }
  112. else // The vehicle doesn't belong to the housing script (it's created and managed by another script), set the fuel to maximum
  113. AVehicleData[vid][Fuel] = MaxFuel;
  114. }
  115.  
  116. // Add all refuel-pickups to the world (including their icon)
  117. AddRefuelPickup(-1471.5, 1863.75, 32.7);
  118. AddRefuelPickup(-1326.5, 2677.5, 50.1);
  119. AddRefuelPickup(611.5, 1694.5, 7.0);
  120. AddRefuelPickup(-2249.25, -2559.0, 32.0);
  121. AddRefuelPickup(-1606.5, -2714.0, 48.6);
  122. AddRefuelPickup(-93.5, -1175.0, 2.3);
  123. AddRefuelPickup(1377.5, 457.0, 19.9);
  124. AddRefuelPickup(651.5, -565.5, 16.4);
  125. AddRefuelPickup(-1675.75, 412.75, 7.2);
  126. AddRefuelPickup(-2405.50, 976.25, 45.3);
  127. AddRefuelPickup(-2023.25, 156.75, 28.9);
  128. AddRefuelPickup(-1131.75, -204.25, 14.2);
  129. AddRefuelPickup(66.50, 1220.50, 18.9);
  130. AddRefuelPickup(350.50, 2537.50, 16.8);
  131. AddRefuelPickup(2147.00, 2747.75, 10.9);
  132. AddRefuelPickup(2639.75, 1106.00, 10.9);
  133. AddRefuelPickup(2115.00, 920.00, 10.9);
  134. AddRefuelPickup(2202.00, 2475.00, 10.9);
  135. AddRefuelPickup(1596.50, 2199.75, 10.9);
  136. AddRefuelPickup(1584.25, 1448.25, 10.9);
  137. AddRefuelPickup(1004.25, -940.50, 42.2);
  138. AddRefuelPickup(1935.00, -1772.75, 13.4);
  139.  
  140. // Load all speedcamera's
  141. CameraFile_Load();
  142.  
  143. printf("\n----------------------------------------");
  144. printf("PPC Speedometer filterscript initialized");
  145. printf("Gas-stations created: %i", TotalRefuelStations);
  146. printf("Speedcamera's loaded: %i", TotalCameras);
  147. printf("----------------------------------------\n");
  148.  
  149. return 1;
  150. }
  151.  
  152. // This callback gets called when a player connects to the server
  153. public OnPlayerConnect(playerid)
  154. {
  155. // Setup the speedometer for this player
  156. Speedometer_Setup(playerid);
  157.  
  158. return 1;
  159. }
  160.  
  161. // This callback gets called when a player disconnects from the server
  162. public OnPlayerDisconnect(playerid, reason)
  163. {
  164. // Cleanup the speedometer for this player
  165. Speedometer_Cleanup(playerid);
  166.  
  167. return 1;
  168. }
  169.  
  170. // This callback gets called when a vehicle respawns at it's spawn-location (where it was created)
  171. public OnVehicleSpawn(vehicleid)
  172. {
  173. // If this vehicle belongs to the PPC_Housing script, don't refuel it, as the housing script manages the fuel for this vehicle
  174. // by using remote calls to this script
  175. if (CallRemoteFunction("Housing_IsVehicleOwned", "i", vehicleid) == 1)
  176. {
  177. // The vehicle is owned by a player in the housing script, so do nothing, the housing script manages this vehicle's fuel
  178. }
  179. else // The vehicle doesn't belong to the housing script (it's created and managed by another script), set the fuel to maximum
  180. AVehicleData[vehicleid][Fuel] = MaxFuel;
  181.  
  182. return 1;
  183. }
  184.  
  185. // This callback gets called whenever a player changes state
  186. public OnPlayerStateChange(playerid,newstate,oldstate)
  187. {
  188. // Setup local variables
  189. new vehicleid, engine, lights, alarm, doors, bonnet, boot, objective;
  190.  
  191. // Check if the player entered a vehicle as driver
  192. if (newstate == PLAYER_STATE_DRIVER)
  193. {
  194. // Get the player's vehicle
  195. vehicleid = GetPlayerVehicleID(playerid);
  196.  
  197. // Check if the vehicle has fuel
  198. if (AVehicleData[vehicleid][Fuel] > 0)
  199. {
  200. // Start the engine and turn on the lights
  201. GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
  202. SetVehicleParamsEx(vehicleid, 1, 1, alarm, doors, bonnet, boot, objective);
  203. }
  204. }
  205. }
  206.  
  207. // This callback gets called when a player exits his vehicle
  208. public OnPlayerExitVehicle(playerid, vehicleid)
  209. {
  210. // Setup local variables
  211. new engine, lights, alarm, doors, bonnet, boot, objective;
  212.  
  213. // Check if the player is the driver of the vehicle
  214. if (GetPlayerVehicleSeat(playerid) == 0)
  215. {
  216. // Turn off the lights and engine
  217. GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
  218. SetVehicleParamsEx(vehicleid, 0, 0, alarm, doors, bonnet, boot, objective);
  219. }
  220.  
  221. return 1;
  222. }
  223.  
  224. // This callback gets called whenever a player presses a key
  225. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  226. {
  227. // Refuel a vehicle when driving a vehicle and pressing the HORN key near a refuelpickup
  228. // Check if the player presses the HORN key
  229. if ((newkeys & KEY_CROUCH) && !(oldkeys & KEY_CROUCH))
  230. {
  231. // Check if the player is driving a vehicle
  232. if (GetPlayerVehicleSeat(playerid) == 0)
  233. {
  234. // Loop through all ARefuelPickups
  235. for (new i; i < sizeof(ARefuelPickups); i++)
  236. {
  237. // Check if this refuel-pickup exists (check for a valid pickup)
  238. if (IsValidDynamicPickup(ARefuelPickups[i][PickupID]))
  239. {
  240. // Check if the player is in range of a refuelpickup
  241. if(IsPlayerInRangeOfPoint(playerid, 5.0, ARefuelPickups[i][pux], ARefuelPickups[i][puy], ARefuelPickups[i][puz]))
  242. {
  243. // Show a message that the player's vehicle is refuelling
  244. GameTextForPlayer(playerid, "~g~tankolás...", 3000, 4);
  245. // Don't allow the player to move again (the timer will allow it after refuelling)
  246. TogglePlayerControllable(playerid, 0);
  247. // Start a timer (let the player wait until the vehicle is refuelled)
  248. SetTimerEx("RefuelVehicle", 5000, false, "i", playerid);
  249. // Stop the search
  250. break;
  251. }
  252. }
  253. else // No more refuel-pickups, so stop searching through the array
  254. break;
  255. }
  256. }
  257. }
  258. }
  259.  
  260.  
  261.  
  262. // ******************************************************************************************************************************
  263. // Commands
  264. // ******************************************************************************************************************************
  265.  
  266. // This command allows you to create a speedcamera
  267. COMMAND:createcamera(playerid, params[])
  268. {
  269. // Setup local variables
  270. new Float:x, Float:y, Float:z, Float:rot, MaxSpeed, Msg[128];
  271.  
  272. // If a player hasn't logged in properly, he cannot use this command
  273. if (INT_IsPlayerLoggedIn(playerid) == 0) return 0;
  274. // If the player has an insufficient admin-level (he needs level 5 or RCON admin), exit the command
  275. // returning "SERVER: Unknown command" to the player
  276. if (INT_CheckPlayerAdminLevel(playerid, 5) == 0) return 0;
  277.  
  278. // Split the parameters to useable variables
  279. if (sscanf(params, "i", MaxSpeed)) SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}Használat: \"/createcamera <max_speed>\"");
  280. else
  281. {
  282. // Check if the player is on foot
  283. if (GetPlayerVehicleSeat(playerid) == -1)
  284. {
  285. // Get player's position and facing angle
  286. GetPlayerPos(playerid, x, y, z);
  287. GetPlayerFacingAngle(playerid, rot);
  288. z = z - 1.0; // Adjust camera Z-coordinate 1m lower than normal (otherwise the camera floats in the air)
  289.  
  290. // Move the player a bit, otherwise he could get stuck inside the camera-object
  291. SetPlayerPos(playerid, x, y + 1.0, z + 1.0);
  292.  
  293. // Save the camera to a file
  294. for (new CamID; CamID < MAX_CAMERAS; CamID++)
  295. {
  296. // Check if this index is free
  297. if (ACameras[CamID][CamSpeed] == 0)
  298. {
  299. // Setup this camera (create the objects and store the data)
  300. SetupSpeedCamera(CamID, x, y, z, rot, MaxSpeed);
  301.  
  302. // Also save the entire camerafile again to add this new camera to the file
  303. CameraFile_Save();
  304.  
  305. // Let the player know he created a new camera
  306. format(Msg, 128, "{00FF00}Már létrehoztál egy sebességmérő id-t: {FFFF00}%i", CamID);
  307. SendClientMessage(playerid, 0xFFFFFFFF, Msg);
  308.  
  309. // Exit the function
  310. return 1;
  311. }
  312. }
  313.  
  314. // In case all camera-slots are occupied (100 camera's have been created already), let the player know about it
  315. format(Msg, 128, "{FF0000}Nem tudsz létrehozni több %i sebességmérő kamerát! ", MAX_CAMERAS);
  316. SendClientMessage(playerid, 0xFFFFFFFF, Msg);
  317. }
  318. else
  319. SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}Csak gyalog tudod használni a parancsot!");
  320. }
  321.  
  322. // Let the server know that this was a valid command
  323. return 1;
  324. }
  325.  
  326. // This command allows you to delete a speedcamera
  327. COMMAND:delcamera(playerid, params[])
  328. {
  329. // Setup local variables
  330. new Msg[128];
  331.  
  332. // If a player hasn't logged in properly, he cannot use this command
  333. if (INT_IsPlayerLoggedIn(playerid) == 0) return 0;
  334. // If the player has an insufficient admin-level (he needs level 5 or RCON admin), exit the command
  335. // returning "SERVER: Unknown command" to the player
  336. if (INT_CheckPlayerAdminLevel(playerid, 5) == 0) return 0;
  337.  
  338. // Check if the player is on foot
  339. if (GetPlayerVehicleSeat(playerid) == -1)
  340. {
  341. // Loop through all camera's
  342. for (new CamID; CamID < MAX_CAMERAS; CamID++)
  343. {
  344. // Check if this index is used
  345. if (ACameras[CamID][CamSpeed] != 0)
  346. {
  347. // Check if the player is in range of the camera
  348. if (IsPlayerInRangeOfPoint(playerid, 5.0, ACameras[CamID][CamX], ACameras[CamID][CamY], ACameras[CamID][CamZ]))
  349. {
  350. // Delete both camera objects
  351. DestroyDynamicObject(ACameras[CamID][CamObj1]);
  352. DestroyDynamicObject(ACameras[CamID][CamObj2]);
  353. // Also clear the data from memory
  354. ACameras[CamID][CamX] = 0.0;
  355. ACameras[CamID][CamY] = 0.0;
  356. ACameras[CamID][CamZ] = 0.0;
  357. ACameras[CamID][CamAngle] = 0.0;
  358. ACameras[CamID][CamSpeed] = 0;
  359. ACameras[CamID][CamObj1] = 0;
  360. ACameras[CamID][CamObj2] = 0;
  361.  
  362. // Also save the entire camerafile again to remove this camera from the file
  363. CameraFile_Save();
  364.  
  365. // Let the player know he deleted a camera
  366. format(Msg, 128, "{00FF00}Törölted a sebességmérő kamerát. {FFFF00}%i", CamID);
  367. SendClientMessage(playerid, 0xFFFFFFFF, Msg);
  368.  
  369. // Exit the function
  370. return 1;
  371. }
  372. }
  373. }
  374.  
  375. // In case the player wasn't near a speedcamera, inform him about it
  376. SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}You must be near a speedcamera to delete it");
  377. }
  378. else
  379. SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}Csak gyalog tudod használni a parancsot!");
  380.  
  381. // Let the server know that this was a valid command
  382. return 1;
  383. }
  384.  
  385. // This command allows you to refuel your vehicle for free (admins only)
  386. COMMAND:fuel(playerid, params[])
  387. {
  388. // Setup local variables
  389. new vid, engine, lights, alarm, doors, bonnet, boot, objective;
  390.  
  391. // If a player hasn't logged in properly, he cannot use this command
  392. if (INT_IsPlayerLoggedIn(playerid) == 0) return 0;
  393. // If the player has an insufficient admin-level (he needs level 1 or RCON admin), exit the command
  394. // returning "SERVER: Unknown command" to the player
  395. if (INT_CheckPlayerAdminLevel(playerid, 1) == 0) return 0;
  396.  
  397. // Check if the player is the driver of a vehicle
  398. if (GetPlayerVehicleSeat(playerid) == 0)
  399. {
  400. // Get the vehicleid
  401. vid = GetPlayerVehicleID(playerid);
  402. // Refuel the vehicle
  403. AVehicleData[vid][Fuel] = MaxFuel;
  404. // Also (re-)start the engine and turn on the lights in case the vehicle is completely out of fuel
  405. GetVehicleParamsEx(vid, engine, lights, alarm, doors, bonnet, boot, objective);
  406. SetVehicleParamsEx(vid, 1, 1, alarm, doors, bonnet, boot, objective);
  407. // Let the player know about it
  408. SendClientMessage(playerid, 0xFFFFFFFF, "{00FF00}Jármű megtankolva.");
  409. }
  410. else
  411. SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}Te nem vagy vezető.");
  412.  
  413. // Let the server know that this was a valid command
  414. return 1;
  415. }
  416.  
  417.  
  418.  
  419. // ******************************************************************************************************************************
  420. // Speedometer functions
  421. // ******************************************************************************************************************************
  422.  
  423. // This function sets up the speedometer for the given player
  424. Speedometer_Setup(playerid)
  425. {
  426. // Setup the speedometer for the player
  427. APlayerData[playerid][SpeedometerText] = TextDrawCreate(500.0, 395.0, " ");
  428. APlayerData[playerid][FuelGauge] = TextDrawCreate(500.0, 410.0, " ");
  429. // Disable shadows if required
  430. if (DisableShadows == true)
  431. {
  432. TextDrawSetShadow(APlayerData[playerid][SpeedometerText], 0);
  433. TextDrawSetShadow(APlayerData[playerid][FuelGauge], 0);
  434. }
  435. // Enable the TextDraw for this player
  436. TextDrawShowForPlayer(playerid, APlayerData[playerid][SpeedometerText]);
  437. TextDrawShowForPlayer(playerid, APlayerData[playerid][FuelGauge]);
  438.  
  439. // Start the speedometer timer for this player
  440. APlayerData[playerid][SpeedometerTimer] = SetTimerEx("Speedometer_Update", 500, true, "i", playerid);
  441.  
  442. return 1;
  443. }
  444.  
  445. // This function cleans up the speedometer for the given player
  446. Speedometer_Cleanup(playerid)
  447. {
  448. // Destroy the speedometer textdraw
  449. TextDrawDestroy(APlayerData[playerid][SpeedometerText]);
  450. TextDrawDestroy(APlayerData[playerid][FuelGauge]);
  451. // Kill the speedometer timer
  452. KillTimer(APlayerData[playerid][SpeedometerTimer]);
  453. // Set player speed to 0
  454. APlayerData[playerid][PlayerSpeed] = 0;
  455.  
  456. return 1;
  457. }
  458.  
  459. // Forward the function needed to update the speedometer
  460. forward Speedometer_Update(playerid);
  461. // This function gets called by a timer which runs every 500ms to display and update the speedometer
  462. public Speedometer_Update(playerid)
  463. {
  464. // Setup local variables
  465. new vid, Float:speed_x, Float:speed_y, Float:speed_z, Float:final_speed, speed_string[50], final_speed_int, Float:vehiclehealth;
  466. new FuelString[50], FuelStatus[20];
  467.  
  468. // Get the ID of the player's vehicle
  469. vid = GetPlayerVehicleID(playerid);
  470.  
  471. // If the player is inside a vehicle
  472. if(vid != 0)
  473. {
  474. // Get the vehicles velocity
  475. GetVehicleVelocity(vid, speed_x, speed_y, speed_z);
  476. // Calculate the speed (in kph)
  477. final_speed = floatsqroot(((speed_x * speed_x) + (speed_y * speed_y)) + (speed_z * speed_z)) * 158.179;
  478. // Convert the float value to an int value
  479. final_speed_int = floatround(final_speed, floatround_round);
  480. // Also save the speed for the player
  481. APlayerData[playerid][PlayerSpeed] = final_speed_int;
  482. // Setup the string to display for the player and display it
  483. format(speed_string, 50, "~w~sebesség: ~b~%i~w~ kph", final_speed_int);
  484. TextDrawSetString(APlayerData[playerid][SpeedometerText], speed_string);
  485.  
  486. // Also display the vehicle's health through the player-health bar
  487. GetVehicleHealth(vid, vehiclehealth);
  488. SetPlayerHealth(vid, vehiclehealth / 10.0);
  489.  
  490. // Check if the player is the driver of the vehicle (otherwise every passenger would consume fuel for just being in the car)
  491. if (GetPlayerVehicleSeat(playerid) == 0)
  492. if ((final_speed_int > 10) && (AVehicleData[vid][Fuel] > 0)) // Check if the speed is above 10kph and if the vehicle didn't run out of fuel
  493. AVehicleData[vid][Fuel] = AVehicleData[vid][Fuel] - 1; // Decrease the fuel for this vehicle every time the timer is run
  494.  
  495. // Construct the fuelgauge
  496. if ((AVehicleData[vid][Fuel] > 0) && (AVehicleData[vid][Fuel] < 100000))
  497. format(FuelStatus, 20, "~g~%s~r~%s", "I", "IIIIIIIII"); // Fuel is between 0% and 10% full
  498.  
  499. if ((AVehicleData[vid][Fuel] >= ((MaxFuel / 10) * 1)) && (AVehicleData[vid][Fuel] < ((MaxFuel / 10) * 2)))
  500. format(FuelStatus, 20, "~g~%s~r~%s", "II", "IIIIIIII"); // Fuel is between 10% and 20% full
  501.  
  502. if ((AVehicleData[vid][Fuel] >= ((MaxFuel / 10) * 2)) && (AVehicleData[vid][Fuel] < ((MaxFuel / 10) * 3)))
  503. format(FuelStatus, 20, "~g~%s~r~%s", "III", "IIIIIII"); // Fuel is between 20% and 30% full
  504.  
  505. if ((AVehicleData[vid][Fuel] >= ((MaxFuel / 10) * 3)) && (AVehicleData[vid][Fuel] < ((MaxFuel / 10) * 4)))
  506. format(FuelStatus, 20, "~g~%s~r~%s", "IIII", "IIIIII"); // Fuel is between 30% and 40% full
  507.  
  508. if ((AVehicleData[vid][Fuel] >= ((MaxFuel / 10) * 4)) && (AVehicleData[vid][Fuel] < ((MaxFuel / 10) * 5)))
  509. format(FuelStatus, 20, "~g~%s~r~%s", "IIIII", "IIIII"); // Fuel is between 40% and 50% full
  510.  
  511. if ((AVehicleData[vid][Fuel] >= ((MaxFuel / 10) * 5)) && (AVehicleData[vid][Fuel] < ((MaxFuel / 10) * 6)))
  512. format(FuelStatus, 20, "~g~%s~r~%s", "IIIIII", "IIII"); // Fuel is between 50% and 60% full
  513.  
  514. if ((AVehicleData[vid][Fuel] >= ((MaxFuel / 10) * 6)) && (AVehicleData[vid][Fuel] < ((MaxFuel / 10) * 7)))
  515. format(FuelStatus, 20, "~g~%s~r~%s", "IIIIIII", "III"); // Fuel is between 60% and 70% full
  516.  
  517. if ((AVehicleData[vid][Fuel] >= ((MaxFuel / 10) * 7)) && (AVehicleData[vid][Fuel] < ((MaxFuel / 10) * 8)))
  518. format(FuelStatus, 20, "~g~%s~r~%s", "IIIIIIII", "II"); // Fuel is between 70% and 80% full
  519.  
  520. if ((AVehicleData[vid][Fuel] >= ((MaxFuel / 10) * 8)) && (AVehicleData[vid][Fuel] < ((MaxFuel / 10) * 9)))
  521. format(FuelStatus, 20, "~g~%s~r~%s", "IIIIIIIII", "I"); // Fuel is between 80% and 90% full
  522.  
  523. if ((AVehicleData[vid][Fuel] >= ((MaxFuel / 10) * 9)) && (AVehicleData[vid][Fuel] <= MaxFuel))
  524. format(FuelStatus, 20, "~g~%s", "IIIIIIIIII"); // Fuel is between 90% and 100% full (all bars are green)
  525.  
  526. if (AVehicleData[vid][Fuel] == 0)
  527. format(FuelStatus, 20, "~r~%s", "IIIIIIIIII"); // Fuel is empty (all bars are red)
  528.  
  529. // Format the final fuel-gauge readout
  530. format(FuelString, 50, "~w~Benzin: %s", FuelStatus);
  531. // Display the fuel-gauge
  532. TextDrawSetString(APlayerData[playerid][FuelGauge], FuelString);
  533.  
  534. // Check if the vehicle is out of fuel
  535. if (AVehicleData[vid][Fuel] == 0)
  536. {
  537. // Stop the engine and turn off the lights so the player cannot drive anymore with this vehicle
  538. new engine,lights,alarm,doors,bonnet,boot,objective;
  539. GetVehicleParamsEx(vid, engine, lights, alarm, doors, bonnet, boot, objective);
  540. SetVehicleParamsEx(vid, 0, 0, alarm, doors, bonnet, boot, objective);
  541. }
  542.  
  543. // Check if the player is not in any plane or helicopter (those cannot be caught by speedcamera's)
  544. if (IsVehicleAirVehicle(vid) == 0)
  545. CheckPlayerSpeeding(playerid);
  546. }
  547. else
  548. {
  549. // If the player is not inside a vehicle, display an empty string (looks like the speedometer is gone)
  550. TextDrawSetString(APlayerData[playerid][SpeedometerText], " ");
  551. TextDrawSetString(APlayerData[playerid][FuelGauge], " ");
  552. // Set the speed of the player to 0
  553. APlayerData[playerid][PlayerSpeed] = 0;
  554. }
  555. }
  556.  
  557. // This function checks if the player is speeding near a speedcamera
  558. CheckPlayerSpeeding(playerid)
  559. {
  560. // Check if the player hasn't been caught speeding recently
  561. if (APlayerData[playerid][PlayerCaughtSpeeding] == 0)
  562. {
  563. // Loop through all speedcameras
  564. for (new CamID; CamID < MAX_CAMERAS; CamID++)
  565. {
  566. // Check if this camera has been created
  567. if (ACameras[CamID][CamSpeed] != 0)
  568. {
  569. // Check if the player is the driver of the vehicle
  570. if (GetPlayerVehicleSeat(playerid) == 0)
  571. {
  572. // 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)
  573. if (APlayerData[playerid][PlayerSpeed] > ACameras[CamID][CamSpeed])
  574. {
  575. // Check if the player is near the camera
  576. if (IsPlayerInRangeOfPoint(playerid, 50.0, ACameras[CamID][CamX], ACameras[CamID][CamY], ACameras[CamID][CamZ]))
  577. {
  578. // Prevent the player being caught multiple times by the same speed-camera
  579. APlayerData[playerid][PlayerCaughtSpeeding] = 20;
  580. // Increase the wanted-level of this player by 1 star
  581. SetPlayerWantedLevel(playerid, GetPlayerWantedLevel(playerid) + 1);
  582. // Let the player know he's been caught speeding
  583. SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}Elkapott egy trafipax, kérlek lassíts!");
  584. }
  585. }
  586. }
  587. }
  588. }
  589. }
  590. else // If the player has been caught before, reduce the value until it's 0 again, then he can be caught again
  591. APlayerData[playerid][PlayerCaughtSpeeding]--;
  592. }
  593.  
  594. // This function returns "1" if the given vehicle-id is a plane or helicopter
  595. IsVehicleAirVehicle(vid)
  596. {
  597. switch (GetVehicleModel(vid))
  598. {
  599. case 592, 577, 511, 512, 593, 520, 553, 476, 519, 460, 513, 548, 425, 417, 487, 488, 497, 563, 447, 469: return 1;
  600. default: return 0;
  601. }
  602.  
  603. return 0;
  604. }
  605.  
  606. // Forward the refueltimer
  607. forward RefuelVehicle(playerid);
  608. // This timer-function is called when a player refuels near a refuelpickup
  609. public RefuelVehicle(playerid)
  610. {
  611. new RefuelMsg[128];
  612. // Get the vehicle-id of the player's vehicle
  613. new vid = GetPlayerVehicleID(playerid);
  614. // Calculate the amount of fuel that needs to be refuelled
  615. new Amount = MaxFuel - AVehicleData[vid][Fuel];
  616. // Calculate the price to refuel
  617. new RefuelPrice = (Amount * RefuelMaxPrice) / MaxFuel;
  618.  
  619. // Check if the player has enough cash
  620. if (INT_GetPlayerMoney(playerid) >= RefuelPrice)
  621. {
  622. // Refuel the vehicle
  623. AVehicleData[vid][Fuel] = MaxFuel;
  624. // Withdraw the money from the player
  625. INT_GivePlayerMoney(playerid, -RefuelPrice);
  626. // Let the player know he refuelled his vehicle
  627. format(RefuelMsg, 128, "{00FF00}A Benzin ára: $%i", RefuelPrice);
  628. SendClientMessage(playerid, 0xFFFFFFFF, RefuelMsg);
  629. }
  630. else
  631. SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}Nincs elég pénzed hogy megtankold!");
  632.  
  633. // Allow the player to move again
  634. TogglePlayerControllable(playerid, 1);
  635.  
  636. return 1;
  637. }
  638.  
  639. // This function is used to add refuelling pickups to the map
  640. AddRefuelPickup(Float:x, Float:y, Float:z)
  641. {
  642. // Add the pickup-id to the ARefuelPickups array
  643. for (new i; i < sizeof(ARefuelPickups); i++)
  644. {
  645. // If an empty array-index is found (no valid pickup)
  646. if (!IsValidDynamicPickup(ARefuelPickups[i][PickupID]))
  647. {
  648. // Store the pickup-id in this empty slot
  649. ARefuelPickups[i][PickupID] = CreateDynamicPickup(1244, 1, x, y, z, 0); // Type 1, cannot be pickup up, exists all the time
  650. ARefuelPickups[i][pux] = x;
  651. ARefuelPickups[i][puy] = y;
  652. ARefuelPickups[i][puz] = z;
  653. // Count the total amount of refuelstations that have been created
  654. TotalRefuelStations++;
  655.  
  656. // Add a 3DText message above the refuel-pickup
  657. CreateDynamic3DTextLabel("Dudálj egyet\nhogy megtankolják a kocsidat.", 0x008080FF, x, y, z + 0.8, 30.0);
  658.  
  659. // Add an icon to the map for this refuel-spot
  660. CreateDynamicMapIcon(x, y, z, 56, 0, 0, 0, -1, 300.0);
  661.  
  662. // Stop browsing through the array
  663. break;
  664. }
  665. }
  666. }
  667.  
  668. // This function will load the speedcamera's datafile (used when the server is started to load all cameras)
  669. CameraFile_Load()
  670. {
  671. // Setup local variables
  672. new file[128], File:CFile, LineFromFile[100], ParameterName[50], ParameterValue[50];
  673. new CamID, Float:x, Float:y, Float:z, Float:rot, MaxSpeed;
  674.  
  675. // Construct the complete filename for this camera-file
  676. format(file, sizeof(file), CameraFile);
  677.  
  678. // Check if the camerafile exists
  679. if (fexist(file))
  680. {
  681. // Open the camerafile for reading
  682. CFile = fopen(file, io_read);
  683.  
  684. // Read the first line of the file
  685. fread(CFile, LineFromFile);
  686.  
  687. // Keep reading until the end of the file is found (no more data)
  688. // An empty line between data-segments still has the NewLine characters (\r\n) so it's not completely empty
  689. // Reading past the last line will read a completely empty line, therefore indicating the end of the file
  690. while (strlen(LineFromFile) > 0)
  691. {
  692. StripNewLine(LineFromFile); // Strip any newline characters from the LineFromFile
  693. sscanf(LineFromFile, "s[50]s[50]", ParameterName, ParameterValue); // Extract parametername and parametervalue
  694.  
  695. // Check if there is anything in the LineFromFile (skipping empty lines)
  696. if (strlen(LineFromFile) > 0)
  697. {
  698. // Check if a header for a camera has been found
  699. if (strcmp(ParameterName, "[Camera]", false) == 0)
  700. {
  701. // Clear all variables
  702. x = 0.0;
  703. y = 0.0;
  704. z = 0.0;
  705. rot = 0.0;
  706. MaxSpeed = 0;
  707. }
  708. // Store the proper value in the proper place
  709. if (strcmp(ParameterName, "CamX", false) == 0) // If the parametername is correct ("CamX")
  710. x = floatstr(ParameterValue); // Store the CamX
  711. if (strcmp(ParameterName, "CamY", false) == 0) // If the parametername is correct ("CamY")
  712. y = floatstr(ParameterValue); // Store the CamY
  713. if (strcmp(ParameterName, "CamZ", false) == 0) // If the parametername is correct ("CamZ")
  714. z = floatstr(ParameterValue); // Store the CamZ
  715. if (strcmp(ParameterName, "CamAngle", false) == 0) // If the parametername is correct ("CamAngle")
  716. rot = floatstr(ParameterValue); // Store the CamAngle
  717. if (strcmp(ParameterName, "CamSpeed", false) == 0) // If the parametername is correct ("CamSpeed")
  718. MaxSpeed = strval(ParameterValue); // Store the CamSpeed
  719.  
  720. // Check if a end of a camera has been found
  721. if (strcmp(ParameterName, "[/Camera]", false) == 0)
  722. {
  723. SetupSpeedCamera(CamID, x, y, z, rot, MaxSpeed); // Setup the camera
  724. TotalCameras++; // Count the total camera's loaded from the file
  725. CamID++; // Increase the CamID to select the next camera before data is loaded (in case more camera's are found in the file)
  726. }
  727. }
  728.  
  729. // Read the next line of the file
  730. fread(CFile, LineFromFile);
  731. }
  732.  
  733. // Close the file
  734. fclose(CFile);
  735. }
  736. }
  737.  
  738. // This function will save the speedcamera's datafile
  739. CameraFile_Save()
  740. {
  741. // Setup local variables
  742. new file[100], File:PFile, LineForFile[100];
  743.  
  744. // Save the file
  745. format(file, sizeof(file), CameraFile); // Construct the complete filename for the camera-file
  746.  
  747. PFile = fopen(file, io_write); // Open the camera-file for writing
  748.  
  749. // Loop through all camera's
  750. for (new CamID; CamID < MAX_CAMERAS; CamID++)
  751. {
  752. // Check if this index holds a camera
  753. if (ACameras[CamID][CamSpeed] != 0)
  754. {
  755. fwrite(PFile, "[Camera]\r\n"); // Save the header of the camera
  756.  
  757. format(LineForFile, 100, "CamX %f\r\n", ACameras[CamID][CamX]);
  758. fwrite(PFile, LineForFile); // And save it to the file
  759. format(LineForFile, 100, "CamY %f\r\n", ACameras[CamID][CamY]);
  760. fwrite(PFile, LineForFile); // And save it to the file
  761. format(LineForFile, 100, "CamZ %f\r\n", ACameras[CamID][CamZ]);
  762. fwrite(PFile, LineForFile); // And save it to the file
  763. format(LineForFile, 100, "CamAngle %f\r\n", ACameras[CamID][CamAngle]);
  764. fwrite(PFile, LineForFile); // And save it to the file
  765. format(LineForFile, 100, "CamSpeed %i\r\n", ACameras[CamID][CamSpeed]);
  766. fwrite(PFile, LineForFile); // And save it to the file
  767.  
  768. fwrite(PFile, "[/Camera]\r\n"); // Save the end of this camera
  769. fwrite(PFile, "\r\n"); // Save an empty line to split the camera's up a bit (for readability)
  770. }
  771. }
  772.  
  773. fclose(PFile); // Close the file
  774. }
  775.  
  776.  
  777.  
  778. // This function creates a speedcamera (store data and create the objects)
  779. SetupSpeedCamera(CamID, Float:x, Float:y, Float:z, Float:rot, MaxSpeed)
  780. {
  781. // Store all the given values
  782. ACameras[CamID][CamX] = x;
  783. ACameras[CamID][CamY] = y;
  784. ACameras[CamID][CamZ] = z;
  785. ACameras[CamID][CamAngle] = rot;
  786. ACameras[CamID][CamSpeed] = MaxSpeed;
  787. // Create both camera objects and store their reference
  788. ACameras[CamID][CamObj1] = CreateDynamicObject(18880, x, y, z, 0.0, 0.0, rot);
  789. ACameras[CamID][CamObj2] = CreateDynamicObject(18880, x, y, z, 0.0, 0.0, rot + 180.0);
  790.  
  791. // Update the draw distance of each camera to 300m, otherwise they could be invisible until you're standing right next to them
  792. // By default, dynamic objects have a draw distance of 0m, meaning they're only visible when you're very close to them
  793. Streamer_SetFloatData(STREAMER_TYPE_OBJECT, ACameras[CamID][CamObj1], E_STREAMER_DRAW_DISTANCE, 300.0);
  794. Streamer_SetFloatData(STREAMER_TYPE_OBJECT, ACameras[CamID][CamObj2], E_STREAMER_DRAW_DISTANCE, 300.0);
  795. }
  796.  
  797.  
  798.  
  799. // ******************************************************************************************************************************
  800. // Support functions
  801. // ******************************************************************************************************************************
  802.  
  803. // This function is copied from the include-file "dutils.inc"
  804. stock StripNewLine(string[])
  805. {
  806. new len = strlen(string); // Get the length of the given string
  807.  
  808. if (string[0] == 0) return ; // If the given string is empty, exit the function
  809. if ((string[len - 1] == '\n') || (string[len - 1] == '\r')) // If the string ends with \n or \r
  810. {
  811. string[len - 1] = 0; // Replace the \n or \r with a 0 character
  812. if (string[0]==0) return ; // If the string became empty, exit the function
  813. if ((string[len - 2] == '\n') || (string[len - 2] == '\r')) // Check again if the string ends with \n or \r
  814. string[len - 2] = 0; // Replace the \n or \r again with a 0 character
  815. }
  816. }
  817.  
  818.  
  819.  
  820. // ******************************************************************************************************************************
  821. // Special functions that try to access external public functions to retreive data from another script
  822. // ******************************************************************************************************************************
  823.  
  824. // This function is used to get the player's money
  825. INT_GetPlayerMoney(playerid)
  826. {
  827. // Setup local variables
  828. new Money;
  829.  
  830. // Try to call the external function to get the player's money (used to get the serversided money for this player)
  831. Money = CallRemoteFunction("Admin_GetPlayerMoney", "i", playerid);
  832.  
  833. // The external function returned "0" (as the player doesn't have any money yet), or the function is not used in another script
  834. if (Money == 0)
  835. return GetPlayerMoney(playerid); // Return the normal money of the player
  836. else
  837. return Money; // Return the money that was returned by the external function
  838. }
  839.  
  840. // This function is used to set the player's money
  841. INT_GivePlayerMoney(playerid, Money)
  842. {
  843. // Setup local variables
  844. new Success;
  845.  
  846. // Try to call the external function to get the player's money (used to get the serversided money for this player)
  847. Success = CallRemoteFunction("Admin_GivePlayerMoney", "ii", playerid, Money);
  848.  
  849. // The external function returned "0" as the function is not used in another script
  850. if (Success == 0)
  851. GivePlayerMoney(playerid, Money); // Use the normal money (client-sided money)
  852. }
  853.  
  854. // This function checks if the admin-level of a player is sufficient
  855. INT_CheckPlayerAdminLevel(playerid, AdminLevel)
  856. {
  857. // Setup local variables
  858. new Level;
  859.  
  860. // Check if the player is an RCON admin
  861. if (IsPlayerAdmin(playerid))
  862. return 1; // Return 1 to indicate this player has a sufficient admin-level to use a command
  863.  
  864. // If the player is not an RCON admin, try to get his admin-level from an external script using a remote function
  865. Level = CallRemoteFunction("Admin_GetPlayerAdminLevel", "i", playerid);
  866. // Check if the player has a sufficient admin-level
  867. if (Level >= AdminLevel)
  868. return 1; // Return 1 to indicate this player has a sufficient admin-level
  869. else
  870. return 0; // Return 0 to indicate this player has an insufficient admin-level
  871. }
  872.  
  873. // This function checks if the player has logged in properly by entering his password
  874. INT_IsPlayerLoggedIn(playerid)
  875. {
  876. // Setup local variables
  877. new LoggedIn;
  878.  
  879. // Try to determine if the player logged in properly by entering his password in another script
  880. LoggedIn = CallRemoteFunction("Admin_IsPlayerLoggedIn", "i", playerid);
  881.  
  882. // Check if the player has logged in properly
  883. switch (LoggedIn)
  884. {
  885. case 0: return 1; // No admin script present that holds the LoggedIn status of a player, so allow a command to be used
  886. case 1: return 1; // The player logged in properly by entering his password, allow commands to be used
  887. case -1: return 0; // There is an admin script present, but the player hasn't entered his password yet, so block all commands
  888. // This prevents executing the commands using F6 during login with an admin-account before entering a password
  889. }
  890.  
  891. // In any other case, block all commands
  892. return 0;
  893. }
  894.  
  895.  
  896.  
  897. // ******************************************************************************************************************************
  898. // External functions to be used from within other filterscripts or gamemode (these aren't called anywhere inside this script)
  899. // These functions can be called from other filterscripts or the gamemode to get data from the speedometer filterscript
  900. // ******************************************************************************************************************************
  901.  
  902. // This function can be used to get the fuel-status from the given vehicle
  903. forward Speedo_GetVehicleFuel(vehicleid);
  904. public Speedo_GetVehicleFuel(vehicleid)
  905. {
  906. return AVehicleData[vehicleid][Fuel];
  907. }
  908.  
  909. // This function can be used to set the fuel-status for the given vehicle
  910. forward Speedo_SetVehicleFuel(vehicleid, fuel);
  911. public Speedo_SetVehicleFuel(vehicleid, fuel)
  912. {
  913. // If a fuel-value of -1 is used, this will refuel the vehicle to maximum fuel
  914. if (fuel == -1)
  915. {
  916. AVehicleData[vehicleid][Fuel] = MaxFuel; // Set fuel to maximum
  917. return 1; // Return 1 (this can be used in the other script to check if the function was called successfully)
  918. }
  919.  
  920. // Fuel cannot be negative (other negative values are ignored)
  921. if (fuel >= 0)
  922. {
  923. // Check if the fuel is within normal limits
  924. if (fuel > MaxFuel)
  925. AVehicleData[vehicleid][Fuel] = MaxFuel; // If a higher value was given than allowed (higher than MaxFuel), set fuel to maximum
  926. else
  927. AVehicleData[vehicleid][Fuel] = fuel; // Set the fuel to the given value
  928. }
  929. else
  930. return -1; // Return -1 (this can be used in the other script to check if the function was called successfully,
  931. // but the fuel-value was not acceptable)
  932.  
  933. // Return 1 (this can be used in the other script to check if the function was called successfully)
  934. return 1;
  935. }
  936.  
  937. // This function can be used to get the player's speed (returns 0 if the player is not inside a vehicle)
  938. forward Speedo_GetPlayerSpeed(playerid);
  939. public Speedo_GetPlayerSpeed(playerid)
  940. {
  941. return APlayerData[playerid][PlayerSpeed];
  942. }
  943.  
  944.  
  945.  
  946. // ******************************************************************************************************************************
  947. // Functions that need to be placed in the gamemode or filterscript which holds the playerdata
  948. // Only needed when the server uses server-sided money, otherwise the normal money is used
  949. // ******************************************************************************************************************************
  950.  
  951. /*
  952. // This function is used to get the player's money
  953. forward Admin_GetPlayerMoney(playerid);
  954. public Admin_GetPlayerMoney(playerid)
  955. {
  956. return APlayerData[playerid][PlayerMoney];
  957. }
  958.  
  959. // This function is used to get the player's money
  960. forward Admin_GivePlayerMoney(playerid, Money);
  961. public Admin_GivePlayerMoney(playerid, Money)
  962. {
  963. // Add the given money to the player's account
  964. APlayerData[playerid][PlayerMoney] = APlayerData[playerid][PlayerMoney] + Money;
  965.  
  966. // Return that the function had success (another script holds the player's money on the server-side)
  967. return 1;
  968. }
  969.  
  970. // This function is used to get the player's admin-level
  971. forward Admin_GetPlayerAdminLevel(playerid);
  972. public Admin_GetPlayerAdminLevel(playerid)
  973. {
  974. return APlayerData[playerid][AdminLevel];
  975. }
  976.  
  977. // This function is used to determine if the player has logged in (he succesfully entered his password)
  978. forward Admin_IsPlayerLoggedIn(playerid);
  979. public Admin_IsPlayerLoggedIn(playerid)
  980. {
  981. if (APlayerData[playerid][LoggedIn] == true)
  982. return 1; // The player has logged in succesfully
  983. else
  984. return -1; // The player hasn't logged in (yet)
  985. }
  986. */
Advertisement
Add Comment
Please, Sign In to add comment