Guest User

Untitled

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