Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/add-fill-full-tank-payment-option #88

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 73 additions & 27 deletions client/fuel_cl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -743,6 +766,27 @@ RegisterNetEvent('cdn-fuel:client:FinalMenu', function(purchasetype)
}}
})
else
if (purchasetype ~= "full") then
fuel = exports['qb-input']:ShowInput({
header = "Select the Amount of Fuel<br>Current Price: $" ..
FuelPrice .. " / Liter <br> Current Fuel: " .. finalfuel .. " Liters <br> 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 = {};
fuel.amount = maxfuel;
end
end
else
if (purchasetype ~= "full") then
fuel = exports['qb-input']:ShowInput({
header = "Select the Amount of Fuel<br>Current Price: $" ..
FuelPrice .. " / Liter <br> Current Fuel: " .. finalfuel .. " Liters <br> Full Tank Cost: $" ..
Expand All @@ -755,20 +799,11 @@ 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 = {};
fuel.amount = maxfuel;
end
else
fuel = exports['qb-input']:ShowInput({
header = "Select the Amount of Fuel<br>Current Price: $" ..
FuelPrice .. " / Liter <br> Current Fuel: " .. finalfuel .. " Liters <br> 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
Expand Down Expand Up @@ -880,6 +915,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"),
Expand Down Expand Up @@ -908,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
Expand Down
4 changes: 3 additions & 1 deletion locales/en.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
17 changes: 15 additions & 2 deletions server/fuel_sv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -237,4 +250,4 @@ CreateThread(function()
updatePath = "/CodineDev/cdn-fuel"
resourceName = "cdn-fuel ("..GetCurrentResourceName()..")"
PerformHttpRequest("https://raw.githubusercontent.com"..updatePath.."/master/version", checkVersion, "GET")
end)
end)
2 changes: 2 additions & 0 deletions shared/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down