Main/resources/[carscripts]/mh_garage/client/retrieve.lua

110 lines
3.8 KiB
Lua
Raw Normal View History

2025-06-08 16:20:16 +02:00
RegisterNetEvent('mh_garage:retrieveVehicle')
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-09 18:48:19 +02:00
local mods = json.decode(cb[i].mods)
2025-06-09 13:28:19 +02:00
table.insert(opt, {
2025-06-09 13:50:04 +02:00
title = cb[i].name,
2025-06-09 19:09:17 +02:00
description = "Kennzeichen: "..cb[i].plate.."\nTankinhalt: "..math.round(mods.fuelLevel, 2).."%",
2025-06-09 13:28:19 +02:00
icon = "car",
onSelect = function()
2025-06-09 18:48:19 +02:00
cb[i].mods = mods
2025-06-09 13:28:19 +02:00
SpawnThisVehicle(cb[i])
end
})
end
lib.registerContext({
id = "retrieveVehicle",
title = random.name,
options = opt
})
lib.showContext("retrieveVehicle")
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:40:01 +02:00
exports["lc_fuel"]:SetFuel(vehicle, 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