function ReFuel()
if GasOnline then
for i,ent in pairs (vehicle_table) do
local Vehicle = ent
if not (Vehicle and Vehicle:IsValid() and Vehicle:IsVehicle()) then return end
local ply = Vehicle:GetDriver()
if ply:IsValid() and ply:IsPlayer() then
local Fuel = Vehicle:GetNWInt("fuel")
local price = 2
local plypos = ply:GetPos()
local plyposx = math.Round(plypos.x)
local plyposy = math.Round(plypos.y)
if (plyposx <= tankx1 and plyposx >= tankx2) or (plyposx <= tankx3 and plyposx >= tankx4) then
--print("x-coordinate matches")
if (plyposy <= tanky1 and plyposy >= tanky2) or (plyposy <= tanky3 and plyposy >= tanky4) then
--print("y-coordinate matches")
if Fuel <= 0 and ply:CanAfford(3*price) then
Vehicle:Fire("turnon", 1, 0)
end
if Fuel <= 97 then
if not ply:CanAfford(3*price) then Notify(ply, 1, 4, string.format(LANGUAGE.cant_afford, "fuel")) return "" end
ply:AddMoney(-(3*price))
local newfuel = Fuel + 3
Vehicle:SetNWInt("fuel", newfuel)
elseif Fuel == 98 then
if not ply:CanAfford(2*price) then Notify(ply, 1, 4, string.format(LANGUAGE.cant_afford, "fuel")) return "" end
ply:AddMoney(-(2*price))
local newfuel = Fuel + 2
Vehicle:SetNWInt("fuel", newfuel)
elseif Fuel == 99 then
if not ply:CanAfford(price) then Notify(ply, 1, 4, string.format(LANGUAGE.cant_afford, "fuel")) return "" end
ply:AddMoney(-price)
local newfuel = Fuel + 1
Vehicle:SetNWInt("fuel", newfuel)
elseif Fuel >= 100 then
return
end
end
end
end
end
end
end
timer.Create("Vehicle_Fuel_CountUp", 3, 0, ReFuel)
function CountFuels()
if GasOnline then
for i,ent in pairs (vehicle_table) do
local conv = 10.936133
local Vehicle = ent
if not (Vehicle and Vehicle:IsValid() and Vehicle:IsVehicle()) then return end
local speed = Vehicle:GetVelocity():Length()/conv
local Fuel = Vehicle:GetNWInt("fuel")
if Fuel > 0 and Vehicle:GetDriver() then
if speed > 2 and speed < 50 then
local newfuel = Fuel - 1
Vehicle:SetNWInt("fuel", newfuel)
elseif speed > 49 then
local newfuel = Fuel - 2
Vehicle:SetNWInt("fuel", newfuel)
end
elseif Fuel < 0 then
Vehicle:SetNWInt("fuel", 0)
end
if Vehicle:GetNWInt("fuel") < 1 then
Vehicle:Fire("turnoff", 1, 0)
local Driver = Vehicle:GetDriver()
if Driver and Driver:IsValid() and Driver:IsPlayer() then
Notify(Driver, 1, 5, "This vehicle ran out of fuel!")
end
end
end
end
end
timer.Create("Vehicle_Fuel_Count", 20, 0, CountFuels)