forked from overextended/ox_fuel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Prepare config and fuel sync interval
- Loading branch information
1 parent
c4e955a
commit e1081ee
Showing
7 changed files
with
132 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
# ox_fuel | ||
# ox_fuel (WIP) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |