Skip to content

Commit

Permalink
feat: add confirmation to transfervehicle command
Browse files Browse the repository at this point in the history
  • Loading branch information
solareon committed Dec 21, 2023
1 parent 53b57de commit 25b74cd
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 20 deletions.
12 changes: 12 additions & 0 deletions client/main.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local config = require 'config.client'
local sharedConfig = require 'config.shared'
local VEHICLES = exports.qbx_core:GetVehiclesByName()
local VEHICLES_HASH = exports.qbx_core:GetVehiclesByHash()
local testDriveVeh = 0
local inTestDrive = false
local insideShop = nil
Expand Down Expand Up @@ -622,6 +623,17 @@ RegisterNetEvent('qbx_vehicleshop:client:buyShowroomVehicle', function(vehicle,
TriggerServerEvent('qb-vehicletuning:server:SaveVehicleProps', props)
end)

lib.callback.register('qbx_vehicleshop:client:confirmTrade', function(vehicle, sellAmount)
local input = lib.inputDialog(('Confirm trade of %s %s for $ %s'):format(VEHICLES_HASH[vehicle].brand,VEHICLES_HASH[vehicle].name, CommaValue(sellAmount) or 0),{
{
type = 'checkbox',
label = 'Confirm'
},
})
if not input then return false end
if input[1] == true then return true end
end)

--- Thread to create blips
CreateThread(function()
for _, v in pairs(config.shops) do
Expand Down
1 change: 1 addition & 0 deletions locales/cs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ local Translations = {
notown = "Nevlastnis toto vozidlo",
buyertoopoor = "Kupujuci nema dostatek financi",
nofinanced = "Nemas zadne vozidlo na splatky",
buyerdeclined = "The player declined the transaction",
},
success = {
purchased = "Gratulujeme k vyberu! At slouzi!",
Expand Down
1 change: 1 addition & 0 deletions locales/de.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ local Translations = {
notown = "You don\'t own this vehicle",
buyertoopoor = "The buyer doesn\'t have enough money",
nofinanced = "You don't have any financed vehicles",
buyerdeclined = "The player declined the transaction",
},
success = {
purchased = "Congratulations on your purchase!",
Expand Down
3 changes: 2 additions & 1 deletion locales/en.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ local Translations = {
buyertoopoor = "The buyer doesn\'t have enough money",
nofinanced = "You don't have any financed vehicles",
financed = "This vehicle is financed",
buyerdeclined = "The player declined the transaction",
},
success = {
purchased = "Congratulations on your purchase!",
Expand Down Expand Up @@ -77,7 +78,7 @@ local Translations = {
paymentduein = "Your vehicle payment is due within %{time} minutes",
command_transfervehicle = "Gift or sell your vehicle",
command_transfervehicle_help = "ID of buyer",
command_transfervehicle_amount = "Sell amount (optionnal)",
command_transfervehicle_amount = "Sell amount (optional)",
}
}

Expand Down
1 change: 1 addition & 0 deletions locales/es.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ local Translations = {
buyertoopoor = "El comprador no tiene suficiente dinero",
nofinanced = "No tienes ningún vehículo financiado",
financed = "Este vehículo es financiado",
buyerdeclined = "The player declined the transaction",
},
success = {
purchased = "¡Felicidades por tu compra!",
Expand Down
1 change: 1 addition & 0 deletions locales/fr.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ local Translations = {
buyertoopoor = "L\'acheteur n'a pas assez d'argent",
nofinanced = "Vous n\'avez aucun véhicule financés",
financed = "Ce véhicule est financé",
buyerdeclined = "The player declined the transaction",
},
success = {
purchased = "Félicitations sur votre achat!",
Expand Down
1 change: 1 addition & 0 deletions locales/hu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ local Translations = {
buyertoopoor = "A vásárlónak nem áll rendelkezésre elegendő fizető eszköze",
nofinanced = "Nincsen hitelezett járműved",
financed = "Ez a jármű hitelezett",
buyerdeclined = "The player declined the transaction",
},
success = {
purchased = "Gratulálunk a vásárláshoz!",
Expand Down
1 change: 1 addition & 0 deletions locales/nl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ local Translations = {
buyertoopoor = "De koper heeft onvoldoende saldo",
nofinanced = "Je hebt geen gefinancierde voertuigen",
financed = "Dit voertuig is gefinancierd",
buyerdeclined = "The player declined the transaction",
},
success = {
purchased = "Gefeliciteerd met je nieuwe voertuig!",
Expand Down
1 change: 1 addition & 0 deletions locales/ro.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ local Translations = {
buyertoopoor = "Cumparatorul nu are suficienti bani!",
nofinanced = "Nu ai niciun vehicul cumparat in leasing",
financed = "Acest vehicul este inca in leasing",
buyerdeclined = "The player declined the transaction",
},
success = {
purchased = "Felicitari pentru achizitie!",
Expand Down
41 changes: 22 additions & 19 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -424,10 +424,12 @@ RegisterNetEvent('qbx_vehicleshop:server:checkFinance', function()
end)

-- Transfer vehicle to player in passenger seat
lib.addCommand('transfervehicle', {help = Lang:t('general.command_transfervehicle'), params = {{name = 'id', type = 'playerId', help = Lang:t('general.command_transfervehicle_help')}, {name = 'amount', type = 'number', help = Lang:t('general.command_transfervehicle_amount')}}}, function(source, args)
lib.addCommand('transfervehicle', {help = Lang:t('general.command_transfervehicle'), params = {
{name = 'id', type = 'playerId', help = Lang:t('general.command_transfervehicle_help')},
{name = 'amount', type = 'number', help = Lang:t('general.command_transfervehicle_amount'), optional = true}}}, function(source, args)
local src = source
local buyerId = args.id
local sellAmount = args.amount
local sellAmount = args.amount or 0
if buyerId == 0 then
return exports.qbx_core:Notify(src, Lang:t('error.Invalid_ID'), 'error')
end
Expand Down Expand Up @@ -466,23 +468,24 @@ lib.addCommand('transfervehicle', {help = Lang:t('general.command_transfervehicl
if not target then
return exports.qbx_core:Notify(src, Lang:t('error.buyerinfo'), 'error')
end
if not sellAmount then
lib.callback('qbx_vehicleshop:client:confirmTrade', buyerId, function(approved)
if not approved then
exports.qbx_core:Notify(src, Lang:t('error.buyerdeclined'), 'error')
return
end
if sellAmount > 0 then
local currencyType = findChargeableCurrencyType(sellAmount, target.PlayerData.money.cash, target.PlayerData.money.bank)
if not currencyType then
return exports.qbx_core:Notify(src, Lang:t('error.buyertoopoor'), 'error')
end
player.Functions.AddMoney(currencyType, sellAmount)
target.Functions.RemoveMoney(currencyType, sellAmount)
end
UpdateVehicleEntityOwner(targetcid, targetlicense, plate)
exports.qbx_core:Notify(src, Lang:t('success.gifted'), 'success')
TriggerClientEvent('vehiclekeys:client:SetOwner', buyerId, plate)
exports.qbx_core:Notify(buyerId, Lang:t('success.received_gift'), 'success')
return
end

local currencyType = findChargeableCurrencyType(sellAmount, target.PlayerData.money.cash, target.PlayerData.money.bank)
if not currencyType then
return exports.qbx_core:Notify(src, Lang:t('error.buyertoopoor'), 'error')
end

UpdateVehicleEntityOwner(targetcid, targetlicense, plate)
player.Functions.AddMoney(currencyType, sellAmount)
target.Functions.RemoveMoney(currencyType, sellAmount)
exports.qbx_core:Notify(src, Lang:t('success.soldfor')..CommaValue(sellAmount), 'success')
TriggerClientEvent('vehiclekeys:client:SetOwner', buyerId, plate)
exports.qbx_core:Notify(buyerId, Lang:t('success.boughtfor')..CommaValue(sellAmount), 'success')
local sellerMessage = sellAmount > 0 and Lang:t('success.soldfor') .. CommaValue(sellAmount) or Lang:t('success.gifted')
local buyerMessage = sellAmount > 0 and Lang:t('success.boughtfor') .. CommaValue(sellAmount) or Lang:t('success.received_gift')
exports.qbx_core:Notify(src, sellerMessage, 'success')
exports.qbx_core:Notify(buyerId, buyerMessage, 'success')
end, GetEntityModel(vehicle), sellAmount)
end)

0 comments on commit 25b74cd

Please sign in to comment.