From 6dfdad60a123fb96dddd39f82208e0813125b5dc Mon Sep 17 00:00:00 2001 From: Jared Date: Fri, 3 Nov 2023 18:40:32 -0400 Subject: [PATCH 1/3] feature/add-fill-full-tank-payment-option --- client/fuel_cl.lua | 96 +++++++++++++++++++++++++++++++++------------- locales/en.lua | 4 +- server/fuel_sv.lua | 15 +++++++- shared/config.lua | 2 + 4 files changed, 88 insertions(+), 29 deletions(-) diff --git a/client/fuel_cl.lua b/client/fuel_cl.lua index aba327b..95f918a 100644 --- a/client/fuel_cl.lua +++ b/client/fuel_cl.lua @@ -583,6 +583,7 @@ RegisterNetEvent('cdn-fuel:client:FinalMenu', function(purchasetype) if Config.FuelDebug then print('cdn-fuel:client:FinalMenu', purchasetype) end + -- TODO Handle purchaseType of `full` if RefuelingType == nil then FetchStationInfo("all") Wait(Config.WaitTime) @@ -596,6 +597,18 @@ RegisterNetEvent('cdn-fuel:client:FinalMenu', function(purchasetype) end end local money = nil + if purchasetype == "full" then + if Config.FillUpWithBank then + money = QBCore.Functions.GetPlayerData().money['bank'] + end + if Config.FillUpWithCash then + if money == nil then + money = QBCore.Functions.GetPlayerData().money['cash'] + else + money = money + QBCore.Functions.GetPlayerData().money['cash'] + end + end + end if purchasetype == "bank" then money = QBCore.Functions.GetPlayerData().money['bank'] elseif purchasetype == 'cash' then money = QBCore.Functions.GetPlayerData().money['cash'] end if not Config.PlayerOwnedGasStationsEnabled then FuelPrice = (1 * Config.CostMultiplier) @@ -684,24 +697,34 @@ RegisterNetEvent('cdn-fuel:client:FinalMenu', function(purchasetype) if not fuel then if Config.FuelDebug then print("Fuel Is Nil! #1") end return end fuelAmount = tonumber(fuel[5]) else + if (purchasetype ~= "full") then + fuel = lib.inputDialog('Gas Station', { + { type = "input", label = 'Gasoline Price', default = '$'.. FuelPrice .. ' Per Liter', disabled = true }, + { type = "input", label = 'Current Fuel', default = finalfuel .. ' Per Liter', disabled = true }, + { type = "input", label = 'Required For A Full Tank', default = maxfuel, disabled = true }, + { type = "slider", label = 'Full Tank Cost: $' ..wholetankcostwithtax.. '', default = maxfuel, min = 0, max = maxfuel }, + }) + if not fuel then if Config.FuelDebug then print("Fuel Is Nil! #2") end return end + fuelAmount = tonumber(fuel[4]) + else + -- They want to fill up the tank completely... + fuelAmount = maxfuel; + end + end + else + if (purchasetype ~= "full") then fuel = lib.inputDialog('Gas Station', { - { type = "input", label = 'Gasoline Price', default = '$'.. FuelPrice .. ' Per Liter', disabled = true }, - { type = "input", label = 'Current Fuel', default = finalfuel .. ' Per Liter', disabled = true }, + { type = "input", label = 'Gasoline Price', default = '$'.. FuelPrice .. ' Per Liter',disabled = true }, + { type = "input", label = 'Current Fuel', default = finalfuel .. ' Per Liter',disabled = true }, { type = "input", label = 'Required For A Full Tank', default = maxfuel, disabled = true }, - { type = "slider", label = 'Full Tank Cost: $' ..wholetankcostwithtax.. '', default = maxfuel, min = 0, max = maxfuel }, - }) - if not fuel then if Config.FuelDebug then print("Fuel Is Nil! #2") end return end + { type = "slider", label = 'Full Tank Cost: $' ..wholetankcostwithtax.. '', default = maxfuel, min = 0, max = maxfuel}, + }); + if not fuel then if Config.FuelDebug then print("Fuel Is Nil! #3") end return end fuelAmount = tonumber(fuel[4]) + else + -- They want to fill up the tank completely... + fuelAmount = maxfuel; end - else - fuel = lib.inputDialog('Gas Station', { - { type = "input", label = 'Gasoline Price', default = '$'.. FuelPrice .. ' Per Liter',disabled = true }, - { type = "input", label = 'Current Fuel', default = finalfuel .. ' Per Liter',disabled = true }, - { type = "input", label = 'Required For A Full Tank', default = maxfuel, disabled = true }, - { type = "slider", label = 'Full Tank Cost: $' ..wholetankcostwithtax.. '', default = maxfuel, min = 0, max = maxfuel}, - }) - if not fuel then if Config.FuelDebug then print("Fuel Is Nil! #3") end return end - fuelAmount = tonumber(fuel[4]) end if fuel then if not fuelAmount then print("Fuel Amount Nil") return end @@ -743,6 +766,26 @@ RegisterNetEvent('cdn-fuel:client:FinalMenu', function(purchasetype) }} }) else + if (purchasetype ~= "full") then + fuel = exports['qb-input']:ShowInput({ + header = "Select the Amount of Fuel
Current Price: $" .. + FuelPrice .. " / Liter
Current Fuel: " .. finalfuel .. " Liters
Full Tank Cost: $" .. + wholetankcostwithtax .. "", + submitText = Lang:t("input_insert_nozzle"), + inputs = { { + type = 'number', + isRequired = true, + name = 'amount', + text = 'The Tank Can Hold ' .. maxfuel .. ' More Liters.' + }} + }) + else + -- They want to fill up the tank completely... + fuel.amount = maxfuel; + end + end + else + if (purchasetype ~= "full") then fuel = exports['qb-input']:ShowInput({ header = "Select the Amount of Fuel
Current Price: $" .. FuelPrice .. " / Liter
Current Fuel: " .. finalfuel .. " Liters
Full Tank Cost: $" .. @@ -755,20 +798,10 @@ RegisterNetEvent('cdn-fuel:client:FinalMenu', function(purchasetype) text = 'The Tank Can Hold ' .. maxfuel .. ' More Liters.' }} }) + else + -- They want to fill up the tank completely... + fuel.amount = maxfuel; end - else - fuel = exports['qb-input']:ShowInput({ - header = "Select the Amount of Fuel
Current Price: $" .. - FuelPrice .. " / Liter
Current Fuel: " .. finalfuel .. " Liters
Full Tank Cost: $" .. - wholetankcostwithtax .. "", - submitText = Lang:t("input_insert_nozzle"), - inputs = { { - type = 'number', - isRequired = true, - name = 'amount', - text = 'The Tank Can Hold ' .. maxfuel .. ' More Liters.' - }} - }) end if fuel then if not fuel.amount then if Config.FuelDebug then print("fuel.amount = nil") end return end @@ -880,6 +913,15 @@ RegisterNetEvent('cdn-fuel:client:SendMenuToServer', function(type) args = 'bank', } }, + { + header = Lang:t("menu_header_pay_full"), + txt = Lang:t("menu_pay_full"), + icon = "fas fa-fill", + params = { + event = "cdn-fuel:client:FinalMenu", + args = 'full', + } + }, { header = Lang:t("menu_header_close"), txt = Lang:t("menu_refuel_cancel"), diff --git a/locales/en.lua b/locales/en.lua index f9464ec..03f48a8 100644 --- a/locales/en.lua +++ b/locales/en.lua @@ -84,9 +84,11 @@ local Translations = { menu_header_cash = "Cash", menu_header_bank = "Bank", + menu_header_pay_full = "Fill me up", menu_header_close = "Cancel", menu_pay_with_cash = "Pay with cash. \nYou have: $", - menu_pay_with_bank = "Pay with bank.", + menu_pay_with_bank = "Pay with bank.", + menu_pay_full = "Fill up my gas tank fully...", menu_refuel_header = "Gas Station", menu_refuel_accept = "I would like to purchase the fuel.", menu_refuel_cancel = "I actually don't want fuel anymore.", diff --git a/server/fuel_sv.lua b/server/fuel_sv.lua index 0487188..7ff8f43 100644 --- a/server/fuel_sv.lua +++ b/server/fuel_sv.lua @@ -88,9 +88,22 @@ RegisterNetEvent("cdn-fuel:server:PayForFuel", function(amount, purchasetype, Fu elseif purchasetype == "cash" then moneyremovetype = "cash" end + local cash = player.PlayerData.money['cash'] + local bank = player.PlayerData.money['bank'] local payString = Lang:t("menu_pay_label_1") ..FuelPrice..Lang:t("menu_pay_label_2") if electric then payString = Lang:t("menu_electric_payment_label_1") ..FuelPrice..Lang:t("menu_electric_payment_label_2") end - Player.Functions.RemoveMoney(moneyremovetype, total, payString) + if (purchasetype ~= "full") then + Player.Functions.RemoveMoney(moneyremovetype, total, payString) + else + if (total <= cash) then + Player.Functions.RemoveMoney("cash", total, payString) + elseif (total > cash) then + -- Need to take money from bank + total = total - cash; + Player.Functions.RemoveMoney("cash", cash, payString) + Player.Functions.RemoveMoney("bank", total, payString) + end + end end) RegisterNetEvent("cdn-fuel:server:purchase:jerrycan", function(purchasetype) diff --git a/shared/config.lua b/shared/config.lua index e527867..f920806 100644 --- a/shared/config.lua +++ b/shared/config.lua @@ -5,6 +5,8 @@ Config.ShowNearestGasStationOnly = true -- When enabled, only the nearest gas st Config.LeaveEngineRunning = false -- When true, the vehicle's engine will be left running upon exit if the player *HOLDS* F. Config.VehicleBlowUp = true -- When true, there will be a configurable chance of the vehicle blowing up, if you fuel while the engine is on. Config.BlowUpChance = 5 -- Percentage for Chance of Engine Explosion (Default: 5% or 5) +Config.FillUpWithBank = true -- Use player's bank to fill up tank +Config.FillUpWithCash = true -- Use player's cash to fill up tank Config.CostMultiplier = 3 -- Amount to multiply 1 by. This indicates fuel price. (Default: $3.0/l or 3.0) Config.GlobalTax = 15.0 -- The tax, in %, that people will be charged at the pump. (Default: 15% or 15.0) Config.FuelNozzleExplosion = false -- When true, it enables the fuel pump exploding when players run away with the nozzle. Highly recommeded to be false. From c32d725115e7eed2293a269ab15b3a5fe252ece6 Mon Sep 17 00:00:00 2001 From: Jared Date: Fri, 3 Nov 2023 20:48:04 -0400 Subject: [PATCH 2/3] Hot fix --- client/fuel_cl.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/client/fuel_cl.lua b/client/fuel_cl.lua index 95f918a..e54dafc 100644 --- a/client/fuel_cl.lua +++ b/client/fuel_cl.lua @@ -781,6 +781,7 @@ RegisterNetEvent('cdn-fuel:client:FinalMenu', function(purchasetype) }) else -- They want to fill up the tank completely... + fuel = {}; fuel.amount = maxfuel; end end @@ -800,6 +801,7 @@ RegisterNetEvent('cdn-fuel:client:FinalMenu', function(purchasetype) }) else -- They want to fill up the tank completely... + fuel = {}; fuel.amount = maxfuel; end end @@ -950,6 +952,8 @@ RegisterNetEvent('cdn-fuel:client:RefuelVehicle', function(data) purchasetype = data.purchasetype elseif data.purchasetype == "cash" then purchasetype = "cash" + elseif data.purchasetype == "full" then + purchasetype = "full" else purchasetype = RefuelPurchaseType end From 7b8a85b143eb81d111d9e8e1bdc32d54e548c00b Mon Sep 17 00:00:00 2001 From: Jared Date: Wed, 8 Nov 2023 09:41:00 -0500 Subject: [PATCH 3/3] Fix player to Player to work properly --- server/fuel_sv.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/fuel_sv.lua b/server/fuel_sv.lua index 7ff8f43..ec8acb6 100644 --- a/server/fuel_sv.lua +++ b/server/fuel_sv.lua @@ -88,8 +88,8 @@ RegisterNetEvent("cdn-fuel:server:PayForFuel", function(amount, purchasetype, Fu elseif purchasetype == "cash" then moneyremovetype = "cash" end - local cash = player.PlayerData.money['cash'] - local bank = player.PlayerData.money['bank'] + local cash = Player.PlayerData.money['cash'] + local bank = Player.PlayerData.money['bank'] local payString = Lang:t("menu_pay_label_1") ..FuelPrice..Lang:t("menu_pay_label_2") if electric then payString = Lang:t("menu_electric_payment_label_1") ..FuelPrice..Lang:t("menu_electric_payment_label_2") end if (purchasetype ~= "full") then @@ -250,4 +250,4 @@ CreateThread(function() updatePath = "/CodineDev/cdn-fuel" resourceName = "cdn-fuel ("..GetCurrentResourceName()..")" PerformHttpRequest("https://raw.githubusercontent.com"..updatePath.."/master/version", checkVersion, "GET") -end) \ No newline at end of file +end)