So I’ve been trying to create a custom system (kinda lika a garage system, but different) for my server.
As I got to the part where I display the player all vehicles he ownes I need to create a server callback where the script gets all vehicles from the database using the license. The problem is, that the result is always nil - even if there are saved vehicles. I also see the saved vehicles displayed in the database, so that works.
Server-Side Code:
QBCore.Functions.CreateCallback("emergsaver:server:GetUserVehicles", function(source, cb)
local src = source
local pData = QBCore.Functions.GetPlayer(src)
exports.oxmysql:execute('SELECT * FROM saved_emergency_vehicles WHERE license = ?', pData.PlayerData.license, function(result)
if result[1] then
print('PosRes')
cb(result)
else
print('NegRes')
cb(nil)
end
end)
end)
Client-Side Code:
RegisterNetEvent('emergsaver:client:VehicleList', function()
QBCore.Functions.TriggerCallback('emergsaver:server:GetUserVehicles', function(result)
if result == nil then
QBCore.Functions.Notify("Keine gespeicherten Fahrzeuge", "error", 5000)
else
local MenuPublicGarageOptions = {
{
header = "Polizeiwagengarage",
isMenuheader = true
},
}
for k, v in pairs(result) do
vname = GetDisplayNameFromVehicleModel(v.model)
liv = v.livery
local livtext
if liv == 1 then
livtext = "BCSO"
elseif liv == 2 then
livtext = "SAST"
elseif liv == 3 then
livtext = "Unmarked"
elseif liv == 4 then
livtext = "LSSD"
elseif liv > 4 then
livtext = "LSPD"
end
MenuPublicGarageOptions[#MenuPublicGarageOptions+1] = {
header = vname.." [".. v.plate.."]",
txt = "Livery: " .. livtext,
params = {
event = "emergsaver:client:spawnVeh",
args = v,
}
}
exports['qb-menu']:openMenu(MenuPublicGarageOptions)
end
MenuPublicGarageOptions[#MenuPublicGarageOptions+1] = {
header = "⬅ Schließen",
txt = "",
params = {
event = "qb-menu:closeMenu",
}
}
end
end)
end)
I copied the code from another working system, but it just doens’t work for me.
There are no errors displayed.
~ Paul