[GARAGE] Ausparken

This commit is contained in:
Miho931 2025-06-09 19:05:18 +02:00
parent e89bac3c6d
commit 8042ad195d
2 changed files with 80 additions and 2 deletions

View file

@ -31,6 +31,79 @@ AddEventHandler('mh_garage:retrieveVehicle', function()
end, CurrentZone.name) end, CurrentZone.name)
end) end)
function SpawnThisVehicle(veh) function SpawnThisVehicle(vehicle)
print("Spawn 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)
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 end

View file

@ -144,3 +144,8 @@ QBCore.Functions.CreateCallback('mh_garage:verwaltung', function(source, cb)
end) end)
return vehicles return vehicles
end) end)
RegisterServerEvent('mh_garage:spawnedVehicle')
AddEventHandler('mh_garage:spawnedVehicle', function(netID, plate)
MySQL.query("UPDATE player_vehicles SET parking = ? WHERE plate = ?", {0, plate})
end)