2025-06-08 16:20:16 +02:00
|
|
|
RegisterNetEvent('mh_garage:retrieveVehicle')
|
2025-06-09 18:14:06 +02:00
|
|
|
AddEventHandler('mh_garage:retrieveVehicle', function()
|
2025-06-09 13:28:19 +02:00
|
|
|
local ped = PlayerPedId()
|
|
|
|
local coords = GetEntityCoords(ped)
|
|
|
|
local random = SelectName()
|
|
|
|
|
|
|
|
local opt = {}
|
|
|
|
|
|
|
|
QBCore.Functions.TriggerCallback('mh_garage:CallVehicles', function(cb)
|
2025-06-09 14:22:50 +02:00
|
|
|
Debug(json.encode(cb))
|
2025-06-09 13:28:19 +02:00
|
|
|
for i = 1, #cb, 1 do
|
2025-06-12 12:55:30 +02:00
|
|
|
if cb[i].garage ~= "OUT" then
|
|
|
|
local mods = json.decode(cb[i].mods)
|
|
|
|
table.insert(opt, {
|
|
|
|
title = cb[i].name,
|
|
|
|
description = "Kennzeichen: "..cb[i].plate.."\nTankinhalt: "..math.round(mods.fuelLevel, 2).."%",
|
|
|
|
icon = "car",
|
|
|
|
onSelect = function()
|
|
|
|
cb[i].mods = mods
|
|
|
|
SpawnThisVehicle(cb[i])
|
|
|
|
end
|
|
|
|
})
|
|
|
|
end
|
2025-06-09 13:28:19 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
lib.registerContext({
|
|
|
|
id = "retrieveVehicle",
|
|
|
|
title = random.name,
|
|
|
|
options = opt
|
|
|
|
})
|
|
|
|
|
|
|
|
lib.showContext("retrieveVehicle")
|
2025-06-09 18:14:06 +02:00
|
|
|
end, CurrentZone.name)
|
2025-06-09 18:48:19 +02:00
|
|
|
end)
|
|
|
|
|
2025-06-09 19:05:18 +02:00
|
|
|
function SpawnThisVehicle(vehicle)
|
|
|
|
local spawnPoint = nil
|
|
|
|
|
|
|
|
-- Freien Spawnpunkt suchen
|
|
|
|
for _, spot in pairs(CurrentZone.vehicle_spawn) do
|
|
|
|
if not IsAnyVehicleNearPoint(spot.x, spot.y, spot.z, 3.0) then
|
|
|
|
spawnPoint = spot
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if spawnPoint then
|
|
|
|
QBCore.Functions.SpawnVehicle(vehicle.vehicle, function(veh)
|
|
|
|
-- Fahrzeug ID für Server
|
|
|
|
local netId = NetworkGetNetworkIdFromEntity(veh)
|
|
|
|
|
|
|
|
-- Grundeinstellungen
|
|
|
|
SetVehicleNumberPlateText(veh, vehicle.plate)
|
|
|
|
SetVehicleDoorsLocked(veh, 0)
|
|
|
|
SetEntityHeading(veh, spawnPoint.w)
|
|
|
|
|
|
|
|
-- Motor aus
|
|
|
|
SetVehicleEngineOn(veh, false, true, true)
|
|
|
|
|
|
|
|
-- Fahrzeug Eigenschaften
|
|
|
|
local mods = type(vehicle.mods) == 'string' and json.decode(vehicle.mods) or vehicle.mods
|
|
|
|
|
|
|
|
-- Grundwerte setzen
|
|
|
|
SetVehicleFuelLevel(veh, mods.fuelLevel)
|
2025-06-09 19:46:37 +02:00
|
|
|
exports["lc_fuel"]:SetFuel(veh, mods.fuelLevel)
|
2025-06-09 19:05:18 +02:00
|
|
|
SetVehicleEngineHealth(veh, mods.engineHealth)
|
|
|
|
SetVehicleBodyHealth(veh, mods.bodyHealth)
|
|
|
|
SetVehicleDirtLevel(veh, mods.dirtLevel)
|
|
|
|
|
|
|
|
-- Türen Status
|
|
|
|
if mods.doorStatus then
|
|
|
|
for doorIndex = 0, 5 do
|
|
|
|
if mods.doorStatus[tostring(doorIndex)] then
|
|
|
|
SetVehicleDoorBroken(veh, doorIndex, true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Fenster Status
|
|
|
|
if mods.windowStatus then
|
|
|
|
for windowIndex = 0, 7 do
|
|
|
|
if not mods.windowStatus[tostring(windowIndex)] then
|
|
|
|
SmashVehicleWindow(veh, windowIndex)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Alle Mods anwenden
|
|
|
|
QBCore.Functions.SetVehicleProperties(veh, mods)
|
|
|
|
|
|
|
|
-- Fahrzeug auf den Boden setzen
|
|
|
|
SetVehicleOnGroundProperly(veh)
|
|
|
|
|
|
|
|
-- Server über gespawntes Fahrzeug informieren
|
|
|
|
TriggerServerEvent('mh_garage:spawnedVehicle', netId, vehicle.plate)
|
|
|
|
|
|
|
|
-- Optional: Erfolgsmeldung
|
|
|
|
lib.notify({
|
|
|
|
title = "Fahrzeug geparkt...",
|
|
|
|
description = "Dein Fahrzeug steht auf Parkplatz "..math.random(1, 15),
|
|
|
|
type = "success"
|
|
|
|
})
|
|
|
|
end, vector3(spawnPoint.x, spawnPoint.y, spawnPoint.z), true)
|
|
|
|
else
|
|
|
|
QBCore.Functions.Notify('Alle Parkplätze sind belegt!', 'error')
|
|
|
|
lib.notify({
|
|
|
|
title = "Fahrzeug nicht gefunden",
|
|
|
|
description = "Alle Parkplätze sind belegt!",
|
|
|
|
type = "success"
|
|
|
|
})
|
|
|
|
end
|
2025-06-09 18:48:19 +02:00
|
|
|
end
|