diff --git a/[core]/mercyv-garage/client/admin.lua b/[core]/mercyv-garage/client/admin.lua index 14ba9ee2..b912e2fb 100644 --- a/[core]/mercyv-garage/client/admin.lua +++ b/[core]/mercyv-garage/client/admin.lua @@ -55,15 +55,11 @@ end, false) RegisterNUICallback('closeAdmin', function(data, cb) AdminOpen = false GarageIsOpen = false - SetNuiFocus(false, false) - exports['hex_4_hud']:HideHud(false) - -- Garage-Kamera aufräumen falls sie noch läuft - if GarageCam then - RenderScriptCams(false, true, 500, true, true) - DestroyCam(GarageCam, false) - GarageCam = nil - end + -- NUI-Fokus freigeben und Steuerung zurückgeben + SetNuiFocus(false, false) + SetNuiFocusKeepInput(false) + exports['hex_4_hud']:HideHud(false) -- Preview-Fahrzeug löschen falls vorhanden if PreviewVeh and DoesEntityExist(PreviewVeh) then @@ -72,7 +68,6 @@ RegisterNUICallback('closeAdmin', function(data, cb) end CurrentGarage = nil - SendNUIMessage({ action = "CLOSE" }) cb({}) end) diff --git a/[core]/mercyv-garage/server/main.lua b/[core]/mercyv-garage/server/main.lua index 81a3d692..7aa8001f 100644 --- a/[core]/mercyv-garage/server/main.lua +++ b/[core]/mercyv-garage/server/main.lua @@ -178,6 +178,52 @@ local function LoadGarages() GaragesData[row.id] = DBRowToGarage(row) end end + + -- Job-Fahrzeuge aus DB laden + MySQL.query.await([[CREATE TABLE IF NOT EXISTS `mercyv_job_vehicles` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `garage_id` VARCHAR(80) NOT NULL, + `model` VARCHAR(100) NOT NULL, + `label` VARCHAR(100) DEFAULT NULL + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4]]) + + local jvResult = MySQL.query.await('SELECT * FROM mercyv_job_vehicles') + if jvResult then + for _, row in ipairs(jvResult) do + if not Config.JobVehicles then Config.JobVehicles = {} end + if not Config.JobVehicles[row.garage_id] then + Config.JobVehicles[row.garage_id] = {} + end + -- Prüfen ob schon in config (config hat Vorrang beim ersten Start) + local exists = false + for _, existing in ipairs(Config.JobVehicles[row.garage_id]) do + if existing.model == row.model then exists = true; break end + end + if not exists then + table.insert(Config.JobVehicles[row.garage_id], { + model = row.model, + label = row.label or row.model, + grade = 0, + }) + end + end + end + + -- Config.JobVehicles auch initial in DB schreiben (einmalig) + if Config.JobVehicles then + for garageId, vehicles in pairs(Config.JobVehicles) do + for _, v in ipairs(vehicles) do + local exists = MySQL.query.await( + 'SELECT id FROM mercyv_job_vehicles WHERE garage_id = ? AND model = ?', + { garageId, v.model }) + if not exists or #exists == 0 then + MySQL.insert('INSERT INTO mercyv_job_vehicles (garage_id, model, label) VALUES (?, ?, ?)', + { garageId, v.model, v.label or v.model }) + end + end + end + end + local cnt = 0; for _ in pairs(GaragesData) do cnt=cnt+1 end print(string.format('[mercyv-garage] %d Garagen geladen.', cnt)) end @@ -601,10 +647,16 @@ RegisterNetEvent('mercyv-garage:admin:saveGarage', function(data) showcar_x=data.showcar_x,showcar_y=data.showcar_y,showcar_z=data.showcar_z,showcar_heading=data.showcar_heading or 0, cam_x=data.cam_x,cam_y=data.cam_y,cam_z=data.cam_z,cam_rot_z=data.cam_rot_z or -20, }) - -- Job-Fahrzeuge in Config aktualisieren + -- Job-Fahrzeuge persistieren (DB + Config) if data.type == 'jobgarage' and data.job_vehicles then if not Config.JobVehicles then Config.JobVehicles = {} end Config.JobVehicles[data.access] = data.job_vehicles + -- In DB speichern + MySQL.update.await("DELETE FROM mercyv_job_vehicles WHERE garage_id = ?", { data.id }) + for _, v in ipairs(data.job_vehicles) do + MySQL.insert("INSERT INTO mercyv_job_vehicles (garage_id, model, label) VALUES (?, ?, ?)", + { data.id, v.model, v.label or v.model }) + end end BroadcastGarages()