Advertisement
Guest User

Fuelscript V0.5 edited by FaztSquirrel

a guest
May 9th, 2015
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.52 KB | None | 0 0
  1. -- Fuel Script V 0.5 by Sakis25 edited by FaztSquirrel
  2. -- http://sakis25games.blogspot.com
  3.  
  4. -- Configuration:
  5. -- x,y of gas bar
  6. local gasx = 0.01
  7. local gasy = 0.8
  8.  
  9. -- width, height of gas bar
  10. local gasw = 0.3
  11. local gash = 0.009
  12.  
  13. -- refuel key
  14. local refuelKey = Keys.L
  15.  
  16. ---------------------------------------
  17.  --     DO NOT EDIT BEYOND HERE     --
  18. ---------------------------------------
  19.  -- Cause this is no hello world... --
  20. ---------------------------------------
  21.  
  22. local GUI = {}
  23. GUI.GUI = {}
  24. GUI.time = 0
  25.  
  26. local gasStations = {{-735, -945, 30},{-85, -1767, 30},{250, -1275, 30},{732, -1037, 30},{-2110, -333, 30},
  27. {1212, 2657, 30},{2677, 3257, 30},{-2566, 2319, 30},{164, 6591, 30},{2575, 359, 30},
  28. {1702, 6418, 30},{-1803, 803, 30},{-95, 6415, 30},{264, 2609, 30},{50, 2776, 30},
  29. {2537, 2593, 30},{1179, -333, 30},{-526, -1203, 30},{1205, -1397, 30},{2004, 3771, 30},
  30. {620, 270, 30},{-1430, -275, 30},{1686, 4930, 30}}
  31.  
  32. local refillCar = false
  33. local lowFuel = false
  34. local drawHint = false
  35. local drawHintB = false
  36. local blip = {}
  37. local cars = {}
  38.  
  39. function GUI.unload()
  40.     for i, coords in pairs(gasStations) do
  41.         UI.REMOVE_BLIP(blip[i])
  42.     end
  43. end
  44.  
  45. function GUI.init()
  46.   GUI.time = GAMEPLAY.GET_GAME_TIMER()
  47.  
  48.     for i, coords in pairs(gasStations) do
  49.         blip[i] = UI.ADD_BLIP_FOR_COORD(coords[1],coords[2],coords[3])
  50.         UI.SET_BLIP_SPRITE(blip[i], 361)
  51.         UI.SET_BLIP_AS_SHORT_RANGE(blip[i], true)
  52.     end
  53. end
  54.  
  55. function GUI.tick()
  56.     local playerPed = PLAYER.PLAYER_PED_ID()
  57.     local player = PLAYER.GET_PLAYER_PED(playerPed)
  58.     local playerExists = ENTITY.DOES_ENTITY_EXIST(playerPed)
  59.     local playerPosition = ENTITY.GET_ENTITY_COORDS(PLAYER.PLAYER_PED_ID(), false)
  60.  
  61.     if( playerExists ) then
  62.         --refill with jerry can
  63.         if( GAMEPLAY.GET_HASH_KEY(WEAPON.GET_SELECTED_PED_WEAPON(playerPed)) == 2821749192 ) then -- 2821749192 = jerrycan
  64.             for key, value in pairs(cars) do
  65.                 if( ENTITY.DOES_ENTITY_EXIST(value.pointer) and value.fuel < 0.14 ) then
  66.                     local coords = ENTITY.GET_ENTITY_COORDS( value.pointer, nil )
  67.                     local coords2 = ENTITY.GET_ENTITY_COORDS( playerPed, nil )
  68.                     if( GAMEPLAY.GET_DISTANCE_BETWEEN_COORDS( coords.x, coords.y, coords.z, coords2.x, coords2.y, coords2.z, false ) < 3 ) then
  69.                         local ammo = WEAPON.GET_AMMO_IN_PED_WEAPON( playerPed, WEAPON.GET_SELECTED_PED_WEAPON(playerPed) )
  70.                         drawHintB = false
  71.                         drawHint = true
  72.                         GUI.drawText()
  73.             GUI.renderGUI()
  74.                         if( get_key_pressed(refuelKey) and ammo > 0 ) then
  75.                             value.fuel = value.fuel + 0.0005
  76.                             WEAPON.SET_PED_AMMO( playerPed, WEAPON.GET_SELECTED_PED_WEAPON(playerPed), ammo-9 )
  77.                         end
  78.                     else
  79.                         drawHint = false
  80.                     end
  81.                 end
  82.             end
  83.         end
  84.  
  85.         --ENTERED CAR
  86.         if( PED.IS_PED_IN_ANY_VEHICLE( playerPed, false ) ) then
  87.             local veh = PED.GET_VEHICLE_PED_IS_IN( playerPed,true )
  88.             local carspeed = ENTITY.GET_ENTITY_SPEED( veh )
  89.  
  90.       -- If vehicle has changed
  91.       if not cars[1] or cars[1].pointer ~= veh then
  92.         local found = false
  93.         local emptyfound = false
  94.  
  95.         -- Check if current vehicle is used before
  96.         for key, value in pairs(cars) do
  97.           if value.pointer == veh then
  98.             -- Has been in this car before
  99.             found = true
  100.             local temp = table.remove(cars, key)
  101.             table.insert(cars, temp)
  102.             break
  103.           else
  104.             -- Check if vehicle still exists, if not then make a possible value if there is no other one (really sloppy)
  105.             if not ENTITY.DOES_ENTITY_EXIST(value.pointer) then
  106.               value = {veh, fuel=math.random(6,12)/100}
  107.               emptyfound = true
  108.             end
  109.           end
  110.         end
  111.  
  112.         if ( not found ) then
  113.           -- There is a possible value from earlier
  114.           if ( emptyfound ) then
  115.             for key, value in pairs(cars) do
  116.               if not ENTITY.DOES_ENTITY_EXIST(value.pointer) then
  117.                 table.remove(cars, key)
  118.               end
  119.             end
  120.           else
  121.             -- Remove cars if we are over the 10 cars limit
  122.             if ( #cars > 10 ) then
  123.               table.remove(cars, 1)
  124.             end
  125.           end
  126.  
  127.           -- Insert current car at pos #1
  128.           table.insert(cars, 1, {pointer=veh, fuel=math.random(6,12)/100})
  129.         end
  130.       end
  131.  
  132.       -- Does vehicle use fuel?
  133.             if (VEHICLE.IS_THIS_MODEL_A_CAR(ENTITY.GET_ENTITY_MODEL(veh)) or VEHICLE.IS_THIS_MODEL_A_BIKE(ENTITY.GET_ENTITY_MODEL(veh)) or VEHICLE.IS_THIS_MODEL_A_QUADBIKE(ENTITY.GET_ENTITY_MODEL(veh))) then
  134.         -- Fuel usage
  135.                 if((GAMEPLAY.GET_GAME_TIMER() - GUI.time)> 200) then
  136.                     if(cars[1].fuel > 0 and cars[1].pointer) then
  137.             local carHealth = VEHICLE.GET_VEHICLE_ENGINE_HEALTH(cars[1].pointer) -- 1000 = max
  138.                         cars[1].fuel = cars[1].fuel - ((carspeed/450000.0) * (900.0/carHealth))
  139.                         GUI.time = GAMEPLAY.GET_GAME_TIMER()
  140.                     else
  141.                         cars[1].fuel = 0
  142.                     end
  143.                 end
  144.  
  145.                 GUI.renderGUI()
  146.  
  147.         -- Has used his horn to refuel
  148.                 if (refillCar==true) then
  149.                     if (cars[1].fuel < 0.14) then
  150.                         cars[1].fuel = cars[1].fuel + 0.001
  151.                         VEHICLE.SET_VEHICLE_ENGINE_ON(veh, false,true)
  152.                     else
  153.                         refillCar=false
  154.                         cars[1].fuel = 0.14
  155.                         VEHICLE.SET_VEHICLE_ENGINE_ON(veh, true,true)
  156.                     end
  157.                 end
  158.  
  159.                 -- OUT OF GAS
  160.                 if (cars[1].fuel == 0) then
  161.                     VEHICLE.SET_VEHICLE_ENGINE_ON(veh, false, true)
  162.                 end
  163.  
  164.                 --sound horn to refill gas
  165.                 if (carspeed < 1 and refillCar == false) then
  166.                     local coords = ENTITY.GET_ENTITY_COORDS(playerPed, nil);
  167.                     for i, current in pairs(gasStations) do
  168.                         if(GAMEPLAY.GET_DISTANCE_BETWEEN_COORDS(coords.x,coords.y,coords.z,current[1],current[2],coords.z,false) < 12 and drawHintB==false) then
  169.                             --you are close show hint
  170.                             drawHint = false
  171.                             drawHintB = true
  172.                             GUI.drawText()
  173.  
  174.                             if (cars[1].fuel < 0.14 and drawHintB==true) and get_key_pressed(refuelKey) then
  175.                                 refillCar = get_key_pressed(refuelKey)
  176.                             else
  177.                                 if (drawHintB==true) then
  178.                                     drawHintB = false
  179.                                 end
  180.                             end
  181.                             break
  182.                         else
  183.                             --you are far hide hint
  184.                             if (drawHintB==true) then
  185.                                 drawHintB = false
  186.                             end
  187.                         end
  188.                     end
  189.                 end
  190.             end
  191.         else
  192.             --EXIT CAR
  193.             lowFuel=false
  194.             drawHintB = false
  195.             refillCar=false
  196.         end
  197.     end
  198. end
  199.  
  200. function GUI.drawText()
  201.     if(drawHint) then
  202.         UI.SET_TEXT_FONT(0)
  203.         UI.SET_TEXT_PROPORTIONAL(1)
  204.         UI.SET_TEXT_SCALE(0.0, 0.35)
  205.         UI.SET_TEXT_COLOUR(255, 255, 255, 255)
  206.         UI.SET_TEXT_DROPSHADOW(0, 0, 0, 0,255)
  207.         UI.SET_TEXT_EDGE(1, 0, 0, 0, 255)
  208.         UI.SET_TEXT_DROP_SHADOW()
  209.         UI.SET_TEXT_OUTLINE()
  210.         UI._SET_TEXT_ENTRY("STRING")
  211.         UI._ADD_TEXT_COMPONENT_STRING("Hold L (default) to refuel your vehicle.")
  212.         UI._DRAW_TEXT(0.015, 0.015)
  213.     elseif(drawHintB) then
  214.         UI.SET_TEXT_FONT(0)
  215.         UI.SET_TEXT_PROPORTIONAL(1)
  216.         UI.SET_TEXT_SCALE(0.0, 0.35)
  217.         UI.SET_TEXT_COLOUR(255, 255, 255, 255)
  218.         UI.SET_TEXT_DROPSHADOW(0, 0, 0, 0,255)
  219.         UI.SET_TEXT_EDGE(1, 0, 0, 0, 255)
  220.         UI.SET_TEXT_DROP_SHADOW()
  221.         UI.SET_TEXT_OUTLINE()
  222.         UI._SET_TEXT_ENTRY("STRING")
  223.         UI._ADD_TEXT_COMPONENT_STRING("Press L (default) to refuel your vehicle.")
  224.         UI._DRAW_TEXT(0.015, 0.015)
  225.     end
  226. end
  227.  
  228. function GUI.renderGUI()
  229.     GRAPHICS.DRAW_RECT(gasx+0.07, gasy, 0.14, gash, 0, 0, 0, 60)
  230.  
  231.     if (cars[1].fuel<0.026) then
  232.         GRAPHICS.DRAW_RECT(gasx+(cars[1].fuel/2), gasy, cars[1].fuel, gash, 220, 20, 20, 255)
  233.         lowFuel=true
  234.     else
  235.         GRAPHICS.DRAW_RECT(gasx+(cars[1].fuel/2), gasy, cars[1].fuel, gash, 156, 181, 42, 255)
  236.         lowFuel=false
  237.     end
  238. end
  239.  
  240. return GUI
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement