Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Fuel Script V 0.5 by Sakis25 edited by FaztSquirrel
- -- http://sakis25games.blogspot.com
- -- Configuration:
- -- x,y of gas bar
- local gasx = 0.01
- local gasy = 0.8
- -- width, height of gas bar
- local gasw = 0.3
- local gash = 0.009
- -- refuel key
- local refuelKey = Keys.L
- ---------------------------------------
- -- DO NOT EDIT BEYOND HERE --
- ---------------------------------------
- -- Cause this is no hello world... --
- ---------------------------------------
- local GUI = {}
- GUI.GUI = {}
- GUI.time = 0
- local gasStations = {{-735, -945, 30},{-85, -1767, 30},{250, -1275, 30},{732, -1037, 30},{-2110, -333, 30},
- {1212, 2657, 30},{2677, 3257, 30},{-2566, 2319, 30},{164, 6591, 30},{2575, 359, 30},
- {1702, 6418, 30},{-1803, 803, 30},{-95, 6415, 30},{264, 2609, 30},{50, 2776, 30},
- {2537, 2593, 30},{1179, -333, 30},{-526, -1203, 30},{1205, -1397, 30},{2004, 3771, 30},
- {620, 270, 30},{-1430, -275, 30},{1686, 4930, 30}}
- local refillCar = false
- local lowFuel = false
- local drawHint = false
- local drawHintB = false
- local blip = {}
- local cars = {}
- function GUI.unload()
- for i, coords in pairs(gasStations) do
- UI.REMOVE_BLIP(blip[i])
- end
- end
- function GUI.init()
- GUI.time = GAMEPLAY.GET_GAME_TIMER()
- for i, coords in pairs(gasStations) do
- blip[i] = UI.ADD_BLIP_FOR_COORD(coords[1],coords[2],coords[3])
- UI.SET_BLIP_SPRITE(blip[i], 361)
- UI.SET_BLIP_AS_SHORT_RANGE(blip[i], true)
- end
- end
- function GUI.tick()
- local playerPed = PLAYER.PLAYER_PED_ID()
- local player = PLAYER.GET_PLAYER_PED(playerPed)
- local playerExists = ENTITY.DOES_ENTITY_EXIST(playerPed)
- local playerPosition = ENTITY.GET_ENTITY_COORDS(PLAYER.PLAYER_PED_ID(), false)
- if( playerExists ) then
- --refill with jerry can
- if( GAMEPLAY.GET_HASH_KEY(WEAPON.GET_SELECTED_PED_WEAPON(playerPed)) == 2821749192 ) then -- 2821749192 = jerrycan
- for key, value in pairs(cars) do
- if( ENTITY.DOES_ENTITY_EXIST(value.pointer) and value.fuel < 0.14 ) then
- local coords = ENTITY.GET_ENTITY_COORDS( value.pointer, nil )
- local coords2 = ENTITY.GET_ENTITY_COORDS( playerPed, nil )
- if( GAMEPLAY.GET_DISTANCE_BETWEEN_COORDS( coords.x, coords.y, coords.z, coords2.x, coords2.y, coords2.z, false ) < 3 ) then
- local ammo = WEAPON.GET_AMMO_IN_PED_WEAPON( playerPed, WEAPON.GET_SELECTED_PED_WEAPON(playerPed) )
- drawHintB = false
- drawHint = true
- GUI.drawText()
- GUI.renderGUI()
- if( get_key_pressed(refuelKey) and ammo > 0 ) then
- value.fuel = value.fuel + 0.0005
- WEAPON.SET_PED_AMMO( playerPed, WEAPON.GET_SELECTED_PED_WEAPON(playerPed), ammo-9 )
- end
- else
- drawHint = false
- end
- end
- end
- end
- --ENTERED CAR
- if( PED.IS_PED_IN_ANY_VEHICLE( playerPed, false ) ) then
- local veh = PED.GET_VEHICLE_PED_IS_IN( playerPed,true )
- local carspeed = ENTITY.GET_ENTITY_SPEED( veh )
- -- If vehicle has changed
- if not cars[1] or cars[1].pointer ~= veh then
- local found = false
- local emptyfound = false
- -- Check if current vehicle is used before
- for key, value in pairs(cars) do
- if value.pointer == veh then
- -- Has been in this car before
- found = true
- local temp = table.remove(cars, key)
- table.insert(cars, 1, temp)
- break
- else
- -- Check if vehicle still exists, if not then make a possible value if there is no other one (really sloppy)
- if not ENTITY.DOES_ENTITY_EXIST(value.pointer) then
- value = {veh, fuel=math.random(6,12)/100}
- emptyfound = true
- end
- end
- end
- if ( not found ) then
- -- There is a possible value from earlier
- if ( emptyfound ) then
- for key, value in pairs(cars) do
- if not ENTITY.DOES_ENTITY_EXIST(value.pointer) then
- table.remove(cars, key)
- end
- end
- else
- -- Remove cars if we are over the 10 cars limit
- if ( #cars > 10 ) then
- table.remove(cars, 1)
- end
- end
- -- Insert current car at pos #1
- table.insert(cars, 1, {pointer=veh, fuel=math.random(6,12)/100})
- end
- end
- -- Does vehicle use fuel?
- 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
- -- Fuel usage
- if((GAMEPLAY.GET_GAME_TIMER() - GUI.time)> 200) then
- if(cars[1].fuel > 0 and cars[1].pointer) then
- local carHealth = VEHICLE.GET_VEHICLE_ENGINE_HEALTH(cars[1].pointer) -- 1000 = max
- cars[1].fuel = cars[1].fuel - ((carspeed/450000.0) * (900.0/carHealth))
- GUI.time = GAMEPLAY.GET_GAME_TIMER()
- else
- cars[1].fuel = 0
- end
- end
- GUI.renderGUI()
- -- Has used his horn to refuel
- if (refillCar==true) then
- if (cars[1].fuel < 0.14) then
- cars[1].fuel = cars[1].fuel + 0.001
- VEHICLE.SET_VEHICLE_ENGINE_ON(veh, false,true)
- else
- refillCar=false
- cars[1].fuel = 0.14
- VEHICLE.SET_VEHICLE_ENGINE_ON(veh, true,true)
- end
- end
- -- OUT OF GAS
- if (cars[1].fuel == 0) then
- VEHICLE.SET_VEHICLE_ENGINE_ON(veh, false, true)
- end
- --sound horn to refill gas
- if (carspeed < 1 and refillCar == false) then
- local coords = ENTITY.GET_ENTITY_COORDS(playerPed, nil);
- for i, current in pairs(gasStations) do
- if(GAMEPLAY.GET_DISTANCE_BETWEEN_COORDS(coords.x,coords.y,coords.z,current[1],current[2],coords.z,false) < 12 and drawHintB==false) then
- --you are close show hint
- drawHint = false
- drawHintB = true
- GUI.drawText()
- if (cars[1].fuel < 0.14 and drawHintB==true) and get_key_pressed(refuelKey) then
- refillCar = get_key_pressed(refuelKey)
- else
- if (drawHintB==true) then
- drawHintB = false
- end
- end
- break
- else
- --you are far hide hint
- if (drawHintB==true) then
- drawHintB = false
- end
- end
- end
- end
- end
- else
- --EXIT CAR
- lowFuel=false
- drawHintB = false
- refillCar=false
- end
- end
- end
- function GUI.drawText()
- if(drawHint) then
- UI.SET_TEXT_FONT(0)
- UI.SET_TEXT_PROPORTIONAL(1)
- UI.SET_TEXT_SCALE(0.0, 0.35)
- UI.SET_TEXT_COLOUR(255, 255, 255, 255)
- UI.SET_TEXT_DROPSHADOW(0, 0, 0, 0,255)
- UI.SET_TEXT_EDGE(1, 0, 0, 0, 255)
- UI.SET_TEXT_DROP_SHADOW()
- UI.SET_TEXT_OUTLINE()
- UI._SET_TEXT_ENTRY("STRING")
- UI._ADD_TEXT_COMPONENT_STRING("Hold L (default) to refuel your vehicle.")
- UI._DRAW_TEXT(0.015, 0.015)
- elseif(drawHintB) then
- UI.SET_TEXT_FONT(0)
- UI.SET_TEXT_PROPORTIONAL(1)
- UI.SET_TEXT_SCALE(0.0, 0.35)
- UI.SET_TEXT_COLOUR(255, 255, 255, 255)
- UI.SET_TEXT_DROPSHADOW(0, 0, 0, 0,255)
- UI.SET_TEXT_EDGE(1, 0, 0, 0, 255)
- UI.SET_TEXT_DROP_SHADOW()
- UI.SET_TEXT_OUTLINE()
- UI._SET_TEXT_ENTRY("STRING")
- UI._ADD_TEXT_COMPONENT_STRING("Press L (default) to refuel your vehicle.")
- UI._DRAW_TEXT(0.015, 0.015)
- end
- end
- function GUI.renderGUI()
- GRAPHICS.DRAW_RECT(gasx+0.07, gasy, 0.14, gash, 0, 0, 0, 60)
- if (cars[1].fuel<0.026) then
- GRAPHICS.DRAW_RECT(gasx+(cars[1].fuel/2), gasy, cars[1].fuel, gash, 220, 20, 20, 255)
- lowFuel=true
- else
- GRAPHICS.DRAW_RECT(gasx+(cars[1].fuel/2), gasy, cars[1].fuel, gash, 156, 181, 42, 255)
- lowFuel=false
- end
- end
- return GUI
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement