okokGarage

// sv_utils.lua

add this at the end of the file

lib.callback.register('okokGarage:server:check-persistence-takeout', function(source, plate)
    if plate then
        local result = MySQL.query.await('SELECT persist FROM rx56_permvehicles WHERE plate = ?', {plate})
        if result and result[1] and result[1].persist == 1 then
            TriggerClientEvent('garage:client:showNotification', source, {
                title = 'error',
                description = 'This vehicle cannot be removed because it is still somewhere',
                type = 'error'
            })
            return false
        end
    end
    return true
end)

lib.callback.register('okokGarage:server:check-persistence-transfer', function(source, plate)
    if plate then
        local result = MySQL.query.await('SELECT persist FROM rx56_permvehicles WHERE plate = ?', {plate})
        if result and result[1] and result[1].persist == 1 then
            TriggerClientEvent('garage:client:showNotification', source, {
                title = 'error',
                description = 'This vehicle cannot be transferred because it is still somewhere',
                type = 'error'
            })
            return false
        end
    end
    return true
end)
// cl_utils.lua
---@param vehicle integer Vehicle entity
---@param vehicleDbData table Vehicle row from the database
---@param type "personal" | "job" | "gang"
RegisterNetEvent("okokGarage:client:InsertVehicle:config", function(vehicle, vehicleDbData, type)
  -- Code placed in here will be run when the player inserts their vehicle (if the vehicle is owned; and passes all the checks)
  local plate = GetVehicleNumberPlateText(vehicle)
  TriggerServerEvent('rx56_permvehicles:delete', plate)
end)

---@param vehicle integer Vehicle entity
RegisterNetEvent("okokGarage:client:ImpoundVehicle:config", function(vehicle)
  -- Code placed in here will be run just before the vehicle is set to impounded in the DB, and before the entity is deleted
  local plate = GetVehicleNumberPlateText(vehicle)
  TriggerServerEvent('rx56_permvehicles:delete', plate)
end)

---@param vehicle integer Vehicle entity
---@param vehicleDbData table Vehicle row from the database
---@param type "personal" | "job" | "gang"
RegisterNetEvent("okokGarage:client:TakeOutVehicle:config", function(vehicle, vehicleDbData, type)
  -- Code placed in here will be run after a vehicle has been taken out of a garage
  local NetId = VehToNet(vehicle)
  TriggerServerEvent('rx56_perm:register', NetId)
end)

---@param plate string
---@param newOwnerPlayerId integer
RegisterNetEvent("okokGarage:client:TransferVehicle:config", function(plate, newOwnerPlayerId)
  -- Code placed in here will be fired when a vehicle is transferred to another player via a public garage
  --local plate = GetVehicleNumberPlateText(vehicle)
  TriggerServerEvent('rx56_permvehicles:delete', plate)
end)

---@param plate string
---@param vehicleDbData table Vehicle row from the database
---@param garageId string
lib.callback.register("okokGarage:client:takeout-vehicle-verification", function(plate, vehicleDbData, garageId)
  -- Check if vehicle is persistent in rx56_permvehicles table
  local canTakeout = lib.callback.await('okokGarage:server:check-persistence-takeout', false, plate)
  return canTakeout
end)

Last updated