Skip to content

Commit

Permalink
feat: Prepare config and fuel sync interval
Browse files Browse the repository at this point in the history
  • Loading branch information
dunak-debug committed Jan 15, 2022
1 parent c4e955a commit e1081ee
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 1 deletion.
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
trim_trailing_whitespace = true
indent_size = 2
indent_style = space

[*.lua]
indent_size = 4
indent_style = tab
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# ox_fuel
# ox_fuel (WIP)
28 changes: 28 additions & 0 deletions client.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
if ox.showBlips == 1 then
-- DISTANCE BLIPS
elseif ox.showBlips == 2 then
-- CREATE BLIPS
end

-- Synchronize fuel
SetInterval(function()
local ped = PlayerPedId()
local vehicle = GetVehiclePedIsIn(ped, false)

if vehicle == 0 or GetPedInVehicleSeat(vehicle, -1) ~= ped or not GetIsVehicleEngineRunning(vehicle) then
return
end

local usage = ox.rpmUsage[math.floor(GetVehicleCurrentRpm(vehicle) * 10) / 10]
local multiplier = ox.classUsage[GetVehicleClass(vehicle)] or 1.0

local Vehicle = Entity(vehicle).state
local fuel = Vehicle.fuel

local newFuel = fuel and fuel - usage * multiplier or GetVehicleFuelLevel(vehicle)

if newFuel < 0 or newFuel > 100 then return end

SetVehicleFuelLevel(vehicle, newFuel)
Vehicle:set('fuel', newFuel, true)
end, 1000)
38 changes: 38 additions & 0 deletions config.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
ox = {
-- Enable support for ox_inventory
inventory = false,

/*
* Show or hide gas stations blips
* 0 - Hide all
* 1 - Show nearest
* 2 - Show all
*/
showBlips = 0,

-- What keys to disable while fueling
disabledKeys = { 0, 22, 23, 24, 29, 30, 31, 37, 44, 56, 82, 140, 166, 167, 168, 170, 288, 289, 311, 323 },

-- Fuel cost
refillCost = 100,

-- Fuel usage multiplier based on class (default 1.0)
classUsage = {
[13] = 0.0, -- Cycles
},

-- Fuel usage per second based on vehicle RPM
rpmUsage = {
[1.0] = 0.14,
[0.9] = 0.12,
[0.8] = 0.10,
[0.7] = 0.09,
[0.6] = 0.08,
[0.5] = 0.07,
[0.4] = 0.05,
[0.3] = 0.04,
[0.2] = 0.02,
[0.1] = 0.01,
[0.0] = 0.00,
}
}
Empty file added data/stations.lua
Empty file.
27 changes: 27 additions & 0 deletions fxmanifest.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--[[ FX Information ]]--
fx_version 'cerulean'
use_fxv2_oal 'yes'
lua54 'yes'
game 'gta5'

--[[ Resource Information ]]--
name 'ox_fuel'
author 'Overextended'
version '1.0.0'
repository 'https://github.com/overextended/ox_fuel'
description 'Fuel management system with ox_inventory support'

--[[ Manifest ]]--
dependencies {
'pe-lualib'
}

shared_scripts {
'config.lua'
}

client_scripts {
'@pe-lualib/init.lua',
'data/stations.lua',
'client.lua'
}
22 changes: 22 additions & 0 deletions server.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
if ox.inventory then
local ox_inventory = exports.ox_inventory

RegisterNetEvent('ox_fuel:pay', function(price)
assert(type(price) == 'number', ('Price expected a number, received %s'):format(type(price)))

local money = ox_inventory:GetItem(source, 'money', false, true)

if money < price then
return TriggerClientEvent('ox_inventory:notify', source, {
type = 'error',
text = ('Not enough money! Missing %s'):format(price)
})
end

ox_inventory:RemoveItem(source, 'money', price)
TriggerClientEvent('ox_inventory:notify', source, {
type = 'success',
text = ('Paid %s'):format(price)
})
end)
end

0 comments on commit e1081ee

Please sign in to comment.