From 1dbe570445b3b62684ff065143b3fb762a0d2d9c Mon Sep 17 00:00:00 2001 From: GhzGarage <57848836+GhzGarage@users.noreply.github.com> Date: Thu, 8 Apr 2021 19:28:22 -0500 Subject: [PATCH 01/31] dist --- functions/functions_client.lua | 2 +- source/fuel_client.lua | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/functions/functions_client.lua b/functions/functions_client.lua index 37ba151..5ee1820 100644 --- a/functions/functions_client.lua +++ b/functions/functions_client.lua @@ -76,7 +76,7 @@ function FindNearestFuelPump() local pumpDistance = 1000 for _, fuelPumpObject in pairs(fuelPumps) do - local dstcheck = GetDistanceBetweenCoords(coords, GetEntityCoords(fuelPumpObject)) + local dstcheck = #(coords - GetEntityCoords(fuelPumpObject)) if dstcheck < pumpDistance then pumpDistance = dstcheck diff --git a/source/fuel_client.lua b/source/fuel_client.lua index df886e7..2a2103f 100644 --- a/source/fuel_client.lua +++ b/source/fuel_client.lua @@ -201,7 +201,7 @@ Citizen.CreateThread(function() local vehicle = GetPlayersLastVehicle() local vehicleCoords = GetEntityCoords(vehicle) - if DoesEntityExist(vehicle) and GetDistanceBetweenCoords(GetEntityCoords(ped), vehicleCoords) < 2.5 then + if DoesEntityExist(vehicle) and #(GetEntityCoords(ped) - vehicleCoords) < 2.5 then if not DoesEntityExist(GetPedInVehicleSeat(vehicle, -1)) then local stringCoords = GetEntityCoords(isNearPump) local canFuel = true @@ -299,7 +299,7 @@ if Config.ShowNearestGasStationOnly then local closestCoords for _, gasStationCoords in pairs(Config.GasStations) do - local dstcheck = GetDistanceBetweenCoords(coords, gasStationCoords) + local dstcheck = #(coords - gasStationCoords) if dstcheck < closest then closest = dstcheck From fca79db50218acce09e1808828719da9e322c974 Mon Sep 17 00:00:00 2001 From: LoveFistRP Date: Mon, 12 Apr 2021 14:06:17 -0700 Subject: [PATCH 02/31] qb changes (still working on can --- config.lua | 10 ++----- source/fuel_client.lua | 64 +++++++++++++----------------------------- source/fuel_server.lua | 23 +++++++-------- 3 files changed, 32 insertions(+), 65 deletions(-) diff --git a/config.lua b/config.lua index 8e4ec39..f80d1cc 100644 --- a/config.lua +++ b/config.lua @@ -1,8 +1,5 @@ Config = {} --- Are you using ESX? Turn this to true if you would like fuel & jerry cans to cost something. -Config.UseESX = true - -- What should the price of jerry cans be? Config.JerryCanCost = 100 Config.RefillCost = 50 -- If it is missing half of it capacity, this amount will be divided in half, and so on. @@ -37,13 +34,10 @@ Config.Strings = { NotEnoughCashJerryCan = "Not enough cash to refill jerry can", JerryCanFull = "Jerry can is full", TotalCost = "Cost", + PurchaseJerryCan = "Press ~g~E ~w~to grab a jerry can", + RefillJerryCan = "Press ~g~E ~w~ to refill the jerry can", } -if not Config.UseESX then - Config.Strings.PurchaseJerryCan = "Press ~g~E ~w~to grab a jerry can" - Config.Strings.RefillJerryCan = "Press ~g~E ~w~ to refill the jerry can" -end - Config.PumpModels = { [-2007231801] = true, [1339433404] = true, diff --git a/source/fuel_client.lua b/source/fuel_client.lua index 2a2103f..c0ad5aa 100644 --- a/source/fuel_client.lua +++ b/source/fuel_client.lua @@ -1,12 +1,11 @@ -if Config.UseESX then - Citizen.CreateThread(function() - while not ESX do - TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) +QBCore = nil - Citizen.Wait(500) - end - end) -end +Citizen.CreateThread(function() + while QBCore == nil do + TriggerEvent("QBCore:GetObject", function(obj) QBCore = obj end) + Citizen.Wait(200) + end +end) local isNearPump = false local isFueling = false @@ -82,16 +81,7 @@ Citizen.CreateThread(function() if pumpDistance < 2.5 then isNearPump = pumpObject - - if Config.UseESX then - local playerData = ESX.GetPlayerData() - for i=1, #playerData.accounts, 1 do - if playerData.accounts[i].name == 'money' then - currentCash = playerData.accounts[i].money - break - end - end - end + currentCash = QBCore.Functions.GetPlayerData().money['cash'] else isNearPump = false @@ -161,11 +151,7 @@ AddEventHandler('fuel:refuelFromPump', function(pumpObject, ped, vehicle) if pumpObject then local stringCoords = GetEntityCoords(pumpObject) - local extraString = "" - - if Config.UseESX then - extraString = "\n" .. Config.Strings.TotalCost .. ": ~g~$" .. Round(currentCost, 1) - end + local extraString = "\n" .. Config.Strings.TotalCost .. ": ~g~$" .. Round(currentCost, 1) DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.CancelFuelingPump .. extraString) DrawText3Ds(vehicleCoords.x, vehicleCoords.y, vehicleCoords.z + 0.5, Round(currentFuel, 1) .. "%") @@ -241,37 +227,27 @@ Citizen.CreateThread(function() DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.PurchaseJerryCan) if IsControlJustReleased(0, 38) then - GiveWeaponToPed(ped, 883325847, 4500, false, true) - + TriggerServerEvent('QBCore:Server:AddItem', "weapon_petrolcan", 1) + TriggerEvent("inventory:client:ItemBox", QBCore.Shared.Items["weapon_petrolcan"], "add") TriggerServerEvent('fuel:pay', Config.JerryCanCost) - - currentCash = ESX.GetPlayerData().money end else - if Config.UseESX then - local refillCost = Round(Config.RefillCost * (1 - GetAmmoInPedWeapon(ped, 883325847) / 4500)) + local refillCost = Round(Config.RefillCost * (1 - GetAmmoInPedWeapon(ped, 883325847) / 4500)) - if refillCost > 0 then - if currentCash >= refillCost then - DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.RefillJerryCan .. refillCost) + if refillCost > 0 then + if currentCash >= refillCost then + DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.RefillJerryCan .. refillCost) - if IsControlJustReleased(0, 38) then - TriggerServerEvent('fuel:pay', refillCost) + if IsControlJustReleased(0, 38) then + TriggerServerEvent('fuel:pay', refillCost) - SetPedAmmo(ped, 883325847, 4500) - end - else - DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.NotEnoughCashJerryCan) + SetPedAmmo(ped, 883325847, 4500) end else - DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.JerryCanFull) + DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.NotEnoughCashJerryCan) end else - DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.RefillJerryCan) - - if IsControlJustReleased(0, 38) then - SetPedAmmo(ped, 883325847, 4500) - end + DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.JerryCanFull) end end else diff --git a/source/fuel_server.lua b/source/fuel_server.lua index 5a61c65..85bb2b8 100644 --- a/source/fuel_server.lua +++ b/source/fuel_server.lua @@ -1,15 +1,12 @@ -ESX = nil +QBCore = nil +TriggerEvent('QBCore:GetObject', function(obj) QBCore = obj end) -if Config.UseESX then - TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) +RegisterServerEvent('fuel:pay') +AddEventHandler('fuel:pay', function(price) + local xPlayer = QBCore.Functions.GetPlayer(source) + local amount = math.floor(price + 0.5) - RegisterServerEvent('fuel:pay') - AddEventHandler('fuel:pay', function(price) - local xPlayer = ESX.GetPlayerFromId(source) - local amount = ESX.Math.Round(price) - - if price > 0 then - xPlayer.removeMoney(amount) - end - end) -end + if price > 0 then + xPlayer.Functions.RemoveMoney('cash', amount) + end +end) \ No newline at end of file From cb891166cfb143890fef4eafe30fdff413ce53e7 Mon Sep 17 00:00:00 2001 From: LoveFistRP Date: Mon, 12 Apr 2021 14:12:11 -0700 Subject: [PATCH 03/31] hud --- config.lua | 2 +- source/fuel_client.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config.lua b/config.lua index f80d1cc..68f6dc6 100644 --- a/config.lua +++ b/config.lua @@ -11,7 +11,7 @@ Config.FuelDecor = "_FUEL_LEVEL" Config.DisableKeys = {0, 22, 23, 24, 29, 30, 31, 37, 44, 56, 82, 140, 166, 167, 168, 170, 288, 289, 311, 323} -- Want to use the HUD? Turn this to true. -Config.EnableHUD = true +Config.EnableHUD = false -- Configure blips here. Turn both to false to disable blips all together. Config.ShowNearestGasStationOnly = true diff --git a/source/fuel_client.lua b/source/fuel_client.lua index c0ad5aa..5d7b282 100644 --- a/source/fuel_client.lua +++ b/source/fuel_client.lua @@ -3,7 +3,7 @@ QBCore = nil Citizen.CreateThread(function() while QBCore == nil do TriggerEvent("QBCore:GetObject", function(obj) QBCore = obj end) - Citizen.Wait(200) + Citizen.Wait(2000) end end) From d4032874fbc18ba0f3dcbc31ee7a6fa227d4e30f Mon Sep 17 00:00:00 2001 From: BerkieBb <82737367+BerkieBb@users.noreply.github.com> Date: Mon, 19 Apr 2021 21:15:28 +0200 Subject: [PATCH 04/31] Fixed error with source --- fuel_client.lua | 364 ++++++++++++++++++++++++++++++++++++++++++++++++ fuel_server.lua | 13 ++ 2 files changed, 377 insertions(+) create mode 100644 fuel_client.lua create mode 100644 fuel_server.lua diff --git a/fuel_client.lua b/fuel_client.lua new file mode 100644 index 0000000..4f11014 --- /dev/null +++ b/fuel_client.lua @@ -0,0 +1,364 @@ +QBCore = nil + +Citizen.CreateThread(function() + while QBCore == nil do + TriggerEvent("QBCore:GetObject", function(obj) QBCore = obj end) + Citizen.Wait(2000) + end +end) + +local isNearPump = false +local isFueling = false +local currentFuel = 0.0 +local currentCost = 0.0 +local currentCash = 1000 +local fuelSynced = false +local inBlacklisted = false + +function ManageFuelUsage(vehicle) + if not DecorExistOn(vehicle, Config.FuelDecor) then + SetFuel(vehicle, math.random(200, 800) / 10) + elseif not fuelSynced then + SetFuel(vehicle, GetFuel(vehicle)) + + fuelSynced = true + end + + if IsVehicleEngineOn(vehicle) then + SetFuel(vehicle, GetVehicleFuelLevel(vehicle) - Config.FuelUsage[Round(GetVehicleCurrentRpm(vehicle), 1)] * (Config.Classes[GetVehicleClass(vehicle)] or 1.0) / 10) + end +end + +Citizen.CreateThread(function() + DecorRegister(Config.FuelDecor, 1) + + for index = 1, #Config.Blacklist do + if type(Config.Blacklist[index]) == 'string' then + Config.Blacklist[GetHashKey(Config.Blacklist[index])] = true + else + Config.Blacklist[Config.Blacklist[index]] = true + end + end + + for index = #Config.Blacklist, 1, -1 do + table.remove(Config.Blacklist, index) + end + + while true do + Citizen.Wait(1000) + + local ped = PlayerPedId() + + if IsPedInAnyVehicle(ped) then + local vehicle = GetVehiclePedIsIn(ped) + + if Config.Blacklist[GetEntityModel(vehicle)] then + inBlacklisted = true + else + inBlacklisted = false + end + + if not inBlacklisted and GetPedInVehicleSeat(vehicle, -1) == ped then + ManageFuelUsage(vehicle) + end + else + if fuelSynced then + fuelSynced = false + end + + if inBlacklisted then + inBlacklisted = false + end + end + end +end) + +Citizen.CreateThread(function() + while true do + Citizen.Wait(250) + + local pumpObject, pumpDistance = FindNearestFuelPump() + + if pumpDistance < 2.5 then + isNearPump = pumpObject + currentCash = QBCore.Functions.GetPlayerData().money['cash'] + else + isNearPump = false + + Citizen.Wait(math.ceil(pumpDistance * 20)) + end + end +end) + +AddEventHandler('fuel:startFuelUpTick', function(pumpObject, ped, vehicle) + currentFuel = GetVehicleFuelLevel(vehicle) + + while isFueling do + Citizen.Wait(500) + + local oldFuel = DecorGetFloat(vehicle, Config.FuelDecor) + local fuelToAdd = math.random(10, 20) / 10.0 + local extraCost = fuelToAdd / 1.5 * Config.CostMultiplier + + if not pumpObject then + if GetAmmoInPedWeapon(ped, 883325847) - fuelToAdd * 100 >= 0 then + currentFuel = oldFuel + fuelToAdd + + SetPedAmmo(ped, 883325847, math.floor(GetAmmoInPedWeapon(ped, 883325847) - fuelToAdd * 100)) + else + isFueling = false + end + else + currentFuel = oldFuel + fuelToAdd + end + + if currentFuel > 100.0 then + currentFuel = 100.0 + isFueling = false + end + + currentCost = currentCost + extraCost + + if currentCash >= currentCost then + SetFuel(vehicle, currentFuel) + else + isFueling = false + end + end + + if pumpObject then + TriggerServerEvent('fuel:pay', currentCost, GetPlayerServerId(PlayerId())) + end + + currentCost = 0.0 +end) + +AddEventHandler('fuel:refuelFromPump', function(pumpObject, ped, vehicle) + TaskTurnPedToFaceEntity(ped, vehicle, 1000) + Citizen.Wait(1000) + SetCurrentPedWeapon(ped, -1569615261, true) + LoadAnimDict("timetable@gardener@filling_can") + TaskPlayAnim(ped, "timetable@gardener@filling_can", "gar_ig_5_filling_can", 2.0, 8.0, -1, 50, 0, 0, 0, 0) + + TriggerEvent('fuel:startFuelUpTick', pumpObject, ped, vehicle) + + while isFueling do + for _, controlIndex in pairs(Config.DisableKeys) do + DisableControlAction(0, controlIndex) + end + + local vehicleCoords = GetEntityCoords(vehicle) + + if pumpObject then + local stringCoords = GetEntityCoords(pumpObject) + local extraString = "\n" .. Config.Strings.TotalCost .. ": ~g~$" .. Round(currentCost, 1) + + DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.CancelFuelingPump .. extraString) + DrawText3Ds(vehicleCoords.x, vehicleCoords.y, vehicleCoords.z + 0.5, Round(currentFuel, 1) .. "%") + else + DrawText3Ds(vehicleCoords.x, vehicleCoords.y, vehicleCoords.z + 0.5, Config.Strings.CancelFuelingJerryCan .. "\nGas can: ~g~" .. Round(GetAmmoInPedWeapon(ped, 883325847) / 4500 * 100, 1) .. "% | Vehicle: " .. Round(currentFuel, 1) .. "%") + end + + if not IsEntityPlayingAnim(ped, "timetable@gardener@filling_can", "gar_ig_5_filling_can", 3) then + TaskPlayAnim(ped, "timetable@gardener@filling_can", "gar_ig_5_filling_can", 2.0, 8.0, -1, 50, 0, 0, 0, 0) + end + + if IsControlJustReleased(0, 38) or DoesEntityExist(GetPedInVehicleSeat(vehicle, -1)) or (isNearPump and GetEntityHealth(pumpObject) <= 0) then + isFueling = false + end + + Citizen.Wait(0) + end + + ClearPedTasks(ped) + RemoveAnimDict("timetable@gardener@filling_can") +end) + +Citizen.CreateThread(function() + while true do + local ped = PlayerPedId() + + if not isFueling and ((isNearPump and GetEntityHealth(isNearPump) > 0) or (GetSelectedPedWeapon(ped) == 883325847 and not isNearPump)) then + if IsPedInAnyVehicle(ped) and GetPedInVehicleSeat(GetVehiclePedIsIn(ped), -1) == ped then + local pumpCoords = GetEntityCoords(isNearPump) + + DrawText3Ds(pumpCoords.x, pumpCoords.y, pumpCoords.z + 1.2, Config.Strings.ExitVehicle) + else + local vehicle = GetPlayersLastVehicle() + local vehicleCoords = GetEntityCoords(vehicle) + + if DoesEntityExist(vehicle) and #(GetEntityCoords(ped) - vehicleCoords) < 2.5 then + if not DoesEntityExist(GetPedInVehicleSeat(vehicle, -1)) then + local stringCoords = GetEntityCoords(isNearPump) + local canFuel = true + + if GetSelectedPedWeapon(ped) == 883325847 then + stringCoords = vehicleCoords + + if GetAmmoInPedWeapon(ped, 883325847) < 100 then + canFuel = false + end + end + + if GetVehicleFuelLevel(vehicle) < 95 and canFuel then + if currentCash > 0 then + DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.EToRefuel) + + if IsControlJustReleased(0, 38) then + isFueling = true + + TriggerEvent('fuel:refuelFromPump', isNearPump, ped, vehicle) + LoadAnimDict("timetable@gardener@filling_can") + end + else + DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.NotEnoughCash) + end + elseif not canFuel then + DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.JerryCanEmpty) + else + DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.FullTank) + end + end + elseif isNearPump then + local stringCoords = GetEntityCoords(isNearPump) + + if currentCash >= Config.JerryCanCost then + if not HasPedGotWeapon(ped, 883325847) then + DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.PurchaseJerryCan) + + if IsControlJustReleased(0, 38) then + TriggerServerEvent('QBCore:Server:AddItem', "weapon_petrolcan", 1) + TriggerEvent("inventory:client:ItemBox", QBCore.Shared.Items["weapon_petrolcan"], "add") + TriggerServerEvent('fuel:pay', Config.JerryCanCost, GetPlayerServerId(PlayerId())) + end + else + local refillCost = Round(Config.RefillCost * (1 - GetAmmoInPedWeapon(ped, 883325847) / 4500)) + + if refillCost > 0 then + if currentCash >= refillCost then + DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.RefillJerryCan .. refillCost) + + if IsControlJustReleased(0, 38) then + TriggerServerEvent('fuel:pay', refillCost, GetPlayerServerId(PlayerId())) + + SetPedAmmo(ped, 883325847, 4500) + end + else + DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.NotEnoughCashJerryCan) + end + else + DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.JerryCanFull) + end + end + else + DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.NotEnoughCash) + end + else + Citizen.Wait(250) + end + end + else + Citizen.Wait(250) + end + + Citizen.Wait(0) + end +end) + +if Config.ShowNearestGasStationOnly then + Citizen.CreateThread(function() + local currentGasBlip = 0 + + while true do + local coords = GetEntityCoords(PlayerPedId()) + local closest = 1000 + local closestCoords + + for _, gasStationCoords in pairs(Config.GasStations) do + local dstcheck = #(coords - gasStationCoords) + + if dstcheck < closest then + closest = dstcheck + closestCoords = gasStationCoords + end + end + + if DoesBlipExist(currentGasBlip) then + RemoveBlip(currentGasBlip) + end + + currentGasBlip = CreateBlip(closestCoords) + + Citizen.Wait(10000) + end + end) +elseif Config.ShowAllGasStations then + Citizen.CreateThread(function() + for _, gasStationCoords in pairs(Config.GasStations) do + CreateBlip(gasStationCoords) + end + end) +end + +if Config.EnableHUD then + local function DrawAdvancedText(x,y ,w,h,sc, text, r,g,b,a,font,jus) + SetTextFont(font) + SetTextProportional(0) + SetTextScale(sc, sc) + N_0x4e096588b13ffeca(jus) + SetTextColour(r, g, b, a) + SetTextDropShadow(0, 0, 0, 0,255) + SetTextEdge(1, 0, 0, 0, 255) + SetTextDropShadow() + SetTextOutline() + SetTextEntry("STRING") + AddTextComponentString(text) + DrawText(x - 0.1+w, y - 0.02+h) + end + + local mph = 0 + local kmh = 0 + local fuel = 0 + local displayHud = false + + local x = 0.01135 + local y = 0.002 + + Citizen.CreateThread(function() + while true do + local ped = PlayerPedId() + + if IsPedInAnyVehicle(ped) and not (Config.RemoveHUDForBlacklistedVehicle and inBlacklisted) then + local vehicle = GetVehiclePedIsIn(ped) + local speed = GetEntitySpeed(vehicle) + + mph = tostring(math.ceil(speed * 2.236936)) + kmh = tostring(math.ceil(speed * 3.6)) + fuel = tostring(math.ceil(GetVehicleFuelLevel(vehicle))) + + displayHud = true + else + displayHud = false + + Citizen.Wait(500) + end + + Citizen.Wait(50) + end + end) + + Citizen.CreateThread(function() + while true do + if displayHud then + DrawAdvancedText(0.130 - x, 0.77 - y, 0.005, 0.0028, 0.6, mph, 255, 255, 255, 255, 6, 1) + DrawAdvancedText(0.174 - x, 0.77 - y, 0.005, 0.0028, 0.6, kmh, 255, 255, 255, 255, 6, 1) + DrawAdvancedText(0.2195 - x, 0.77 - y, 0.005, 0.0028, 0.6, fuel, 255, 255, 255, 255, 6, 1) + DrawAdvancedText(0.148 - x, 0.7765 - y, 0.005, 0.0028, 0.4, "mp/h km/h Fuel", 255, 255, 255, 255, 6, 1) + else + Citizen.Wait(750) + end + + Citizen.Wait(0) + end + end) +end diff --git a/fuel_server.lua b/fuel_server.lua new file mode 100644 index 0000000..1fd2647 --- /dev/null +++ b/fuel_server.lua @@ -0,0 +1,13 @@ +QBCore = nil + +TriggerEvent('QBCore:GetObject', function(obj) QBCore = obj end) + +RegisterServerEvent('fuel:pay') +AddEventHandler('fuel:pay', function(price, source) + local xPlayer = QBCore.Functions.GetPlayer(source) + local amount = math.floor(price + 0.5) + + if price > 0 then + xPlayer.Functions.RemoveMoney('cash', amount) + end +end) \ No newline at end of file From 14e2e7901801929c88d07d9cc7a5cb8e0c114ef9 Mon Sep 17 00:00:00 2001 From: BerkieBb <82737367+BerkieBb@users.noreply.github.com> Date: Wed, 23 Jun 2021 14:14:36 +0200 Subject: [PATCH 05/31] Update fuel_client.lua --- source/fuel_client.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/fuel_client.lua b/source/fuel_client.lua index 5d7b282..aab1385 100644 --- a/source/fuel_client.lua +++ b/source/fuel_client.lua @@ -3,7 +3,7 @@ QBCore = nil Citizen.CreateThread(function() while QBCore == nil do TriggerEvent("QBCore:GetObject", function(obj) QBCore = obj end) - Citizen.Wait(2000) + Citizen.Wait(200) end end) @@ -127,7 +127,7 @@ AddEventHandler('fuel:startFuelUpTick', function(pumpObject, ped, vehicle) end if pumpObject then - TriggerServerEvent('fuel:pay', currentCost) + TriggerServerEvent('fuel:pay', currentCost, GetPlayerServerId(PlayerId())) end currentCost = 0.0 @@ -229,7 +229,7 @@ Citizen.CreateThread(function() if IsControlJustReleased(0, 38) then TriggerServerEvent('QBCore:Server:AddItem', "weapon_petrolcan", 1) TriggerEvent("inventory:client:ItemBox", QBCore.Shared.Items["weapon_petrolcan"], "add") - TriggerServerEvent('fuel:pay', Config.JerryCanCost) + TriggerServerEvent('fuel:pay', Config.JerryCanCost, GetPlayerServerId(PlayerId())) end else local refillCost = Round(Config.RefillCost * (1 - GetAmmoInPedWeapon(ped, 883325847) / 4500)) @@ -239,7 +239,7 @@ Citizen.CreateThread(function() DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.RefillJerryCan .. refillCost) if IsControlJustReleased(0, 38) then - TriggerServerEvent('fuel:pay', refillCost) + TriggerServerEvent('fuel:pay', refillCost, GetPlayerServerId(PlayerId())) SetPedAmmo(ped, 883325847, 4500) end From 3132125acb933dce08216e44a566ea2f73e58d79 Mon Sep 17 00:00:00 2001 From: BerkieBb <82737367+BerkieBb@users.noreply.github.com> Date: Wed, 23 Jun 2021 14:15:09 +0200 Subject: [PATCH 06/31] Update fuel_server.lua --- source/fuel_server.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/fuel_server.lua b/source/fuel_server.lua index 85bb2b8..720da09 100644 --- a/source/fuel_server.lua +++ b/source/fuel_server.lua @@ -1,12 +1,13 @@ QBCore = nil + TriggerEvent('QBCore:GetObject', function(obj) QBCore = obj end) RegisterServerEvent('fuel:pay') -AddEventHandler('fuel:pay', function(price) +AddEventHandler('fuel:pay', function(price, source) local xPlayer = QBCore.Functions.GetPlayer(source) local amount = math.floor(price + 0.5) if price > 0 then xPlayer.Functions.RemoveMoney('cash', amount) end -end) \ No newline at end of file +end) From e1e08ecc862d50b9edf0773bfb62eed152a03e97 Mon Sep 17 00:00:00 2001 From: BerkieBb <82737367+BerkieBb@users.noreply.github.com> Date: Wed, 23 Jun 2021 14:15:18 +0200 Subject: [PATCH 07/31] Delete fuel_client.lua --- fuel_client.lua | 364 ------------------------------------------------ 1 file changed, 364 deletions(-) delete mode 100644 fuel_client.lua diff --git a/fuel_client.lua b/fuel_client.lua deleted file mode 100644 index 4f11014..0000000 --- a/fuel_client.lua +++ /dev/null @@ -1,364 +0,0 @@ -QBCore = nil - -Citizen.CreateThread(function() - while QBCore == nil do - TriggerEvent("QBCore:GetObject", function(obj) QBCore = obj end) - Citizen.Wait(2000) - end -end) - -local isNearPump = false -local isFueling = false -local currentFuel = 0.0 -local currentCost = 0.0 -local currentCash = 1000 -local fuelSynced = false -local inBlacklisted = false - -function ManageFuelUsage(vehicle) - if not DecorExistOn(vehicle, Config.FuelDecor) then - SetFuel(vehicle, math.random(200, 800) / 10) - elseif not fuelSynced then - SetFuel(vehicle, GetFuel(vehicle)) - - fuelSynced = true - end - - if IsVehicleEngineOn(vehicle) then - SetFuel(vehicle, GetVehicleFuelLevel(vehicle) - Config.FuelUsage[Round(GetVehicleCurrentRpm(vehicle), 1)] * (Config.Classes[GetVehicleClass(vehicle)] or 1.0) / 10) - end -end - -Citizen.CreateThread(function() - DecorRegister(Config.FuelDecor, 1) - - for index = 1, #Config.Blacklist do - if type(Config.Blacklist[index]) == 'string' then - Config.Blacklist[GetHashKey(Config.Blacklist[index])] = true - else - Config.Blacklist[Config.Blacklist[index]] = true - end - end - - for index = #Config.Blacklist, 1, -1 do - table.remove(Config.Blacklist, index) - end - - while true do - Citizen.Wait(1000) - - local ped = PlayerPedId() - - if IsPedInAnyVehicle(ped) then - local vehicle = GetVehiclePedIsIn(ped) - - if Config.Blacklist[GetEntityModel(vehicle)] then - inBlacklisted = true - else - inBlacklisted = false - end - - if not inBlacklisted and GetPedInVehicleSeat(vehicle, -1) == ped then - ManageFuelUsage(vehicle) - end - else - if fuelSynced then - fuelSynced = false - end - - if inBlacklisted then - inBlacklisted = false - end - end - end -end) - -Citizen.CreateThread(function() - while true do - Citizen.Wait(250) - - local pumpObject, pumpDistance = FindNearestFuelPump() - - if pumpDistance < 2.5 then - isNearPump = pumpObject - currentCash = QBCore.Functions.GetPlayerData().money['cash'] - else - isNearPump = false - - Citizen.Wait(math.ceil(pumpDistance * 20)) - end - end -end) - -AddEventHandler('fuel:startFuelUpTick', function(pumpObject, ped, vehicle) - currentFuel = GetVehicleFuelLevel(vehicle) - - while isFueling do - Citizen.Wait(500) - - local oldFuel = DecorGetFloat(vehicle, Config.FuelDecor) - local fuelToAdd = math.random(10, 20) / 10.0 - local extraCost = fuelToAdd / 1.5 * Config.CostMultiplier - - if not pumpObject then - if GetAmmoInPedWeapon(ped, 883325847) - fuelToAdd * 100 >= 0 then - currentFuel = oldFuel + fuelToAdd - - SetPedAmmo(ped, 883325847, math.floor(GetAmmoInPedWeapon(ped, 883325847) - fuelToAdd * 100)) - else - isFueling = false - end - else - currentFuel = oldFuel + fuelToAdd - end - - if currentFuel > 100.0 then - currentFuel = 100.0 - isFueling = false - end - - currentCost = currentCost + extraCost - - if currentCash >= currentCost then - SetFuel(vehicle, currentFuel) - else - isFueling = false - end - end - - if pumpObject then - TriggerServerEvent('fuel:pay', currentCost, GetPlayerServerId(PlayerId())) - end - - currentCost = 0.0 -end) - -AddEventHandler('fuel:refuelFromPump', function(pumpObject, ped, vehicle) - TaskTurnPedToFaceEntity(ped, vehicle, 1000) - Citizen.Wait(1000) - SetCurrentPedWeapon(ped, -1569615261, true) - LoadAnimDict("timetable@gardener@filling_can") - TaskPlayAnim(ped, "timetable@gardener@filling_can", "gar_ig_5_filling_can", 2.0, 8.0, -1, 50, 0, 0, 0, 0) - - TriggerEvent('fuel:startFuelUpTick', pumpObject, ped, vehicle) - - while isFueling do - for _, controlIndex in pairs(Config.DisableKeys) do - DisableControlAction(0, controlIndex) - end - - local vehicleCoords = GetEntityCoords(vehicle) - - if pumpObject then - local stringCoords = GetEntityCoords(pumpObject) - local extraString = "\n" .. Config.Strings.TotalCost .. ": ~g~$" .. Round(currentCost, 1) - - DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.CancelFuelingPump .. extraString) - DrawText3Ds(vehicleCoords.x, vehicleCoords.y, vehicleCoords.z + 0.5, Round(currentFuel, 1) .. "%") - else - DrawText3Ds(vehicleCoords.x, vehicleCoords.y, vehicleCoords.z + 0.5, Config.Strings.CancelFuelingJerryCan .. "\nGas can: ~g~" .. Round(GetAmmoInPedWeapon(ped, 883325847) / 4500 * 100, 1) .. "% | Vehicle: " .. Round(currentFuel, 1) .. "%") - end - - if not IsEntityPlayingAnim(ped, "timetable@gardener@filling_can", "gar_ig_5_filling_can", 3) then - TaskPlayAnim(ped, "timetable@gardener@filling_can", "gar_ig_5_filling_can", 2.0, 8.0, -1, 50, 0, 0, 0, 0) - end - - if IsControlJustReleased(0, 38) or DoesEntityExist(GetPedInVehicleSeat(vehicle, -1)) or (isNearPump and GetEntityHealth(pumpObject) <= 0) then - isFueling = false - end - - Citizen.Wait(0) - end - - ClearPedTasks(ped) - RemoveAnimDict("timetable@gardener@filling_can") -end) - -Citizen.CreateThread(function() - while true do - local ped = PlayerPedId() - - if not isFueling and ((isNearPump and GetEntityHealth(isNearPump) > 0) or (GetSelectedPedWeapon(ped) == 883325847 and not isNearPump)) then - if IsPedInAnyVehicle(ped) and GetPedInVehicleSeat(GetVehiclePedIsIn(ped), -1) == ped then - local pumpCoords = GetEntityCoords(isNearPump) - - DrawText3Ds(pumpCoords.x, pumpCoords.y, pumpCoords.z + 1.2, Config.Strings.ExitVehicle) - else - local vehicle = GetPlayersLastVehicle() - local vehicleCoords = GetEntityCoords(vehicle) - - if DoesEntityExist(vehicle) and #(GetEntityCoords(ped) - vehicleCoords) < 2.5 then - if not DoesEntityExist(GetPedInVehicleSeat(vehicle, -1)) then - local stringCoords = GetEntityCoords(isNearPump) - local canFuel = true - - if GetSelectedPedWeapon(ped) == 883325847 then - stringCoords = vehicleCoords - - if GetAmmoInPedWeapon(ped, 883325847) < 100 then - canFuel = false - end - end - - if GetVehicleFuelLevel(vehicle) < 95 and canFuel then - if currentCash > 0 then - DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.EToRefuel) - - if IsControlJustReleased(0, 38) then - isFueling = true - - TriggerEvent('fuel:refuelFromPump', isNearPump, ped, vehicle) - LoadAnimDict("timetable@gardener@filling_can") - end - else - DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.NotEnoughCash) - end - elseif not canFuel then - DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.JerryCanEmpty) - else - DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.FullTank) - end - end - elseif isNearPump then - local stringCoords = GetEntityCoords(isNearPump) - - if currentCash >= Config.JerryCanCost then - if not HasPedGotWeapon(ped, 883325847) then - DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.PurchaseJerryCan) - - if IsControlJustReleased(0, 38) then - TriggerServerEvent('QBCore:Server:AddItem', "weapon_petrolcan", 1) - TriggerEvent("inventory:client:ItemBox", QBCore.Shared.Items["weapon_petrolcan"], "add") - TriggerServerEvent('fuel:pay', Config.JerryCanCost, GetPlayerServerId(PlayerId())) - end - else - local refillCost = Round(Config.RefillCost * (1 - GetAmmoInPedWeapon(ped, 883325847) / 4500)) - - if refillCost > 0 then - if currentCash >= refillCost then - DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.RefillJerryCan .. refillCost) - - if IsControlJustReleased(0, 38) then - TriggerServerEvent('fuel:pay', refillCost, GetPlayerServerId(PlayerId())) - - SetPedAmmo(ped, 883325847, 4500) - end - else - DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.NotEnoughCashJerryCan) - end - else - DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.JerryCanFull) - end - end - else - DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.NotEnoughCash) - end - else - Citizen.Wait(250) - end - end - else - Citizen.Wait(250) - end - - Citizen.Wait(0) - end -end) - -if Config.ShowNearestGasStationOnly then - Citizen.CreateThread(function() - local currentGasBlip = 0 - - while true do - local coords = GetEntityCoords(PlayerPedId()) - local closest = 1000 - local closestCoords - - for _, gasStationCoords in pairs(Config.GasStations) do - local dstcheck = #(coords - gasStationCoords) - - if dstcheck < closest then - closest = dstcheck - closestCoords = gasStationCoords - end - end - - if DoesBlipExist(currentGasBlip) then - RemoveBlip(currentGasBlip) - end - - currentGasBlip = CreateBlip(closestCoords) - - Citizen.Wait(10000) - end - end) -elseif Config.ShowAllGasStations then - Citizen.CreateThread(function() - for _, gasStationCoords in pairs(Config.GasStations) do - CreateBlip(gasStationCoords) - end - end) -end - -if Config.EnableHUD then - local function DrawAdvancedText(x,y ,w,h,sc, text, r,g,b,a,font,jus) - SetTextFont(font) - SetTextProportional(0) - SetTextScale(sc, sc) - N_0x4e096588b13ffeca(jus) - SetTextColour(r, g, b, a) - SetTextDropShadow(0, 0, 0, 0,255) - SetTextEdge(1, 0, 0, 0, 255) - SetTextDropShadow() - SetTextOutline() - SetTextEntry("STRING") - AddTextComponentString(text) - DrawText(x - 0.1+w, y - 0.02+h) - end - - local mph = 0 - local kmh = 0 - local fuel = 0 - local displayHud = false - - local x = 0.01135 - local y = 0.002 - - Citizen.CreateThread(function() - while true do - local ped = PlayerPedId() - - if IsPedInAnyVehicle(ped) and not (Config.RemoveHUDForBlacklistedVehicle and inBlacklisted) then - local vehicle = GetVehiclePedIsIn(ped) - local speed = GetEntitySpeed(vehicle) - - mph = tostring(math.ceil(speed * 2.236936)) - kmh = tostring(math.ceil(speed * 3.6)) - fuel = tostring(math.ceil(GetVehicleFuelLevel(vehicle))) - - displayHud = true - else - displayHud = false - - Citizen.Wait(500) - end - - Citizen.Wait(50) - end - end) - - Citizen.CreateThread(function() - while true do - if displayHud then - DrawAdvancedText(0.130 - x, 0.77 - y, 0.005, 0.0028, 0.6, mph, 255, 255, 255, 255, 6, 1) - DrawAdvancedText(0.174 - x, 0.77 - y, 0.005, 0.0028, 0.6, kmh, 255, 255, 255, 255, 6, 1) - DrawAdvancedText(0.2195 - x, 0.77 - y, 0.005, 0.0028, 0.6, fuel, 255, 255, 255, 255, 6, 1) - DrawAdvancedText(0.148 - x, 0.7765 - y, 0.005, 0.0028, 0.4, "mp/h km/h Fuel", 255, 255, 255, 255, 6, 1) - else - Citizen.Wait(750) - end - - Citizen.Wait(0) - end - end) -end From 7c839b4958b1a8dc9d5ed993a7f2f5eedadc2908 Mon Sep 17 00:00:00 2001 From: BerkieBb <82737367+BerkieBb@users.noreply.github.com> Date: Wed, 23 Jun 2021 14:15:22 +0200 Subject: [PATCH 08/31] Delete fuel_server.lua --- fuel_server.lua | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 fuel_server.lua diff --git a/fuel_server.lua b/fuel_server.lua deleted file mode 100644 index 1fd2647..0000000 --- a/fuel_server.lua +++ /dev/null @@ -1,13 +0,0 @@ -QBCore = nil - -TriggerEvent('QBCore:GetObject', function(obj) QBCore = obj end) - -RegisterServerEvent('fuel:pay') -AddEventHandler('fuel:pay', function(price, source) - local xPlayer = QBCore.Functions.GetPlayer(source) - local amount = math.floor(price + 0.5) - - if price > 0 then - xPlayer.Functions.RemoveMoney('cash', amount) - end -end) \ No newline at end of file From 765943ab839a72f8559f819a5d022a58ae65d77b Mon Sep 17 00:00:00 2001 From: vanillaa <80897991+vanillla1@users.noreply.github.com> Date: Fri, 27 Aug 2021 01:54:13 +0300 Subject: [PATCH 09/31] GetObject --- fxmanifest.lua | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/fxmanifest.lua b/fxmanifest.lua index 9103586..996ffa6 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -5,15 +5,17 @@ author 'InZidiuZ' description 'Legacy Fuel' version '1.3' --- What to run +shared_scripts { + '@qb-core/import.lua', + 'config.lua' +} + client_scripts { - 'config.lua', 'functions/functions_client.lua', 'source/fuel_client.lua' } server_scripts { - 'config.lua', 'source/fuel_server.lua' } From 18ee00d97720e18600bc310eb0a3e2da67294688 Mon Sep 17 00:00:00 2001 From: vanillaa <80897991+vanillla1@users.noreply.github.com> Date: Fri, 27 Aug 2021 01:54:48 +0300 Subject: [PATCH 10/31] very big blip --- functions/functions_client.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/functions_client.lua b/functions/functions_client.lua index 5ee1820..b3df7e1 100644 --- a/functions/functions_client.lua +++ b/functions/functions_client.lua @@ -44,7 +44,7 @@ function CreateBlip(coords) local blip = AddBlipForCoord(coords) SetBlipSprite(blip, 361) - SetBlipScale(blip, 0.9) + SetBlipScale(blip, 0.6) SetBlipColour(blip, 4) SetBlipDisplay(blip, 4) SetBlipAsShortRange(blip, true) From 1b654fad19cfd00ad545739c95bac6a0d13d3f2c Mon Sep 17 00:00:00 2001 From: vanillaa <80897991+vanillla1@users.noreply.github.com> Date: Fri, 27 Aug 2021 01:55:31 +0300 Subject: [PATCH 11/31] GetObject --- source/fuel_server.lua | 4 ---- 1 file changed, 4 deletions(-) diff --git a/source/fuel_server.lua b/source/fuel_server.lua index 720da09..0703dc9 100644 --- a/source/fuel_server.lua +++ b/source/fuel_server.lua @@ -1,7 +1,3 @@ -QBCore = nil - -TriggerEvent('QBCore:GetObject', function(obj) QBCore = obj end) - RegisterServerEvent('fuel:pay') AddEventHandler('fuel:pay', function(price, source) local xPlayer = QBCore.Functions.GetPlayer(source) From 896c148e4891fea54633d66a433e238d60c46148 Mon Sep 17 00:00:00 2001 From: vanillaa <80897991+vanillla1@users.noreply.github.com> Date: Fri, 27 Aug 2021 01:55:44 +0300 Subject: [PATCH 12/31] GetObject --- source/fuel_client.lua | 9 --------- 1 file changed, 9 deletions(-) diff --git a/source/fuel_client.lua b/source/fuel_client.lua index aab1385..ba5cbdb 100644 --- a/source/fuel_client.lua +++ b/source/fuel_client.lua @@ -1,12 +1,3 @@ -QBCore = nil - -Citizen.CreateThread(function() - while QBCore == nil do - TriggerEvent("QBCore:GetObject", function(obj) QBCore = obj end) - Citizen.Wait(200) - end -end) - local isNearPump = false local isFueling = false local currentFuel = 0.0 From a5327445da4d4c63c354451784f382e3b6718a8d Mon Sep 17 00:00:00 2001 From: "ev.vanillaa" <80897991+evanillaa@users.noreply.github.com> Date: Sun, 26 Sep 2021 20:39:11 +0300 Subject: [PATCH 13/31] not use this --- source/fuel_client.lua | 63 ------------------------------------------ 1 file changed, 63 deletions(-) diff --git a/source/fuel_client.lua b/source/fuel_client.lua index ba5cbdb..282987e 100644 --- a/source/fuel_client.lua +++ b/source/fuel_client.lua @@ -290,66 +290,3 @@ elseif Config.ShowAllGasStations then end end) end - -if Config.EnableHUD then - local function DrawAdvancedText(x,y ,w,h,sc, text, r,g,b,a,font,jus) - SetTextFont(font) - SetTextProportional(0) - SetTextScale(sc, sc) - N_0x4e096588b13ffeca(jus) - SetTextColour(r, g, b, a) - SetTextDropShadow(0, 0, 0, 0,255) - SetTextEdge(1, 0, 0, 0, 255) - SetTextDropShadow() - SetTextOutline() - SetTextEntry("STRING") - AddTextComponentString(text) - DrawText(x - 0.1+w, y - 0.02+h) - end - - local mph = 0 - local kmh = 0 - local fuel = 0 - local displayHud = false - - local x = 0.01135 - local y = 0.002 - - Citizen.CreateThread(function() - while true do - local ped = PlayerPedId() - - if IsPedInAnyVehicle(ped) and not (Config.RemoveHUDForBlacklistedVehicle and inBlacklisted) then - local vehicle = GetVehiclePedIsIn(ped) - local speed = GetEntitySpeed(vehicle) - - mph = tostring(math.ceil(speed * 2.236936)) - kmh = tostring(math.ceil(speed * 3.6)) - fuel = tostring(math.ceil(GetVehicleFuelLevel(vehicle))) - - displayHud = true - else - displayHud = false - - Citizen.Wait(500) - end - - Citizen.Wait(50) - end - end) - - Citizen.CreateThread(function() - while true do - if displayHud then - DrawAdvancedText(0.130 - x, 0.77 - y, 0.005, 0.0028, 0.6, mph, 255, 255, 255, 255, 6, 1) - DrawAdvancedText(0.174 - x, 0.77 - y, 0.005, 0.0028, 0.6, kmh, 255, 255, 255, 255, 6, 1) - DrawAdvancedText(0.2195 - x, 0.77 - y, 0.005, 0.0028, 0.6, fuel, 255, 255, 255, 255, 6, 1) - DrawAdvancedText(0.148 - x, 0.7765 - y, 0.005, 0.0028, 0.4, "mp/h km/h Fuel", 255, 255, 255, 255, 6, 1) - else - Citizen.Wait(750) - end - - Citizen.Wait(0) - end - end) -end From b35076c56167281da16499caf717a529204d057e Mon Sep 17 00:00:00 2001 From: "ev.vanillaa" <80897991+evanillaa@users.noreply.github.com> Date: Sun, 26 Sep 2021 20:40:35 +0300 Subject: [PATCH 14/31] Update config.lua --- config.lua | 3 --- 1 file changed, 3 deletions(-) diff --git a/config.lua b/config.lua index 68f6dc6..e8ad107 100644 --- a/config.lua +++ b/config.lua @@ -10,9 +10,6 @@ Config.FuelDecor = "_FUEL_LEVEL" -- What keys are disabled while you're fueling. Config.DisableKeys = {0, 22, 23, 24, 29, 30, 31, 37, 44, 56, 82, 140, 166, 167, 168, 170, 288, 289, 311, 323} --- Want to use the HUD? Turn this to true. -Config.EnableHUD = false - -- Configure blips here. Turn both to false to disable blips all together. Config.ShowNearestGasStationOnly = true Config.ShowAllGasStations = false From bff87b3a8dccd319a925643fba57be135356456a Mon Sep 17 00:00:00 2001 From: darknight2590 <87971656+darknight2590@users.noreply.github.com> Date: Tue, 12 Oct 2021 11:25:05 +0300 Subject: [PATCH 15/31] The price is changing Adding a new economic variable cost The price is changing --- source/fuel_client.lua | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/source/fuel_client.lua b/source/fuel_client.lua index ba5cbdb..16fa9b1 100644 --- a/source/fuel_client.lua +++ b/source/fuel_client.lua @@ -2,7 +2,8 @@ local isNearPump = false local isFueling = false local currentFuel = 0.0 local currentCost = 0.0 -local currentCash = 1000 +local todaycoast = 0 +local currentCash = 0 local fuelSynced = false local inBlacklisted = false @@ -89,7 +90,7 @@ AddEventHandler('fuel:startFuelUpTick', function(pumpObject, ped, vehicle) local oldFuel = DecorGetFloat(vehicle, Config.FuelDecor) local fuelToAdd = math.random(10, 20) / 10.0 - local extraCost = fuelToAdd / 1.5 * Config.CostMultiplier + --local extraCost = fuelToAdd / 1.5 * Config.CostMultiplier if not pumpObject then if GetAmmoInPedWeapon(ped, 883325847) - fuelToAdd * 100 >= 0 then @@ -108,8 +109,9 @@ AddEventHandler('fuel:startFuelUpTick', function(pumpObject, ped, vehicle) isFueling = false end - currentCost = currentCost + extraCost - + if extraCost >= 1 then + currentCost = currentCost + extraCost + todaycoast = extraCost if currentCash >= currentCost then SetFuel(vehicle, currentFuel) else @@ -118,7 +120,7 @@ AddEventHandler('fuel:startFuelUpTick', function(pumpObject, ped, vehicle) end if pumpObject then - TriggerServerEvent('fuel:pay', currentCost, GetPlayerServerId(PlayerId())) + TriggerServerEvent('fuel:pay', currentCost) end currentCost = 0.0 @@ -142,10 +144,11 @@ AddEventHandler('fuel:refuelFromPump', function(pumpObject, ped, vehicle) if pumpObject then local stringCoords = GetEntityCoords(pumpObject) - local extraString = "\n" .. Config.Strings.TotalCost .. ": ~g~$" .. Round(currentCost, 1) + local extraString = "\n" .. Config.Strings.TotalCost .. ": ~g~$" .. Round(todaycoast, 1) DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.CancelFuelingPump .. extraString) DrawText3Ds(vehicleCoords.x, vehicleCoords.y, vehicleCoords.z + 0.5, Round(currentFuel, 1) .. "%") + DrawText3Ds(vehicleCoords.x, vehicleCoords.y, vehicleCoords.z + 1.3, Round(currentCost, 1) .. '~b~$~w~ cost') else DrawText3Ds(vehicleCoords.x, vehicleCoords.y, vehicleCoords.z + 0.5, Config.Strings.CancelFuelingJerryCan .. "\nGas can: ~g~" .. Round(GetAmmoInPedWeapon(ped, 883325847) / 4500 * 100, 1) .. "% | Vehicle: " .. Round(currentFuel, 1) .. "%") end From 50ee63442b2008cc53a6f58a21513a7eff403551 Mon Sep 17 00:00:00 2001 From: darknight2590 <87971656+darknight2590@users.noreply.github.com> Date: Mon, 25 Oct 2021 13:44:47 +0300 Subject: [PATCH 16/31] Update fuel_client.lua --- source/fuel_client.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/fuel_client.lua b/source/fuel_client.lua index 16fa9b1..4ba471c 100644 --- a/source/fuel_client.lua +++ b/source/fuel_client.lua @@ -2,7 +2,7 @@ local isNearPump = false local isFueling = false local currentFuel = 0.0 local currentCost = 0.0 -local todaycoast = 0 +local todaycost = 0 local currentCash = 0 local fuelSynced = false local inBlacklisted = false @@ -109,9 +109,9 @@ AddEventHandler('fuel:startFuelUpTick', function(pumpObject, ped, vehicle) isFueling = false end - if extraCost >= 1 then + if extraCost >= 1 then currentCost = currentCost + extraCost - todaycoast = extraCost + todaycost = extraCost if currentCash >= currentCost then SetFuel(vehicle, currentFuel) else @@ -144,7 +144,7 @@ AddEventHandler('fuel:refuelFromPump', function(pumpObject, ped, vehicle) if pumpObject then local stringCoords = GetEntityCoords(pumpObject) - local extraString = "\n" .. Config.Strings.TotalCost .. ": ~g~$" .. Round(todaycoast, 1) + local extraString = "\n" .. Config.Strings.TotalCost .. ": ~g~$" .. Round(todaycost, 1) DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.CancelFuelingPump .. extraString) DrawText3Ds(vehicleCoords.x, vehicleCoords.y, vehicleCoords.z + 0.5, Round(currentFuel, 1) .. "%") From 6b14c67a9440fab7807fd455474549fb9ed07359 Mon Sep 17 00:00:00 2001 From: vanillaa <80897991+evanillaa@users.noreply.github.com> Date: Sat, 6 Nov 2021 19:19:48 +0200 Subject: [PATCH 17/31] add coords --- config.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/config.lua b/config.lua index e8ad107..f4e260a 100644 --- a/config.lua +++ b/config.lua @@ -123,5 +123,6 @@ Config.GasStations = { vector3(176.631, -1562.025, 29.263), vector3(176.631, -1562.025, 29.263), vector3(-319.292, -1471.715, 30.549), + vector3(-66.48, -2532.57, 6.14), vector3(1784.324, 3330.55, 41.253) } From cde0f4632c0b96535d5e5db4c03a270ede931278 Mon Sep 17 00:00:00 2001 From: vanillaa <80897991+evanillaa@users.noreply.github.com> Date: Sun, 7 Nov 2021 07:58:14 +0200 Subject: [PATCH 18/31] refactor event --- source/fuel_server.lua | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/source/fuel_server.lua b/source/fuel_server.lua index 0703dc9..c16fde9 100644 --- a/source/fuel_server.lua +++ b/source/fuel_server.lua @@ -1,9 +1,8 @@ -RegisterServerEvent('fuel:pay') -AddEventHandler('fuel:pay', function(price, source) - local xPlayer = QBCore.Functions.GetPlayer(source) +RegisterNetEvent('fuel:pay', function(price, source) + local Player = QBCore.Functions.GetPlayer(source) local amount = math.floor(price + 0.5) if price > 0 then - xPlayer.Functions.RemoveMoney('cash', amount) + Player.Functions.RemoveMoney('cash', amount) end end) From 591a08d0f333f92c6b0f9ef37875d43bb0aa656b Mon Sep 17 00:00:00 2001 From: vanillaa <80897991+evanillaa@users.noreply.github.com> Date: Sun, 7 Nov 2021 07:58:52 +0200 Subject: [PATCH 19/31] Update functions_client.lua --- functions/functions_client.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/functions_client.lua b/functions/functions_client.lua index b3df7e1..475ee9d 100644 --- a/functions/functions_client.lua +++ b/functions/functions_client.lua @@ -14,7 +14,7 @@ function LoadAnimDict(dict) RequestAnimDict(dict) while not HasAnimDictLoaded(dict) do - Citizen.Wait(1) + Wait(1) end end end From a46f9023c44205ebb937745154dfc8f54649a87d Mon Sep 17 00:00:00 2001 From: vanillaa <80897991+evanillaa@users.noreply.github.com> Date: Sun, 7 Nov 2021 07:59:24 +0200 Subject: [PATCH 20/31] Update fuel_client.lua --- source/fuel_client.lua | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/source/fuel_client.lua b/source/fuel_client.lua index 282987e..0043fa9 100644 --- a/source/fuel_client.lua +++ b/source/fuel_client.lua @@ -20,7 +20,7 @@ function ManageFuelUsage(vehicle) end end -Citizen.CreateThread(function() +CreateThread(function() DecorRegister(Config.FuelDecor, 1) for index = 1, #Config.Blacklist do @@ -36,7 +36,7 @@ Citizen.CreateThread(function() end while true do - Citizen.Wait(1000) + Wait(1000) local ped = PlayerPedId() @@ -64,9 +64,9 @@ Citizen.CreateThread(function() end end) -Citizen.CreateThread(function() +CreateThread(function() while true do - Citizen.Wait(250) + Wait(250) local pumpObject, pumpDistance = FindNearestFuelPump() @@ -76,7 +76,7 @@ Citizen.CreateThread(function() else isNearPump = false - Citizen.Wait(math.ceil(pumpDistance * 20)) + Wait(math.ceil(pumpDistance * 20)) end end end) @@ -85,7 +85,7 @@ AddEventHandler('fuel:startFuelUpTick', function(pumpObject, ped, vehicle) currentFuel = GetVehicleFuelLevel(vehicle) while isFueling do - Citizen.Wait(500) + Wait(500) local oldFuel = DecorGetFloat(vehicle, Config.FuelDecor) local fuelToAdd = math.random(10, 20) / 10.0 @@ -126,7 +126,7 @@ end) AddEventHandler('fuel:refuelFromPump', function(pumpObject, ped, vehicle) TaskTurnPedToFaceEntity(ped, vehicle, 1000) - Citizen.Wait(1000) + Wait(1000) SetCurrentPedWeapon(ped, -1569615261, true) LoadAnimDict("timetable@gardener@filling_can") TaskPlayAnim(ped, "timetable@gardener@filling_can", "gar_ig_5_filling_can", 2.0, 8.0, -1, 50, 0, 0, 0, 0) @@ -158,14 +158,14 @@ AddEventHandler('fuel:refuelFromPump', function(pumpObject, ped, vehicle) isFueling = false end - Citizen.Wait(0) + Wait(0) end ClearPedTasks(ped) RemoveAnimDict("timetable@gardener@filling_can") end) -Citizen.CreateThread(function() +CreateThread(function() while true do local ped = PlayerPedId() @@ -245,19 +245,19 @@ Citizen.CreateThread(function() DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.NotEnoughCash) end else - Citizen.Wait(250) + Wait(250) end end else - Citizen.Wait(250) + Wait(250) end - Citizen.Wait(0) + Wait(0) end end) if Config.ShowNearestGasStationOnly then - Citizen.CreateThread(function() + CreateThread(function() local currentGasBlip = 0 while true do @@ -280,11 +280,11 @@ if Config.ShowNearestGasStationOnly then currentGasBlip = CreateBlip(closestCoords) - Citizen.Wait(10000) + Wait(10000) end end) elseif Config.ShowAllGasStations then - Citizen.CreateThread(function() + CreateThread(function() for _, gasStationCoords in pairs(Config.GasStations) do CreateBlip(gasStationCoords) end From 87280e9d5ce6b7cfead5bb31e8622a8b32cb9654 Mon Sep 17 00:00:00 2001 From: Kakarot <57848836+GhzGarage@users.noreply.github.com> Date: Wed, 10 Nov 2021 01:09:40 -0600 Subject: [PATCH 21/31] export --- config.lua | 5 ++-- fxmanifest.lua | 5 +--- source/fuel_client.lua | 64 ++++++++++++++++++++++++++++++++++++++++++ source/fuel_server.lua | 9 ++++-- 4 files changed, 74 insertions(+), 9 deletions(-) diff --git a/config.lua b/config.lua index f4e260a..0712ed0 100644 --- a/config.lua +++ b/config.lua @@ -10,6 +10,9 @@ Config.FuelDecor = "_FUEL_LEVEL" -- What keys are disabled while you're fueling. Config.DisableKeys = {0, 22, 23, 24, 29, 30, 31, 37, 44, 56, 82, 140, 166, 167, 168, 170, 288, 289, 311, 323} +-- Want to use the HUD? Turn this to true. +Config.EnableHUD = false + -- Configure blips here. Turn both to false to disable blips all together. Config.ShowNearestGasStationOnly = true Config.ShowAllGasStations = false @@ -31,8 +34,6 @@ Config.Strings = { NotEnoughCashJerryCan = "Not enough cash to refill jerry can", JerryCanFull = "Jerry can is full", TotalCost = "Cost", - PurchaseJerryCan = "Press ~g~E ~w~to grab a jerry can", - RefillJerryCan = "Press ~g~E ~w~ to refill the jerry can", } Config.PumpModels = { diff --git a/fxmanifest.lua b/fxmanifest.lua index 996ffa6..d8414b2 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -5,10 +5,7 @@ author 'InZidiuZ' description 'Legacy Fuel' version '1.3' -shared_scripts { - '@qb-core/import.lua', - 'config.lua' -} +shared_script 'config.lua' client_scripts { 'functions/functions_client.lua', diff --git a/source/fuel_client.lua b/source/fuel_client.lua index 0043fa9..bafea6c 100644 --- a/source/fuel_client.lua +++ b/source/fuel_client.lua @@ -1,3 +1,4 @@ +local QBCore = exports['qb-core']:GetCoreObject() local isNearPump = false local isFueling = false local currentFuel = 0.0 @@ -290,3 +291,66 @@ elseif Config.ShowAllGasStations then end end) end + +if Config.EnableHUD then + local function DrawAdvancedText(x,y ,w,h,sc, text, r,g,b,a,font,jus) + SetTextFont(font) + SetTextProportional(0) + SetTextScale(sc, sc) + N_0x4e096588b13ffeca(jus) + SetTextColour(r, g, b, a) + SetTextDropShadow(0, 0, 0, 0,255) + SetTextEdge(1, 0, 0, 0, 255) + SetTextDropShadow() + SetTextOutline() + SetTextEntry("STRING") + AddTextComponentString(text) + DrawText(x - 0.1+w, y - 0.02+h) + end + + local mph = 0 + local kmh = 0 + local fuel = 0 + local displayHud = false + + local x = 0.01135 + local y = 0.002 + + CreateThread(function() + while true do + local ped = PlayerPedId() + + if IsPedInAnyVehicle(ped) and not (Config.RemoveHUDForBlacklistedVehicle and inBlacklisted) then + local vehicle = GetVehiclePedIsIn(ped) + local speed = GetEntitySpeed(vehicle) + + mph = tostring(math.ceil(speed * 2.236936)) + kmh = tostring(math.ceil(speed * 3.6)) + fuel = tostring(math.ceil(GetVehicleFuelLevel(vehicle))) + + displayHud = true + else + displayHud = false + + Wait(500) + end + + Wait(50) + end + end) + + CreateThread(function() + while true do + if displayHud then + DrawAdvancedText(0.130 - x, 0.77 - y, 0.005, 0.0028, 0.6, mph, 255, 255, 255, 255, 6, 1) + DrawAdvancedText(0.174 - x, 0.77 - y, 0.005, 0.0028, 0.6, kmh, 255, 255, 255, 255, 6, 1) + DrawAdvancedText(0.2195 - x, 0.77 - y, 0.005, 0.0028, 0.6, fuel, 255, 255, 255, 255, 6, 1) + DrawAdvancedText(0.148 - x, 0.7765 - y, 0.005, 0.0028, 0.4, "mp/h km/h Fuel", 255, 255, 255, 255, 6, 1) + else + Wait(750) + end + + Wait(0) + end + end) +end diff --git a/source/fuel_server.lua b/source/fuel_server.lua index c16fde9..34460b3 100644 --- a/source/fuel_server.lua +++ b/source/fuel_server.lua @@ -1,8 +1,11 @@ -RegisterNetEvent('fuel:pay', function(price, source) - local Player = QBCore.Functions.GetPlayer(source) +local QBCore = exports['qb-core']:GetCoreObject() + +RegisterServerEvent('fuel:pay') +AddEventHandler('fuel:pay', function(price, source) + local xPlayer = QBCore.Functions.GetPlayer(source) local amount = math.floor(price + 0.5) if price > 0 then - Player.Functions.RemoveMoney('cash', amount) + xPlayer.Functions.RemoveMoney('cash', amount) end end) From d6e98ec307fc13bab045622997db87d5588d39cd Mon Sep 17 00:00:00 2001 From: vanillaa <80897991+evanillaa@users.noreply.github.com> Date: Wed, 10 Nov 2021 21:02:04 +0200 Subject: [PATCH 22/31] clear --- config.lua | 3 --- 1 file changed, 3 deletions(-) diff --git a/config.lua b/config.lua index 0712ed0..5d8fd80 100644 --- a/config.lua +++ b/config.lua @@ -10,9 +10,6 @@ Config.FuelDecor = "_FUEL_LEVEL" -- What keys are disabled while you're fueling. Config.DisableKeys = {0, 22, 23, 24, 29, 30, 31, 37, 44, 56, 82, 140, 166, 167, 168, 170, 288, 289, 311, 323} --- Want to use the HUD? Turn this to true. -Config.EnableHUD = false - -- Configure blips here. Turn both to false to disable blips all together. Config.ShowNearestGasStationOnly = true Config.ShowAllGasStations = false From fa9922339d2ed024c0174cb53f284cff80dc5d62 Mon Sep 17 00:00:00 2001 From: vanillaa <80897991+evanillaa@users.noreply.github.com> Date: Wed, 10 Nov 2021 21:02:39 +0200 Subject: [PATCH 23/31] clear up --- source/fuel_client.lua | 63 ------------------------------------------ 1 file changed, 63 deletions(-) diff --git a/source/fuel_client.lua b/source/fuel_client.lua index bafea6c..9274633 100644 --- a/source/fuel_client.lua +++ b/source/fuel_client.lua @@ -291,66 +291,3 @@ elseif Config.ShowAllGasStations then end end) end - -if Config.EnableHUD then - local function DrawAdvancedText(x,y ,w,h,sc, text, r,g,b,a,font,jus) - SetTextFont(font) - SetTextProportional(0) - SetTextScale(sc, sc) - N_0x4e096588b13ffeca(jus) - SetTextColour(r, g, b, a) - SetTextDropShadow(0, 0, 0, 0,255) - SetTextEdge(1, 0, 0, 0, 255) - SetTextDropShadow() - SetTextOutline() - SetTextEntry("STRING") - AddTextComponentString(text) - DrawText(x - 0.1+w, y - 0.02+h) - end - - local mph = 0 - local kmh = 0 - local fuel = 0 - local displayHud = false - - local x = 0.01135 - local y = 0.002 - - CreateThread(function() - while true do - local ped = PlayerPedId() - - if IsPedInAnyVehicle(ped) and not (Config.RemoveHUDForBlacklistedVehicle and inBlacklisted) then - local vehicle = GetVehiclePedIsIn(ped) - local speed = GetEntitySpeed(vehicle) - - mph = tostring(math.ceil(speed * 2.236936)) - kmh = tostring(math.ceil(speed * 3.6)) - fuel = tostring(math.ceil(GetVehicleFuelLevel(vehicle))) - - displayHud = true - else - displayHud = false - - Wait(500) - end - - Wait(50) - end - end) - - CreateThread(function() - while true do - if displayHud then - DrawAdvancedText(0.130 - x, 0.77 - y, 0.005, 0.0028, 0.6, mph, 255, 255, 255, 255, 6, 1) - DrawAdvancedText(0.174 - x, 0.77 - y, 0.005, 0.0028, 0.6, kmh, 255, 255, 255, 255, 6, 1) - DrawAdvancedText(0.2195 - x, 0.77 - y, 0.005, 0.0028, 0.6, fuel, 255, 255, 255, 255, 6, 1) - DrawAdvancedText(0.148 - x, 0.7765 - y, 0.005, 0.0028, 0.4, "mp/h km/h Fuel", 255, 255, 255, 255, 6, 1) - else - Wait(750) - end - - Wait(0) - end - end) -end From d37e933e0cacca96fa7b61dc287cebb7c5765d1c Mon Sep 17 00:00:00 2001 From: vanillaa <80897991+evanillaa@users.noreply.github.com> Date: Thu, 11 Nov 2021 11:19:32 +0200 Subject: [PATCH 24/31] Update fuel_server.lua --- source/fuel_server.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/source/fuel_server.lua b/source/fuel_server.lua index 34460b3..3185f69 100644 --- a/source/fuel_server.lua +++ b/source/fuel_server.lua @@ -1,7 +1,6 @@ local QBCore = exports['qb-core']:GetCoreObject() -RegisterServerEvent('fuel:pay') -AddEventHandler('fuel:pay', function(price, source) +RegisterNetEvent('fuel:pay', function(price, source) local xPlayer = QBCore.Functions.GetPlayer(source) local amount = math.floor(price + 0.5) From d71dc4f2410f0ba6af42ef384e16bb70fb5a501f Mon Sep 17 00:00:00 2001 From: darknight2590 <87971656+darknight2590@users.noreply.github.com> Date: Sun, 21 Nov 2021 20:39:34 +0200 Subject: [PATCH 25/31] fix error --- source/fuel_client.lua | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/source/fuel_client.lua b/source/fuel_client.lua index dca2aa8..ab135c2 100644 --- a/source/fuel_client.lua +++ b/source/fuel_client.lua @@ -83,6 +83,8 @@ CreateThread(function() end end) +local extraCost = math.random(3, 6) + AddEventHandler('fuel:startFuelUpTick', function(pumpObject, ped, vehicle) currentFuel = GetVehicleFuelLevel(vehicle) @@ -113,10 +115,11 @@ AddEventHandler('fuel:startFuelUpTick', function(pumpObject, ped, vehicle) if extraCost >= 1 then currentCost = currentCost + extraCost todaycost = extraCost - if currentCash >= currentCost then - SetFuel(vehicle, currentFuel) - else - isFueling = false + if currentCash >= currentCost then + SetFuel(vehicle, currentFuel) + else + isFueling = false + end end end From 65b6c069fa15d585da4a5cdf125a3b320bbfaee9 Mon Sep 17 00:00:00 2001 From: darknight2590 <87971656+darknight2590@users.noreply.github.com> Date: Sun, 21 Nov 2021 20:51:25 +0200 Subject: [PATCH 26/31] add GetPlayerServerId --- source/fuel_client.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/fuel_client.lua b/source/fuel_client.lua index ab135c2..4df71e3 100644 --- a/source/fuel_client.lua +++ b/source/fuel_client.lua @@ -124,7 +124,7 @@ AddEventHandler('fuel:startFuelUpTick', function(pumpObject, ped, vehicle) end if pumpObject then - TriggerServerEvent('fuel:pay', currentCost) + TriggerServerEvent('fuel:pay', currentCost, GetPlayerServerId(PlayerId())) end currentCost = 0.0 From 7bda758107f45f6f91d17fc431f94558c4d1b2c9 Mon Sep 17 00:00:00 2001 From: BerkieBb <82737367+BerkieBb@users.noreply.github.com> Date: Fri, 19 Aug 2022 16:07:12 +0200 Subject: [PATCH 27/31] tweak(client/functions): add exports here --- functions/functions_client.lua | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/functions/functions_client.lua b/functions/functions_client.lua index 475ee9d..cd7fdf8 100644 --- a/functions/functions_client.lua +++ b/functions/functions_client.lua @@ -2,6 +2,8 @@ function GetFuel(vehicle) return DecorGetFloat(vehicle, Config.FuelDecor) end +exports('GetFuel', GetFuel) + function SetFuel(vehicle, fuel) if type(fuel) == 'number' and fuel >= 0 and fuel <= 100 then SetVehicleFuelLevel(vehicle, fuel + 0.0) @@ -9,13 +11,14 @@ function SetFuel(vehicle, fuel) end end +exports('SetFuel', SetFuel) + function LoadAnimDict(dict) - if not HasAnimDictLoaded(dict) then - RequestAnimDict(dict) + if HasAnimDictLoaded(dict) then return end + RequestAnimDict(dict) - while not HasAnimDictLoaded(dict) do - Wait(1) - end + while not HasAnimDictLoaded(dict) do + Wait(10) end end @@ -41,7 +44,7 @@ function Round(num, numDecimalPlaces) end function CreateBlip(coords) - local blip = AddBlipForCoord(coords) + local blip = AddBlipForCoord(coords.x, coords.y, coords.z) SetBlipSprite(blip, 361) SetBlipScale(blip, 0.6) From 7568d2b459f7829e954f7154b084404764c8e084 Mon Sep 17 00:00:00 2001 From: BerkieBb <82737367+BerkieBb@users.noreply.github.com> Date: Fri, 19 Aug 2022 16:07:55 +0200 Subject: [PATCH 28/31] tweak(client): fix exploit --- source/fuel_client.lua | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/source/fuel_client.lua b/source/fuel_client.lua index 4df71e3..577a4b1 100644 --- a/source/fuel_client.lua +++ b/source/fuel_client.lua @@ -1,5 +1,5 @@ local QBCore = exports['qb-core']:GetCoreObject() -local isNearPump = false +local isNearPump = nil local isFueling = false local currentFuel = 0.0 local currentCost = 0.0 @@ -42,8 +42,8 @@ CreateThread(function() local ped = PlayerPedId() - if IsPedInAnyVehicle(ped) then - local vehicle = GetVehiclePedIsIn(ped) + if IsPedInAnyVehicle(ped, false) then + local vehicle = GetVehiclePedIsIn(ped, false) if Config.Blacklist[GetEntityModel(vehicle)] then inBlacklisted = true @@ -76,7 +76,7 @@ CreateThread(function() isNearPump = pumpObject currentCash = QBCore.Functions.GetPlayerData().money['cash'] else - isNearPump = false + isNearPump = nil Wait(math.ceil(pumpDistance * 20)) end @@ -124,7 +124,7 @@ AddEventHandler('fuel:startFuelUpTick', function(pumpObject, ped, vehicle) end if pumpObject then - TriggerServerEvent('fuel:pay', currentCost, GetPlayerServerId(PlayerId())) + TriggerServerEvent('fuel:pay', currentCost) end currentCost = 0.0 @@ -135,13 +135,13 @@ AddEventHandler('fuel:refuelFromPump', function(pumpObject, ped, vehicle) Wait(1000) SetCurrentPedWeapon(ped, -1569615261, true) LoadAnimDict("timetable@gardener@filling_can") - TaskPlayAnim(ped, "timetable@gardener@filling_can", "gar_ig_5_filling_can", 2.0, 8.0, -1, 50, 0, 0, 0, 0) + TaskPlayAnim(ped, "timetable@gardener@filling_can", "gar_ig_5_filling_can", 2.0, 8.0, -1, 50, 0, false, false, false) TriggerEvent('fuel:startFuelUpTick', pumpObject, ped, vehicle) while isFueling do for _, controlIndex in pairs(Config.DisableKeys) do - DisableControlAction(0, controlIndex) + DisableControlAction(0, controlIndex, true) end local vehicleCoords = GetEntityCoords(vehicle) @@ -158,7 +158,7 @@ AddEventHandler('fuel:refuelFromPump', function(pumpObject, ped, vehicle) end if not IsEntityPlayingAnim(ped, "timetable@gardener@filling_can", "gar_ig_5_filling_can", 3) then - TaskPlayAnim(ped, "timetable@gardener@filling_can", "gar_ig_5_filling_can", 2.0, 8.0, -1, 50, 0, 0, 0, 0) + TaskPlayAnim(ped, "timetable@gardener@filling_can", "gar_ig_5_filling_can", 2.0, 8.0, -1, 50, 0, false, false, false) end if IsControlJustReleased(0, 38) or DoesEntityExist(GetPedInVehicleSeat(vehicle, -1)) or (isNearPump and GetEntityHealth(pumpObject) <= 0) then @@ -177,7 +177,7 @@ CreateThread(function() local ped = PlayerPedId() if not isFueling and ((isNearPump and GetEntityHealth(isNearPump) > 0) or (GetSelectedPedWeapon(ped) == 883325847 and not isNearPump)) then - if IsPedInAnyVehicle(ped) and GetPedInVehicleSeat(GetVehiclePedIsIn(ped), -1) == ped then + if IsPedInAnyVehicle(ped, false) and GetPedInVehicleSeat(GetVehiclePedIsIn(ped, false), -1) == ped then local pumpCoords = GetEntityCoords(isNearPump) DrawText3Ds(pumpCoords.x, pumpCoords.y, pumpCoords.z + 1.2, Config.Strings.ExitVehicle) @@ -221,13 +221,13 @@ CreateThread(function() local stringCoords = GetEntityCoords(isNearPump) if currentCash >= Config.JerryCanCost then - if not HasPedGotWeapon(ped, 883325847) then + if not HasPedGotWeapon(ped, 883325847, false) then DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.PurchaseJerryCan) if IsControlJustReleased(0, 38) then - TriggerServerEvent('QBCore:Server:AddItem', "weapon_petrolcan", 1) + TriggerServerEvent('fuel:addPetrolCan') TriggerEvent("inventory:client:ItemBox", QBCore.Shared.Items["weapon_petrolcan"], "add") - TriggerServerEvent('fuel:pay', Config.JerryCanCost, GetPlayerServerId(PlayerId())) + TriggerServerEvent('fuel:pay', Config.JerryCanCost) end else local refillCost = Round(Config.RefillCost * (1 - GetAmmoInPedWeapon(ped, 883325847) / 4500)) @@ -237,7 +237,7 @@ CreateThread(function() DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.RefillJerryCan .. refillCost) if IsControlJustReleased(0, 38) then - TriggerServerEvent('fuel:pay', refillCost, GetPlayerServerId(PlayerId())) + TriggerServerEvent('fuel:pay', refillCost) SetPedAmmo(ped, 883325847, 4500) end From b6d93253b94ea26e93ed91ff1dcee03a90f077cc Mon Sep 17 00:00:00 2001 From: BerkieBb <82737367+BerkieBb@users.noreply.github.com> Date: Fri, 19 Aug 2022 16:08:26 +0200 Subject: [PATCH 29/31] fix(server): add event to fix exploit --- source/fuel_server.lua | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/source/fuel_server.lua b/source/fuel_server.lua index 3185f69..67e6626 100644 --- a/source/fuel_server.lua +++ b/source/fuel_server.lua @@ -1,10 +1,18 @@ local QBCore = exports['qb-core']:GetCoreObject() -RegisterNetEvent('fuel:pay', function(price, source) - local xPlayer = QBCore.Functions.GetPlayer(source) +RegisterNetEvent('fuel:pay', function(price) + local Player = QBCore.Functions.GetPlayer(source) local amount = math.floor(price + 0.5) - if price > 0 then - xPlayer.Functions.RemoveMoney('cash', amount) - end + if not Player or price <= 0 then return end + + Player.Functions.RemoveMoney('cash', amount) +end) + +RegisterNetEvent('fuel:addPetrolCan', function() + local Player = QBCore.Functions.GetPlayer(source) + + if not Player then return end + + Player.Functions.AddItem('weapon_petrolcan', 1) end) From cfb5029bbea8d94f6a72931547956e7d3d2342ca Mon Sep 17 00:00:00 2001 From: BerkieBb <82737367+BerkieBb@users.noreply.github.com> Date: Fri, 19 Aug 2022 16:09:00 +0200 Subject: [PATCH 30/31] chore(manifest): remove exports and add lua54 --- fxmanifest.lua | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/fxmanifest.lua b/fxmanifest.lua index d8414b2..98ca171 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -1,4 +1,4 @@ -fx_version 'bodacious' +fx_version 'cerulean' game 'gta5' author 'InZidiuZ' @@ -16,7 +16,4 @@ server_scripts { 'source/fuel_server.lua' } -exports { - 'GetFuel', - 'SetFuel' -} +lua54 'yes' From b5fc59a0a5686790f77592d85367749e4b2d873d Mon Sep 17 00:00:00 2001 From: BerkieBb <82737367+BerkieBb@users.noreply.github.com> Date: Sat, 20 Aug 2022 09:34:30 +0200 Subject: [PATCH 31/31] fix(client): closestCoords being nil --- source/fuel_client.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/fuel_client.lua b/source/fuel_client.lua index 577a4b1..5ddab32 100644 --- a/source/fuel_client.lua +++ b/source/fuel_client.lua @@ -285,7 +285,7 @@ if Config.ShowNearestGasStationOnly then RemoveBlip(currentGasBlip) end - currentGasBlip = CreateBlip(closestCoords) + if closestCoords then currentGasBlip = CreateBlip(closestCoords) end Wait(10000) end