A highly in-depth fuel system for FiveM with support for the QBCore Framework & QBox Remastered.
Fixes:
Make sure you have the following dependencies, otherwise, issues most likely will arise:
Here, we shall provide a step-by-step guide on installing cdn-fuel to your server and making it work with other scripts you may already have installed.
First, we will start by renaming the resource "cdn-fuel-main" to just "cdn-fuel".
Next, we will drag the "cdn-fuel" resource into your desired folder in your servers resources directory.
Next, we're going to drag the sounds from the cdn-fuel/assets/sounds folder in cdn-fuel, into your interact-sounds folder located at resources/[standalone]/interact-sound/client/html/sounds
Next, we're going to open our entire resources folder in whichever IDE you use, (we will be using Visual Studio Code for this example) and replace all of your current exports titled "LegacyFuel", "ps-fuel" or "lj-fuel", with "cdn-fuel". Then you want to ensure cdn-fuel in your server's config file.
Next, we're going to run our SQL file, which is needed if we want to use the Player Owned Gas Stations, otherwise you do not have to run it.
The file you need to run is located @ cdn-fuel/assets/sql/cdn-fuel.sql
Here is a GIF to run you through the process of running an SQL file:
It is highly recommended, if you plan on restarting the script at all, that you move the stream folder & _datafile paramaters found in the fxmanifest.lua to another resource for the time being. If you do not do this, you & anyone in the server's game will most likely crash when restarting cdn-fuel. The process is very simple & it is outlined in the GIF & Instructions below.
Firstly, we will move our stream folder to our new resource, or existing resource.
In this example, I have a dummy resource named cdn-fool.
Next, we will move our fxmanifest.lua's entries for _datafile into our new resource, and REMOVE IT from cdn-fuel.
data_file 'DLC_ITYP_REQUEST' 'stream/[electric_nozzle]/electric_nozzle_typ.ytyp'
data_file 'DLC_ITYP_REQUEST' 'stream/[electric_charger]/electric_charger_typ.ytyp'
Make sure to ensure this new resource as well as cdn-fuel in your server.cfg!
If you do not want the Jerry Can or Syphoning Kit items, you are now finished with installation.
Otherwise, navigate to Step 6 & Step 7 below, and finish installation.
If you are using OX_Inventory, this step can be ignored.
We will now be installing the Jerry Can & Syphoning Kit items into your server. You don't have to install either, but they are recommended additions. You can install them & disable them in the config, until you want to use them later on!
If you plan to not use them, you can skip this Step and Step 7!
The first step of installing our items is to navigate to your qb-core/shared/items.lua.
Once there, we will paste the following items at the bottom of our items table.
["syphoningkit"] = {["name"] = "syphoningkit", ["label"] = "Syphoning Kit", ["weight"] = 5000, ["type"] = "item", ["image"] = "syphoningkit.png", ["unique"] = true, ["useable"] = true, ["shouldClose"] = false, ["combinable"] = nil, ["description"] = "A kit made to siphon gasoline from vehicles."},
["jerrycan"] = {["name"] = "jerrycan", ["label"] = "Jerry Can", ["weight"] = 15000, ["type"] = "item", ["image"] = "jerrycan.png", ["unique"] = true, ["useable"] = true, ["shouldClose"] = false, ["combinable"] = nil, ["description"] = "A Jerry Can made to hold gasoline."},
For people using inventories with built-in decay, you must add those onto the item, as it doesn't come with it!
You can follow this GIF to better understand how to install the items:
Now, we need to format item data in our inventory. Firstly, find the app.js located at inventoryname/html/js/app.js.
Now we will CTRL+F the following line:
} else if (itemData.name == "harness") {
Once you have found this line, copy the following one line above it:
} else if (itemData.name == "syphoningkit") { // Syphoning Kit (CDN-Fuel or CDN-Syphoning!)
$(".item-info-title").html("<p>" + itemData.label + "</p>");
$(".item-info-description").html(
"<p>" + "A kit used to syphon gasoline from vehicles! <br><br>" + itemData.info.gasamount + " Liters Inside.</p>" +
"</span></p><p style=\"padding-top: .8vh;font-size:11px\"><b>Weight: </b>" + ((itemData.weight * itemData.amount) / 1000).toFixed(1) + " | <b>Amount: </b> " + itemData.amount
);
} else if (itemData.name == "jerrycan") { // Jerry Can (CDN-Fuel!)
$(".item-info-title").html("<p>" + itemData.label + "</p>");
$(".item-info-description").html(
"<p>" + "A Jerry Can, designed to hold fuel! <br><br>" + itemData.info.gasamount + " Liters Inside.</p>" +
"</span></p><p style=\"padding-top: .8vh;font-size:11px\"><b>Weight: </b>" + ((itemData.weight * itemData.amount) / 1000).toFixed(1) + " | <b>Amount: </b> " + itemData.amount
);
Again, if you have decay, you must add in the options yourself!
Here is a GIF to better understand how to install the "jerrycan" and "syphoningkit" in the app.js
Next, we'll add the item's images into our Inventory resource. This is a simple process.
Navigate to the cdn-fuel resource and follow this path: cdn-fuel/assets/images
Once there, select both images and either drag or CTRL + X and CTRL + V them into your inventory's image folder, usually the path is: inventoryname/html/images/
You can follow this GIF to get a better understanding:
This step is only necessary for you to be able to do the /giveitem command or to put items in the qb-shops.
Navigate to inventoryname/server/server.lua, and CTRL + F the following line:
elseif itemData["name"] == "harness" then
info.uses = 20
Now we will add the following above the line below:
elseif itemData["name"] == "syphoningkit" then
info.gasamount = 0
elseif itemData["name"] == "jerrycan" then
info.gasamount = 0
Alternatively, watch this GIF to better understand the process:
Here are some preconfigured shop items if you wish to put them in the shop. (The Jerry Can is buyable via the Gas Pump!)
[10] = {
name = "syphoningkit",
price = 5000,
amount = 5,
info = { gasamount = 0 }, -- This must be included or, your item will not store fuel properly!
type = "item",
slot = 10,
}, -- CDN-Fuel / CDN-Syphoning
[11] = {
name = "jerrycan",
price = 750,
amount = 5,
info = { gasamount = 0 }, -- This must be included or, your item will not store fuel properly!
type = "item",
slot = 11,
}, -- CDN-Fuel
You will most likely have to change the slot it is in for it to work properly!
There is a possible issue with qb-target if you are using the Config.GlobalVehicleOptions or Config.TargetBones options.
Here is a simple fix for that issue:
Firstly, this option will have to be added to your Config.TargetBones under the bones you are having trouble with:
{
type = "client",
event = "cdn-fuel:client:SendMenuToServer",
icon = "fas fa-gas-pump",
label = "Insert Nozzle",
canInteract = function() return Allowrefuel end
},
{
type = "client",
action = function()
TriggerEvent('cdn-fuel:client:electric:RefuelMenu')
end,
icon = "fas fa-bolt",
label = "Insert Electric Nozzle",
canInteract = function() return AllowElectricRefuel end
},
Here is an example of how to add this option:
This is specifically for the "boot" bone, but, add it on which bone you are having trouble with.
Next, we'll add this simple Function & Export into our QB-Target in the Functions() area:
local function AllowRefuel(state, electric)
if state then
if electric then
AllowElectricRefuel = true
else
Allowrefuel = true
end
else
if electric then
AllowElectricRefuel = false
else
Allowrefuel = false
end
end
end exports('AllowRefuel', AllowRefuel)
Example Image:
Lastly, add the following to the top of your init.lua in QB-Target:
local Allowrefuel = false
local AllowElectricRefuel = false
Example Image:
Now, set the Config.FuelTargetExport in cdn-fuel/shared/config.lua to true.
We highly recommend you add the following snippet to your engine toggle command. It will make it to where players cannot turn their vehicle on if they have no fuel! Seems pretty important to us!
-- FOR QB-VEHICLEKEYS, FUNCTION ToggleEngine();
local NotifyCooldown = false
function ToggleEngine(veh)
if veh then
local EngineOn = GetIsVehicleEngineRunning(veh)
if not isBlacklistedVehicle(veh) then
if HasKeys(QBCore.Functions.GetPlate(veh)) or AreKeysJobShared(veh) then
if EngineOn then
SetVehicleEngineOn(veh, false, false, true)
else
if exports['cdn-fuel']:GetFuel(veh) ~= 0 then
SetVehicleEngineOn(veh, true, false, true)
else
if not NotifyCooldown then
RequestAmbientAudioBank("DLC_PILOT_ENGINE_FAILURE_SOUNDS", 0)
PlaySoundFromEntity(l_2613, "Landing_Tone", PlayerPedId(), "DLC_PILOT_ENGINE_FAILURE_SOUNDS", 0, 0)
NotifyCooldown = true
QBCore.Functions.Notify('No fuel..', 'error')
Wait(1500)
StopSound(l_2613)
Wait(3500)
NotifyCooldown = false
end
end
end
end
end
end
end
Enjoy using cdn-fuel, if you have an issues, create an issue on the repository, and we will fix it ASAP!
Here's a couple of videos showcasing the script in action!