From 6e5818c182a0c2778b283bb2d27d30499dd318f9 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 29 Apr 2024 01:17:52 -0700 Subject: [PATCH] refactor: combine saving vehicle props and update vehicle into one callback --- client/main.lua | 7 +------ server/main.lua | 20 ++++---------------- 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/client/main.lua b/client/main.lua index c13e733..9ff0706 100644 --- a/client/main.lua +++ b/client/main.lua @@ -243,12 +243,7 @@ local function parkVehicle(vehicle, garageName, garageInfo) return end - local bodyDamage = math.ceil(GetVehicleBodyHealth(vehicle)) - local engineDamage = math.ceil(GetVehicleEngineHealth(vehicle)) - local totalFuel = GetVehicleFuelLevel(vehicle) - - TriggerServerEvent('qb-vehicletuning:server:SaveVehicleProps', lib.getVehicleProperties(vehicle)) - TriggerServerEvent('qb-garage:server:updateVehicle', 1, totalFuel, engineDamage, bodyDamage, plate, garageName, garageInfo.type, QBX.PlayerData.gang.name) + lib.callback('qbx_garages:server:saveVehicle', false, nil, lib.getVehicleProperties(vehicle), garageName, garageInfo.type, QBX.PlayerData.gang.name) checkPlayers(vehicle) if plate then diff --git a/server/main.lua b/server/main.lua index fd50dbe..c793ed2 100644 --- a/server/main.lua +++ b/server/main.lua @@ -102,28 +102,16 @@ lib.callback.register('qb-garage:server:IsSpawnOk', function(_, plate, type) return true end) -RegisterNetEvent('qb-vehicletuning:server:SaveVehicleProps', function(vehicleProps) - MySQL.update('UPDATE player_vehicles SET mods = ? WHERE plate = ?', - { json.encode(vehicleProps), vehicleProps.plate }) -end) - -RegisterNetEvent('qb-garage:server:updateVehicle', function(state, fuel, engine, body, plate, garage, type, gang) - local owned = checkOwnership(source, plate, type, garage, gang) --Check ownership +lib.callback.register('qbx_garages:server:saveVehicle', function(source, props, garage, type, gang) + local owned = checkOwnership(source, props.plate, type, garage, gang) --Check ownership if not owned then exports.qbx_core:Notify(source, Lang:t('error.not_owned'), 'error') return end - -- Check state value - if state ~= VehicleState.OUT and state ~= VehicleState.GARAGED and state ~= VehicleState.IMPOUNDED then return end + if type ~= 'house' and not sharedConfig.garages[garage] then return end - if type ~= 'house' then - if sharedConfig.garages[garage] then --Check if garage is existing - MySQL.update('UPDATE player_vehicles SET state = ?, garage = ?, fuel = ?, engine = ?, body = ? WHERE plate = ?', {state, garage, fuel, engine, body, plate}) - end - else - MySQL.update('UPDATE player_vehicles SET state = ?, garage = ?, fuel = ?, engine = ?, body = ? WHERE plate = ?', {state, garage, fuel, engine, body, plate}) - end + MySQL.update('UPDATE player_vehicles SET state = ?, garage = ?, fuel = ?, engine = ?, body = ?, mods = ? WHERE plate = ?', {VehicleState.GARAGED, garage, props.fuelLevel, props.engineHealth, props.bodyHealth, json.encode(props), plate}) end) RegisterNetEvent('qb-garage:server:updateVehicleState', function(state, plate, garage)