110 lines
		
	
	
		
			No EOL
		
	
	
		
			3.8 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
			
		
		
	
	
			110 lines
		
	
	
		
			No EOL
		
	
	
		
			3.8 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
RegisterNetEvent('mh_garage:retrieveVehicle')
 | 
						|
AddEventHandler('mh_garage:retrieveVehicle', function()
 | 
						|
    local ped = PlayerPedId()
 | 
						|
    local coords = GetEntityCoords(ped)
 | 
						|
    local random = SelectName()
 | 
						|
 | 
						|
    local opt = {}
 | 
						|
 | 
						|
    QBCore.Functions.TriggerCallback('mh_garage:CallVehicles', function(cb)
 | 
						|
        Debug(json.encode(cb))
 | 
						|
        for i = 1, #cb, 1 do
 | 
						|
            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
 | 
						|
 | 
						|
        lib.registerContext({
 | 
						|
            id = "retrieveVehicle",
 | 
						|
            title = random.name,
 | 
						|
            options = opt
 | 
						|
        })
 | 
						|
 | 
						|
        lib.showContext("retrieveVehicle")
 | 
						|
    end, CurrentZone.name)
 | 
						|
end)
 | 
						|
 | 
						|
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)
 | 
						|
            exports["lc_fuel"]:SetFuel(veh, mods.fuelLevel)
 | 
						|
            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
 | 
						|
end |