jg-advancedgarages
// config-sv.lua (1)
-- Server callback to check if a vehicle can be taken out (persistence check)
lib.callback.register('jg-advancedgarages: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)
-- Server callback to check if a vehicle can be transferred between garages (persistence check)
lib.callback.register('jg-advancedgarages: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)
// config-cl.lua
--
-- Custom code for common events
--
---@param vehicle integer Vehicle entity
---@param vehicleDbData table Vehicle row from the database
---@param type "personal" | "job" | "gang"
RegisterNetEvent("jg-advancedgarages: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("jg-advancedgarages: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("jg-advancedgarages: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("jg-advancedgarages: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("jg-advancedgarages:client:takeout-vehicle-verification", function(plate, vehicleDbData, garageId)
-- Check if vehicle is persistent in rx56_permvehicles table
local canTakeout = lib.callback.await('jg-advancedgarages:server:check-persistence-takeout', false, plate)
return canTakeout
end)
RegisterNetEvent('garage:client:showNotification', function(data)
lib.notify({
title = data.title,
description = data.description,
type = data.type,
position = 'top-left'
})
end)
Last updated