├── .github
└── bug_reports.md
├── README.md
├── client.lua
├── client_functions.lua
├── client_interactions.lua
├── config.lua
├── fxmanifest.lua
├── images
└── fuelsiphon.png
└── server.lua
/.github/bug_reports.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug Report ID
3 | about: Create a report to help us improve or fix something
4 | title: "[BUG]"
5 | labels: bug
6 | assignees: ''
7 | ---
8 |
9 | **Describe the bug**
10 | A brief and straightforward description of the bug. A new member of the QBCore Community who is unfamiliar with QBCore should be able to read your bug report and understand how to recreate it as well as how the functionality should operate normally.
11 |
12 | **To Reproduce**
13 | Write down everything you did as clearly as possible. Make sure each step is self-contained: Anyone should be able to follow your steps, without access to private or proprietary data.
14 |
15 | **Steps to reproduce the behavior examples:**
16 | 1. Go to '...'
17 | 2. Click on '....'
18 | 3. Use this item '....' (item's name from shared.lua if applicable)
19 | 4. See error
20 |
21 | **Expected behavior:**
22 | - A straightforward and simple interpretation of what you anticipated to happen.
23 |
24 | **Result:**
25 | - A straightforward and simple interpretation of what actually happened.
26 |
27 | **Screenshots:**
28 | - If applicable, add screenshots to the bug report to help explain your problem. [e.g. F8 Console Errors / Server Errors]
29 |
30 | **Questions (please complete the following information):**
31 | - When you last updated: [e.g. last week]
32 | - Are you using another resource similar to this one? [e.g. yes/no] if so, which ones? [e.g. LegacyFuel, bt-target]
33 | - Have you renamed the script? [e.g. yes/no]
34 |
35 | **Additional context:**
36 | - Add any other context about the problem here.
37 |
38 | **CREDIT**
39 | - QBFramework For The Bug Report Template
40 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 |
3 | # CC-FUEL
4 |
5 | CC-Fuel is a Modified version of LegacyFuel for QB-Core using QB-Target for Interactions.
6 |
7 | Full credit goes to the author of LegacyFuel, I just reworked it to fit better with qb-target.
8 |
9 |
INSTALLATION GUIDE
10 |
11 | 1. Remove LegacyFuel from your [standalone] folder
12 | 2. Drop the cc-fuel folder into your [standalone] folder
13 | 3. Add fuelsiphon.png to QB-Inventory>html>images
14 | 4. Add The Following Line to QB-Core>Shared.lua
15 |
16 | ```lua
17 | -- CC-Fuel
18 | ['fuelsiphon'] = {['name'] = 'fuelsiphon', ['label'] = 'Fuel Siphon', ['weight'] = 2500, ['type'] = 'item', ['image'] = 'fuelsiphon.png', ['unique'] = false, ['useable'] = false, ['shouldClose'] = false, ['combinable'] = nil, ['description'] = 'A fuel siphon to extract fuel from vehicles'},
19 | ```
20 |
21 | 5. Add Fuel Siphon to a shop of your choice or anywhere else you want it.
22 |
23 | FEATURES
24 |
25 | - QB-Target Based Script
26 | - Can Refill At All Gas Stations
27 | - Refuel From Petrol Cans (Petrol Can Item Required On Person)
28 | - Siphon Fuel From Cars (Fuel Siphon Item Required On Person)
29 | - Added chance for car blowing Up if Engine left on while refueling
30 |
31 |
32 | NOTE
33 |
34 | **Any scripts that use the LegacyFuel export should be changed to use the cc-fuel export instead.**
35 |
36 | - exports['LegacyFuel'] --> exports['cc-fuel']
37 |
38 | To get the HUD fuel indicator working again replace the GetFuel export in qb-hud
39 |
40 | IMAGES
41 |
42 | 
43 | 
44 |
45 |
46 | **CREDIT**
47 | -----
48 | Original Repo - https://github.com/qbcore-framework/LegacyFuel
49 |
50 | **DEPENDENCIES**
51 | -----
52 |
53 | - QBCore - https://github.com/qbcore-framework
54 | - QB-Target - https://github.com/BerkieBb/qb-target
55 |
--------------------------------------------------------------------------------
/client.lua:
--------------------------------------------------------------------------------
1 | --New QBCore way of getting the Object comment out if your using old QB
2 | QBCore = exports['qb-core']:GetCoreObject()
3 | isFueling = false
4 | CurrentWeaponData = nil
5 |
6 | --Pulls Current Weapon data from qb-weapons event calls
7 | AddEventHandler("weapons:client:SetCurrentWeapon",function(weaponData,canShoot)
8 | CurrentWeaponData = weaponData
9 | end)
10 |
11 | function CheckDecor(vehicle)
12 | if not vehicle then return end
13 | if not DecorExistOn(vehicle,Config.FuelDecor) then
14 | DecorSetFloat(vehicle, Config.FuelDecor, GetFuel(vehicle))
15 | end
16 | end
17 |
18 | --Fuel siphon event
19 | RegisterNetEvent("cc-fuel:client:siphonfuel",function()
20 | local petrolCanDurability = GetCurrentGasCanDurability()
21 |
22 | local PlayerPed = PlayerPedId()
23 | local Vehicle = QBCore.Functions.GetClosestVehicle()
24 |
25 | local PlayerCoords = GetEntityCoords(PlayerPed)
26 | local vehicleCoords = GetEntityCoords(Vehicle)
27 |
28 | local distanceToVehicle = #(PlayerCoords - vehicleCoords)
29 |
30 | local petrolCanDurability = GetCurrentGasCanDurability()
31 |
32 |
33 | if distanceToVehicle > 2.5 then
34 | QBCore.Functions.Notify("You are too far away from the vehicle","error")
35 | return
36 | end
37 |
38 | --Check petrol can is able to take fuel
39 | if petrolCanDurability == nil then
40 | QBCore.Functions.Notify("You need a petrol can in your hands","error")
41 | return
42 | elseif petrolCanDurability == 100 then
43 | QBCore.Functions.Notify("You petrol can is full","error")
44 | return
45 | end
46 | local currentFuel = GetFuel(Vehicle)
47 | --Check car is able to have fuel taken
48 | if currentFuel > 0 then
49 | --Start taking the fuel
50 | TaskTurnPedToFaceEntity(PlayerPed, Vehicle, 1000)
51 | Wait(1000)
52 |
53 | LoadAnimDict("timetable@gardener@filling_can")
54 | TaskPlayAnim(ped, "timetable@gardener@filling_can", "gar_ig_5_filling_can", 2.0, 8.0, -1, 50, 0, 0, 0, 0)
55 |
56 | isFueling = true
57 | CheckDecor(Vehicle)
58 | CreateThread(function()
59 | local fuelToTake = Config.SiphonRate
60 | while isFueling do
61 | Wait(500)
62 |
63 | currentFuel = (currentFuel - fuelToTake)
64 | petrolCanDurability = (petrolCanDurability + fuelToTake)
65 |
66 | if currentFuel <= 0 then
67 | currentFuel = 0
68 | isFueling = false
69 | end
70 |
71 | --SetFuel(Vehicle, currentFuel)
72 |
73 | if petrolCanDurability >= 100 then
74 | isFueling = false
75 | end
76 |
77 | SetPetrolCanDurability(petrolCanDurability)
78 | end
79 | print(petrolCanDurability)
80 | SetFuel(Vehicle,GetFuel(Vehicle))
81 | end)
82 |
83 | while isFueling do
84 | for _, controlIndex in pairs(Config.DisableKeys) do
85 | DisableControlAction(0, controlIndex)
86 | end
87 |
88 | DrawText3Ds(vehicleCoords.x, vehicleCoords.y, vehicleCoords.z + 0.5, Config.Strings.CancelSiphoningFuel .. " | Vehicle: " .. Round(currentFuel, 1) .. "%")
89 |
90 | if not IsEntityPlayingAnim(PlayerPed, "timetable@gardener@filling_can", "gar_ig_5_filling_can", 3) then
91 | TaskPlayAnim(PlayerPed, "timetable@gardener@filling_can", "gar_ig_5_filling_can", 2.0, 8.0, -1, 50, 0, 0, 0, 0)
92 | end
93 |
94 | if IsControlJustReleased(0, 38) or DoesEntityExist(GetPedInVehicleSeat(vehicle, -1)) then
95 | isFueling = false
96 | end
97 |
98 | Wait(0)
99 | end
100 |
101 | ClearPedTasks(PlayerPed)
102 | QBCore.Functions.Notify("You siphoned fuel","success")
103 | else
104 | QBCore.Functions.Notify("The tank is empty","error")
105 | end
106 |
107 |
108 | end)
109 |
110 | --Action events
111 | RegisterNetEvent("cc-fuel:client:refillpetrolcan", function()
112 | local petrolCanDurability = GetCurrentGasCanDurability()
113 | if petrolCanDurability ~= nil then
114 | if petrolCanDurability == 100 then
115 | QBCore.Functions.Notify("Your can is full","error")
116 | else
117 | local refillCost = math.floor(100 - petrolCanDurability)
118 | if refillCost > 0 then
119 | local currentCash = QBCore.Functions.GetPlayerData().money['cash']
120 | if currentCash >= refillCost then
121 | TriggerServerEvent('cc-fuel:server:pay', refillCost, GetPlayerServerId(PlayerId()))
122 | SetPetrolCanDurability(100)
123 | QBCore.Functions.Notify("You refilled your petrol can","success")
124 | else
125 | QBCore.Functions.Notify("Not enough cash to refill the can","error")
126 | end
127 | end
128 | end
129 | else
130 | QBCore.Functions.Notify("You don't have a petrol can to refill","error")
131 | end
132 | end)
133 |
134 | RegisterNetEvent("cc-fuel:client:buypetrolcan", function()
135 | local currentCash = QBCore.Functions.GetPlayerData().money['cash']
136 | if currentCash >= Config.JerryCanCost then
137 | TriggerServerEvent('QBCore:Server:AddItem', "weapon_petrolcan", 1)
138 | TriggerEvent("inventory:client:ItemBox", QBCore.Shared.Items["weapon_petrolcan"], "add")
139 | TriggerServerEvent('cc-fuel:server:pay', Config.JerryCanCost, GetPlayerServerId(PlayerId()))
140 | QBCore.Functions.Notify("You bought a jerry can","success")
141 | else
142 | QBCore.Functions.Notify("You don't have enough money to buy a jerry can","error")
143 | end
144 | end)
145 |
146 | RegisterNetEvent("cc-fuel:client:pumprefuel", function(pump)
147 | local PlayerPed = PlayerPedId()
148 | local Vehicle = QBCore.Functions.GetClosestVehicle()
149 |
150 | --Check player is close to pump
151 | local pumpCoords = GetEntityCoords(pump)
152 | local PlayerCoords = GetEntityCoords(PlayerPed)
153 | local vehicleCoords = GetEntityCoords(Vehicle)
154 |
155 | local distanceToPump = #(PlayerCoords - pumpCoords)
156 | local distanceToVehicle = #(PlayerCoords - vehicleCoords)
157 |
158 |
159 | if distanceToVehicle > 2.5 then
160 | QBCore.Functions.Notify("You are too far away from the vehicle","error")
161 | return
162 | end
163 |
164 | --Check car is able to be fueled
165 |
166 |
167 | if CanFuelVehicle(Vehicle) then
168 | --Start the fueling
169 | TaskTurnPedToFaceEntity(PlayerPed, Vehicle, 1000)
170 | Wait(1000)
171 |
172 | LoadAnimDict("timetable@gardener@filling_can")
173 | TaskPlayAnim(ped, "timetable@gardener@filling_can", "gar_ig_5_filling_can", 2.0, 8.0, -1, 50, 0, 0, 0, 0)
174 |
175 | --Go Kaboom if the engine on
176 | if GetIsVehicleEngineRunning(Vehicle) and Config.VehicleEngineOnBlowUp then
177 | local Chance = math.random(1, 100)
178 | if Chance <= Config.VehicleBlowUpChance then
179 | AddExplosion(vehicleCoords, 5, 50.0, true, false, true)
180 | return
181 | end
182 | end
183 |
184 | isFueling = true
185 | local currentCost = 0
186 | local currentFuel = GetFuel(Vehicle)
187 | local currentCash = QBCore.Functions.GetPlayerData().money['cash']
188 |
189 | CheckDecor(Vehicle)
190 | CreateThread(function()
191 | local fuelToAdd = Config.PetrolPumpRefuelRate
192 | while isFueling do
193 | Wait(500)
194 |
195 | local extraCost = fuelToAdd / 1.5 * Config.CostMultiplier
196 |
197 | currentFuel = currentFuel + fuelToAdd
198 |
199 | if currentFuel > 100.0 then
200 | currentFuel = 100.0
201 | isFueling = false
202 | end
203 |
204 | currentCost = currentCost + extraCost
205 |
206 | if currentCash >= currentCost then
207 | SetFuel(Vehicle, currentFuel)
208 | else
209 | isFueling = false
210 | end
211 | end
212 | SetFuel(Vehicle,GetFuel(Vehicle))
213 | end)
214 |
215 | while isFueling do
216 | for _, controlIndex in pairs(Config.DisableKeys) do
217 | DisableControlAction(0, controlIndex)
218 | end
219 |
220 | local extraString = "\n" .. "Cost " .. ": ~b~$" .. Round(currentCost, 1)
221 |
222 | DrawText3Ds(pumpCoords.x, pumpCoords.y, pumpCoords.z + 1.2, Config.Strings.CancelFuelingPump .. extraString)
223 | DrawText3Ds(vehicleCoords.x, vehicleCoords.y, vehicleCoords.z + 0.5, Round(currentFuel, 1) .. "%")
224 |
225 | if not IsEntityPlayingAnim(PlayerPed, "timetable@gardener@filling_can", "gar_ig_5_filling_can", 3) then
226 | TaskPlayAnim(PlayerPed, "timetable@gardener@filling_can", "gar_ig_5_filling_can", 2.0, 8.0, -1, 50, 0, 0, 0, 0)
227 | end
228 |
229 | if IsControlJustReleased(0, 38) or DoesEntityExist(GetPedInVehicleSeat(vehicle, -1)) then
230 | isFueling = false
231 | end
232 |
233 | Wait(0)
234 | end
235 |
236 | ClearPedTasks(PlayerPed)
237 |
238 | TriggerServerEvent('cc-fuel:server:pay', currentCost, GetPlayerServerId(PlayerId()))
239 | QBCore.Functions.Notify("You paid $" .. currentCost .. " for fuel","success")
240 | else
241 | QBCore.Functions.Notify("The tank is full","error")
242 | end
243 |
244 | end)
245 |
246 | RegisterNetEvent("cc-fuel:client:petrolcanrefuel", function()
247 | local PlayerPed = PlayerPedId()
248 | local Vehicle = QBCore.Functions.GetClosestVehicle()
249 |
250 | local PlayerCoords = GetEntityCoords(PlayerPed)
251 | local vehicleCoords = GetEntityCoords(Vehicle)
252 |
253 | local distanceToVehicle = #(PlayerCoords - vehicleCoords)
254 |
255 | local petrolCanDurability = GetCurrentGasCanDurability()
256 |
257 |
258 | if distanceToVehicle > 2.5 then
259 | QBCore.Functions.Notify("You are too far away from the vehicle","error")
260 | return
261 | end
262 |
263 | --Check petrol can can fuel car
264 | if petrolCanDurability == nil then
265 | QBCore.Functions.Notify("You need a petrol can in your hands","error")
266 | return
267 | elseif petrolCanDurability <= 0 then
268 | QBCore.Functions.Notify("You petrol can is empty","error")
269 | return
270 | end
271 |
272 | --Check car is able to be fueled
273 | if CanFuelVehicle(Vehicle) then
274 | --Start the fueling
275 | TaskTurnPedToFaceEntity(PlayerPed, Vehicle, 1000)
276 | Wait(1000)
277 |
278 | LoadAnimDict("timetable@gardener@filling_can")
279 | TaskPlayAnim(ped, "timetable@gardener@filling_can", "gar_ig_5_filling_can", 2.0, 8.0, -1, 50, 0, 0, 0, 0)
280 |
281 | --Go Kaboom if the engine on
282 | if GetIsVehicleEngineRunning(Vehicle) and Config.VehicleEngineOnBlowUp then
283 | local Chance = math.random(1, 100)
284 | if Chance <= Config.VehicleBlowUpChance then
285 | AddExplosion(vehicleCoords, 5, 50.0, true, false, true)
286 | return
287 | end
288 | end
289 |
290 | isFueling = true
291 | local currentFuel = GetFuel(Vehicle)
292 | local currentCash = QBCore.Functions.GetPlayerData().money['cash']
293 |
294 | CheckDecor(Vehicle)
295 | CreateThread(function()
296 | local fuelToAdd = Config.PetrolCanRefuelRate
297 | while isFueling do
298 | Wait(500)
299 |
300 | currentFuel = currentFuel + fuelToAdd
301 | petrolCanDurability = (petrolCanDurability - fuelToAdd)
302 |
303 | if currentFuel > 100.0 then
304 | currentFuel = 100.0
305 | isFueling = false
306 | end
307 |
308 | SetFuel(Vehicle, currentFuel)
309 |
310 | if petrolCanDurability <= 0 then
311 | isFueling = false
312 | end
313 | end
314 |
315 | SetPetrolCanDurability(petrolCanDurability)
316 | SetFuel(Vehicle,GetFuel(Vehicle))
317 | end)
318 |
319 | while isFueling do
320 | for _, controlIndex in pairs(Config.DisableKeys) do
321 | DisableControlAction(0, controlIndex)
322 | end
323 |
324 | DrawText3Ds(vehicleCoords.x, vehicleCoords.y, vehicleCoords.z + 0.5, Config.Strings.CancelFuelingJerryCan .. "| Vehicle: " .. Round(currentFuel, 1) .. "%")
325 |
326 | if not IsEntityPlayingAnim(PlayerPed, "timetable@gardener@filling_can", "gar_ig_5_filling_can", 3) then
327 | TaskPlayAnim(PlayerPed, "timetable@gardener@filling_can", "gar_ig_5_filling_can", 2.0, 8.0, -1, 50, 0, 0, 0, 0)
328 | end
329 |
330 | if IsControlJustReleased(0, 38) or DoesEntityExist(GetPedInVehicleSeat(vehicle, -1)) then
331 | isFueling = false
332 | end
333 |
334 | Wait(10)
335 | end
336 |
337 | ClearPedTasks(PlayerPed)
338 | QBCore.Functions.Notify("You refueled your car","success")
339 | else
340 | QBCore.Functions.Notify("The tank is full","error")
341 | end
342 |
343 | end)
344 |
345 | --Update fuel thread
346 | CreateThread(function()
347 | DecorRegister(Config.FuelDecor, 1)
348 | for index = 1, #Config.Blacklist do
349 | if type(Config.Blacklist[index]) == 'string' then
350 | Config.Blacklist[GetHashKey(Config.Blacklist[index])] = true
351 | else
352 | Config.Blacklist[Config.Blacklist[index]] = true
353 | end
354 | end
355 |
356 | for index = #Config.Blacklist, 1, -1 do
357 | table.remove(Config.Blacklist, index)
358 | end
359 |
360 | local fuelSynced = false
361 |
362 | local inBlacklisted = false
363 | while true do
364 | Wait(1000)
365 |
366 | local ped = PlayerPedId()
367 |
368 | if IsPedInAnyVehicle(ped) then
369 | local vehicle = GetVehiclePedIsIn(ped)
370 |
371 | if Config.Blacklist[GetEntityModel(vehicle)] then
372 | inBlacklisted = true
373 | else
374 | inBlacklisted = false
375 | end
376 |
377 | if not inBlacklisted and GetPedInVehicleSeat(vehicle, -1) == ped then
378 | if not DecorExistOn(vehicle, Config.FuelDecor) then
379 | SetFuel(vehicle,math.random(200, 800) / 10)
380 | elseif IsVehicleEngineOn(vehicle) then
381 | SetFuel(vehicle, GetFuel(vehicle) - Config.FuelUsage[Round(GetVehicleCurrentRpm(vehicle), 1)] * (Config.Classes[GetVehicleClass(vehicle)] or 1.0) / 10)
382 | elseif not fuelSynced then
383 | fuelSynced = true
384 | end
385 | SetFuel(vehicle, GetFuel(vehicle))
386 | else
387 | SetFuel(vehicle,GetFuel(vehicle))
388 | end
389 | else
390 | local closestPlayer, distance = QBCore.Functions.GetClosestPlayer()
391 | local playerPed = GetPlayerPed(closestPlayer)
392 | if IsPedInAnyVehicle(playerPed) then
393 | local closestVehicle = GetVehiclePedIsIn(playerPed,false)
394 | SetFuel(closestVehicle,GetFuel(closestVehicle))
395 | end
396 |
397 | if fuelSynced then
398 | fuelSynced = false
399 | end
400 |
401 | if inBlacklisted then
402 | inBlacklisted = false
403 | end
404 | end
405 | end
406 | end)
--------------------------------------------------------------------------------
/client_functions.lua:
--------------------------------------------------------------------------------
1 | function CanPumpRefuelPetrolCan()
2 | local petrolCan = GetCurrentGasCanDurability()
3 | if petrolCan == nil then return false end
4 | if petrolCan >= 100 then return false end
5 | return true
6 | end
7 |
8 | --Checks if the supplied vehicle can have fuel siphoned from it
9 | function IsSiphonFuelAllowed(vehicle)
10 | if GetVehicleEngineHealth(entity) <= 0 then return false end
11 | if isFueling then return false end
12 |
13 | local curGasCanDurability = GetCurrentGasCanDurability()
14 |
15 | if curGasCanDurability == nil then return false end
16 | if curGasCanDurability >= 100 then return false end
17 |
18 | return Config.AllowFuelSiphoning
19 | end
20 |
21 | --Checks if the vehicle passed in can be refuelled by petrol can
22 | function IsPetrolCanRefuelAllowed(vehicle)
23 | if GetVehicleEngineHealth(entity) <= 0 then return false end
24 | if isFueling then return false end
25 |
26 | local curGasCanDurability = GetCurrentGasCanDurability()
27 | if curGasCanDurability == nil then return false end
28 | if curGasCanDurability <= 0 then return false end
29 |
30 | return Config.AllowPetrolCanRefuelCar
31 | end
32 |
33 | --If the player has a gas can equiped it gets the durability of the can
34 | --nil if no can is equiped
35 | function GetCurrentGasCanDurability()
36 | local ammo = GetAmmoInPedWeapon(PlayerPedId(), `weapon_petrolcan`)
37 | local weapon, hash = GetCurrentPedWeapon(PlayerPedId())
38 | local percentageFull = (ammo / 4000) * 100
39 | if weapon then
40 | return percentageFull
41 | -- if hash == `weapon_petrolcan` then
42 | -- -- if ammo > 4000 then
43 | -- -- print("Ammo over 4000")
44 | -- -- ammo = 4000
45 | -- -- SetPedAmmo(PlayerPedId(), `weapon_petrolcan`, ammo)
46 | -- -- ammo = GetAmmoInPedWeapon(PlayerPedId(), `weapon_petrolcan`)
47 | -- -- end
48 |
49 | -- return percentageFull
50 | -- else
51 | -- return nil
52 | -- end
53 | else
54 | return nil
55 | end
56 | end
57 |
58 | --Sets the ammo contained the petrol can
59 | function SetPetrolCanDurability(percentageFull)
60 | if percentageFull > 100 then percentageFull = 100 end
61 | if percentageFull < 0 then percentageFull = 0 end
62 |
63 | local ammo = (4000 / 100) * percentageFull
64 | if ammo > 4000 then ammo = 100 end
65 | if ammo < 0 then ammo = 0 end
66 | SetPedAmmo(PlayerPedId(),`weapon_petrolcan`,ammo)
67 | TriggerServerEvent("weapons:server:UpdateWeaponAmmo",CurrentWeaponData,ammo)
68 | end
69 |
70 | --Returns true if the vehicle passed in is able to be fueled
71 | function CanFuelVehicle(Vehicle)
72 | if Vehicle then
73 | local fuelLevel = GetFuel(Vehicle)
74 |
75 | if fuelLevel == 100 then
76 | return false
77 | end
78 | return true
79 | end
80 | return false
81 | end
82 |
83 | function GetFuel(vehicle)
84 | if vehicle == 0 or vehicle == nil then return 0 end
85 | return DecorGetFloat(vehicle, Config.FuelDecor)
86 | end
87 |
88 | function SetFuel(vehicle, fuel)
89 | if vehicle == 0 or vehicle == nil then print("nil vehicle") return end
90 | if type(fuel) == 'number' and fuel >= 0 and fuel <= 100 then
91 | SetVehicleFuelLevel(vehicle, fuel)
92 | DecorSetFloat(vehicle, Config.FuelDecor, fuel + 0.0)
93 | end
94 | end
95 |
96 | function LoadAnimDict(dict)
97 | if not HasAnimDictLoaded(dict) then
98 | RequestAnimDict(dict)
99 |
100 | while not HasAnimDictLoaded(dict) do
101 | Wait(1)
102 | end
103 | end
104 | end
105 |
106 | function DrawText3Ds(x, y, z, text)
107 | local onScreen,_x,_y=World3dToScreen2d(x,y,z)
108 |
109 | if onScreen then
110 | SetTextScale(0.35, 0.35)
111 | SetTextFont(4)
112 | SetTextProportional(1)
113 | SetTextColour(255, 255, 255, 215)
114 | SetTextEntry("STRING")
115 | SetTextCentre(1)
116 | AddTextComponentString(text)
117 | DrawText(_x,_y)
118 | end
119 | end
120 |
121 | function Round(num, numDecimalPlaces)
122 | local mult = 10^(numDecimalPlaces or 0)
123 |
124 | return math.floor(num * mult + 0.5) / mult
125 | end
126 |
127 |
128 | function CreateBlip(coords)
129 | local blip = AddBlipForCoord(coords)
130 |
131 | SetBlipSprite(blip, 361)
132 | SetBlipScale(blip, 0.6)
133 | SetBlipColour(blip, 4)
134 | SetBlipDisplay(blip, 4)
135 | SetBlipAsShortRange(blip, true)
136 |
137 | BeginTextCommandSetBlipName("STRING")
138 | AddTextComponentString("Gas Station")
139 | EndTextCommandSetBlipName(blip)
140 |
141 | return blip
142 | end
143 |
144 | function GetGasPumpModels()
145 | return Config.GasPumpModels
146 | end
147 |
148 | function FindNearestFuelPump()
149 | local coords = GetEntityCoords(PlayerPedId())
150 | local fuelPumps = {}
151 | local handle, object = FindFirstObject()
152 | local success
153 |
154 | repeat
155 | if Config.PumpModels[GetEntityModel(object)] then
156 | table.insert(fuelPumps, object)
157 | end
158 |
159 | success, object = FindNextObject(handle, object)
160 | until not success
161 |
162 | EndFindObject(handle)
163 |
164 | local pumpObject = 0
165 | local pumpDistance = 1000
166 |
167 | for _, fuelPumpObject in pairs(fuelPumps) do
168 | local dstcheck = #(coords - GetEntityCoords(fuelPumpObject))
169 |
170 | if dstcheck < pumpDistance then
171 | pumpDistance = dstcheck
172 | pumpObject = fuelPumpObject
173 | end
174 | end
175 |
176 | return pumpObject, pumpDistance
177 | end
178 |
--------------------------------------------------------------------------------
/client_interactions.lua:
--------------------------------------------------------------------------------
1 | CreateThread(function()
2 |
3 | exports['qb-target']:AddTargetBone(Config.PetrolCanRefuelBones,{
4 | options = {
5 | {
6 | type = "client",
7 | event = 'cc-fuel:client:petrolcanrefuel',
8 | label = 'Refuel Car',
9 | icon = 'fas fa-gas-pump',
10 | item = 'weapon_petrolcan',
11 | canInteract = function(entity)
12 | if GetVehicleEngineHealth(entity) <= 0 then return false end
13 | if isFueling == false then
14 | local curGasCanDurability = GetCurrentGasCanDurability()
15 | if curGasCanDurability == nil then return false end
16 | if curGasCanDurability > 0 then return true end
17 | return false
18 | end
19 | return false
20 | end
21 | },
22 | },
23 | distance = 2.5,
24 | })
25 |
26 | exports['qb-target']:AddTargetBone(Config.SiphonBones,{
27 | options = {
28 | {
29 | type="client",
30 | event="cc-fuel:client:siphonfuel",
31 | label = "Siphon Fuel",
32 | icon = 'fas fa-gas-pump',
33 | item = 'fuelsiphon',
34 | canInteract = function(entity)
35 | if GetVehicleEngineHealth(entity) <= 0 then return false end
36 | if isFueling then return false end
37 | local curGasCanDurability = GetCurrentGasCanDurability()
38 | if curGasCanDurability == nil then return false end
39 | if curGasCanDurability >= 100 then return false end
40 |
41 | return Config.AllowFuelSiphoning
42 | end
43 | }
44 | },
45 | distance = 3.0,
46 | })
47 |
48 | exports['qb-target']:AddTargetModel(Config.GasPumpModels, {
49 | options = {
50 | {
51 | icon = "fas fa-gas-pump",
52 | label = "Get Fuel",
53 | action = function(entity)
54 | TriggerEvent("cc-fuel:client:pumprefuel", entity)
55 | end
56 | },
57 | {
58 | type = "client",
59 | event = "cc-fuel:client:buypetrolcan",
60 | icon = "fas fa-gas-pump",
61 | label = "Buy Petrol Can"
62 | },
63 | {
64 | type = "client",
65 | event = "cc-fuel:client:refillpetrolcan",
66 | icon = "fas fa-gas-pump",
67 | label = "Refuel Petrol Can",
68 | canInteract = function(entity)
69 | return CanPumpRefuelPetrolCan()
70 | end
71 | }
72 | },
73 | distance = 3.0
74 | })
75 | if Config.Blips then
76 | for k, v in pairs(Config.FuelStations) do
77 | FuelStationBlip = AddBlipForCoord(v.x, v.y, v.z)
78 | SetBlipSprite(FuelStationBlip, Config.BlipSpirte)
79 | SetBlipDisplay(FuelStationBlip, 2)
80 | SetBlipScale(FuelStationBlip, Config.BlipSize)
81 | SetBlipAsShortRange(FuelStationBlip, true)
82 | SetBlipColour(FuelStationBlip, Config.BlipColor)
83 | BeginTextCommandSetBlipName("STRING")
84 | AddTextComponentSubstringPlayerName(Config.BlipLabel)
85 | EndTextCommandSetBlipName(FuelStationBlip)
86 | end
87 | end
88 | end)
89 |
90 | AddEventHandler('onResourceStop',function(name)
91 | if (GetCurrentResourceName() ~= name) then return end
92 | end)
--------------------------------------------------------------------------------
/config.lua:
--------------------------------------------------------------------------------
1 | Config = {}
2 |
3 | --Decor in which vehicle fuel is stored in, do not touch if you don't know what your doing!
4 | Config.FuelDecor = "_Fuel_Level"
5 |
6 | -- What should the price of jerry cans be?
7 | Config.JerryCanCost = 100
8 |
9 | -- What keys are disabled while you're fueling.
10 | Config.DisableKeys = {0, 22, 23, 24, 29, 30, 31, 37, 44, 56, 82, 140, 166, 167, 168, 170, 288, 289, 311, 323}
11 |
12 | -- Modify the fuel-cost here, using a multiplier value. Setting the value to 2.0 would cause a doubled increase.
13 | Config.CostMultiplier = 1.5
14 |
15 | -- Configure the strings as you wish here.
16 | Config.Strings = {
17 | CancelFuelingPump = "Press ~b~E ~w~to cancel the fueling",
18 | CancelFuelingJerryCan = "Press ~b~E ~w~to cancel the fueling",
19 | CancelSiphoningFuel = "Press ~b~E ~w~ to cancel siphoning fuel"
20 | }
21 |
22 | -- Blacklist certain vehicles. Use names or hashes. https://wiki.gtanet.work/index.php?title=Vehicle_Models
23 | Config.Blacklist = {
24 | --"Adder",
25 | --276773164
26 | }
27 |
28 | -- Do you want the HUD removed from showing in blacklisted vehicles?
29 | Config.RemoveHUDForBlacklistedVehicle = true
30 |
31 | -- Fuel Station Blips
32 | Config.Blips = true -- set false to disable blips
33 | Config.BlipSpirte = 361
34 | Config.BlipColor = 26
35 | Config.BlipSize = 0.6
36 | Config.BlipLabel = "Fuel Station"
37 | Config.FuelStations = { --Add any additional, missing or custom fuel stations here
38 | vector3(621.05, 269.09, 102.93),
39 | vector3(1181.1, -330.58, 69.51),
40 | vector3(819.14, -1028.9, 26.44),
41 | vector3(1208.29, -1401.87, 35.23),
42 | vector3(174.3, -1561.75, 28.39),
43 | vector3(264.3, -1261.57, 29.77),
44 | vector3(-70.15, -1762.1, 29.56),
45 | vector3(-524.17, -1210.58, 18.68),
46 | vector3(-724.05, -935.7, 19.72),
47 | vector3(-1436.29, -276.87, 46.09),
48 | vector3(-2097.08, -318.81, 13.98),
49 | vector3(-1799.9, 802.85, 138.88),
50 | vector3(2580.94, 361.59, 108.4),
51 | vector3(1207.64, 2660.44, 37.82),
52 | vector3(1040.36, 2671.2, 39.71),
53 | vector3(263.88, 2606.94, 45.01),
54 | vector3(2005.46, 3774.62, 31.98),
55 | vector3(1785.16, 3331.04, 41.38),
56 | vector3(2679.52, 3264.05, 55.14),
57 | vector3(1687.49, 4929.92, 42.42),
58 | vector3(1702.49, 6416.16, 32.82),
59 | vector3(180.2, 6602.7, 31.66),
60 | vector3(-94.6, 6419.65, 31.58),
61 | vector3(-2555.02, 2334.03, 32.92),
62 | vector3(49.18, 2779.13, 58.1),
63 | }
64 |
65 | -- Class multipliers. If you want SUVs to use less fuel, you can change it to anything under 1.0, and vise versa.
66 | Config.Classes = {
67 | [0] = 1.0, -- Compacts
68 | [1] = 1.0, -- Sedans
69 | [2] = 1.0, -- SUVs
70 | [3] = 1.0, -- Coupes
71 | [4] = 1.0, -- Muscle
72 | [5] = 1.0, -- Sports Classics
73 | [6] = 1.0, -- Sports
74 | [7] = 1.0, -- Super
75 | [8] = 1.0, -- Motorcycles
76 | [9] = 1.0, -- Off-road
77 | [10] = 1.0, -- Industrial
78 | [11] = 1.0, -- Utility
79 | [12] = 1.0, -- Vans
80 | [13] = 0.0, -- Cycles
81 | [14] = 1.0, -- Boats
82 | [15] = 1.0, -- Helicopters
83 | [16] = 1.0, -- Planes
84 | [17] = 1.0, -- Service
85 | [18] = 1.0, -- Emergency
86 | [19] = 1.0, -- Military
87 | [20] = 1.0, -- Commercial
88 | [21] = 1.0, -- Trains
89 | }
90 |
91 | -- The left part is at percentage RPM, and the right is how much fuel (divided by 10) you want to remove from the tank every second
92 | Config.FuelUsage = {
93 | [1.0] = 1.4,
94 | [0.9] = 1.2,
95 | [0.8] = 1.0,
96 | [0.7] = 0.9,
97 | [0.6] = 0.8,
98 | [0.5] = 0.7,
99 | [0.4] = 0.5,
100 | [0.3] = 0.4,
101 | [0.2] = 0.2,
102 | [0.1] = 0.1,
103 | [0.0] = 0.0,
104 | }
105 |
106 | Config.GasPumpModels = {
107 | "prop_gas_pump_1d",
108 | "prop_gas_pump_1a",
109 | "prop_gas_pump_1b",
110 | "prop_gas_pump_1c",
111 | "prop_vintage_pump",
112 | "prop_gas_pump_old2",
113 | "prop_gas_pump_old3"
114 | }
115 |
116 | --Fueling rates, higher numbers = faster fueling
117 |
118 | --The rate at which fuel can be siphoned from a tank
119 | Config.SiphonRate = 0.25
120 | --The rate at which a petrol can will refuel a car
121 | Config.PetrolCanRefuelRate = 0.50
122 | --The rate at which a pump will refuel a car
123 | Config.PetrolPumpRefuelRate = 0.75
124 |
125 | --Controls whether or not the vehicle will blow up if a refuel is attempted with engine on
126 | Config.VehicleEngineOnBlowUp = true
127 | --Percentage chance that the vehicle will blow up if a refuel is attempted with engine on
128 | Config.VehicleBlowUpChance = 25
129 |
130 |
131 | --Allows people to siphon fuel from other vehicles into their petrol cans
132 | Config.AllowFuelSiphoning = true
133 |
134 | --Allows people to refuel their cars with a petrol can that has fuel in it
135 | Config.AllowPetrolCanRefuelCar = true
136 |
137 | --The bones that can be targeted to attempt to siphon fuel from the vehicle
138 | Config.SiphonBones = {
139 | 'petrolcap',
140 | 'boot',
141 | 'wheel_r',
142 | }
143 |
144 | Config.PetrolCanRefuelBones = {
145 | 'petrolcap',
146 | 'boot',
147 | 'wheel_r',
148 | }
--------------------------------------------------------------------------------
/fxmanifest.lua:
--------------------------------------------------------------------------------
1 | fx_version 'cerulean'
2 | game 'gta5'
3 | lua54 'yes'
4 |
5 | author 'CQC Development'
6 | description 'Fueling system utilising qb-target'
7 | version '1.1'
8 |
9 | shared_scripts {
10 | 'config.lua'
11 | }
12 |
13 | client_scripts {
14 | 'client_functions.lua',
15 | 'client_interactions.lua',
16 | 'client.lua'
17 | }
18 |
19 | server_scripts {
20 | 'server.lua'
21 | }
22 |
23 | dependencies {
24 | 'qb-core'
25 | }
26 |
27 | exports {
28 | 'GetFuel',
29 | 'SetFuel',
30 | 'IsSiphonFuelAllowed',
31 | 'IsPetrolCanRefuelAllowed',
32 | 'CanPumpRefuelPetrolCan',
33 | }
34 |
--------------------------------------------------------------------------------
/images/fuelsiphon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CQC-Scripting/cc-fuel/2f9dd624784579cbb51dae80f4848181ccf88472/images/fuelsiphon.png
--------------------------------------------------------------------------------
/server.lua:
--------------------------------------------------------------------------------
1 | QBCore = exports['qb-core']:GetCoreObject()
2 |
3 | RegisterNetEvent("cc-fuel:server:pay", function(price,source)
4 | local xPlayer = QBCore.Functions.GetPlayer(source)
5 | local amount = math.floor(price)
6 |
7 | if price > 0 then
8 | print("Removing cash for " .. source .. " amount " .. amount)
9 | xPlayer.Functions.RemoveMoney('cash', amount)
10 | end
11 | end)
12 |
--------------------------------------------------------------------------------