Skip to content

Commit

Permalink
refactor(server): extract vehicle keys function to config (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
solareon authored Sep 29, 2024
1 parent dfcde89 commit 53204a4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
9 changes: 8 additions & 1 deletion config/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,12 @@ return {
preventSelling = false, -- prevents players from using /transfervehicle if financed
},
saleTimeout = 60000, -- Delay between attempts to sell/gift a vehicle. Prevents abuse
deleteUnpaidFinancedVehicle = false -- true to delete unpaid vehicles from database, otherwise it will edit citizenid to hide from db select
deleteUnpaidFinancedVehicle = false, -- true to delete unpaid vehicles from database, otherwise it will edit citizenid to hide from db select

---@param src number Player Server ID
---@param plate string Vehicle Plate
---@param vehicle number Vehicle Entity ID
giveKeys = function(src, plate, vehicle)
exports.qbx_vehiclekeys:GiveKeys(src, vehicle)
end
}
18 changes: 9 additions & 9 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,13 @@ end)
---@return number|nil
local function spawnVehicle(src, data)
local coords, vehicleId = data.coords, data.vehicleId
local vehicle = vehicleId and qbx_vehicles:GetPlayerVehicle(vehicleId) or data
if not vehicle then return end
local newVehicle = vehicleId and qbx_vehicles:GetPlayerVehicle(vehicleId) or data
if not newVehicle then return end

local plate = vehicle.plate or vehicle.props.plate
local plate = newVehicle.plate or newVehicle.props.plate

local netId, veh = qbx.spawnVehicle({
model = vehicle.modelName,
local netId, vehicle = qbx.spawnVehicle({
model = newVehicle.modelName,
spawnSource = coords,
warp = GetPlayerPed(src),
props = {
Expand All @@ -301,11 +301,11 @@ local function spawnVehicle(src, data)

if not netId or netId == 0 then return end

if not veh or veh == 0 then return end
if not vehicle or vehicle == 0 then return end

if vehicleId then Entity(veh).state:set('vehicleid', vehicleId, false) end
if vehicleId then Entity(vehicle).state:set('vehicleid', vehicleId, false) end

TriggerClientEvent('vehiclekeys:client:SetOwner', src, plate)
config.giveKeys(src, plate, vehicle)

return netId
end
Expand Down Expand Up @@ -707,7 +707,7 @@ lib.addCommand('transfervehicle', {
end

qbx_vehicles:SetPlayerVehicleOwner(row.id, targetcid)
TriggerClientEvent('vehiclekeys:client:SetOwner', buyerId, row.props.plate)
config.giveKeys(buyerId, row.plate, vehicle)

local sellerMessage = sellAmount > 0 and locale('success.soldfor') .. lib.math.groupdigits(sellAmount) or locale('success.gifted')
local buyerMessage = sellAmount > 0 and locale('success.boughtfor') .. lib.math.groupdigits(sellAmount) or locale('success.received_gift')
Expand Down

0 comments on commit 53204a4

Please sign in to comment.