Skip to content

Commit

Permalink
refactor: combine saving vehicle props and update vehicle into into o…
Browse files Browse the repository at this point in the history
…ne callback (#44)

* refactor: combine saving vehicle props and update vehicle into one callback

* fix plate from props
  • Loading branch information
Manason authored Apr 29, 2024
1 parent 344ea16 commit 2be32f1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 22 deletions.
7 changes: 1 addition & 6 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 4 additions & 16 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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), props.plate})
end)

RegisterNetEvent('qb-garage:server:updateVehicleState', function(state, plate, garage)
Expand Down

0 comments on commit 2be32f1

Please sign in to comment.