forked from Simnation/Main
ed
This commit is contained in:
parent
6d22d5f77c
commit
63fbc60a00
86 changed files with 8352 additions and 3428 deletions
152
resources/[Developer]/mh_garage/client/retrieve.lua
Normal file
152
resources/[Developer]/mh_garage/client/retrieve.lua
Normal file
|
@ -0,0 +1,152 @@
|
|||
RegisterNetEvent('mh_garage:retrieveOwnerVehicle')
|
||||
AddEventHandler('mh_garage:retrieveOwnerVehicle', function()
|
||||
local ped = PlayerPedId()
|
||||
local coords = GetEntityCoords(ped)
|
||||
local random = SelectName()
|
||||
|
||||
local opt = {}
|
||||
|
||||
QBCore.Functions.TriggerCallback('mh_garage:retrieveOwnerVehicle', function(cb)
|
||||
if cb == false then
|
||||
Notification("Es ist kein Fahrzeug hier!", "inform")
|
||||
return
|
||||
end
|
||||
|
||||
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)
|
||||
|
||||
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:retrieveKeyVehicle', function(cb)
|
||||
if cb == false then
|
||||
Notification("Es ist kein Fahrzeug hier!", "inform")
|
||||
return
|
||||
end
|
||||
|
||||
for i = 1, #cb, 1 do
|
||||
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
|
||||
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
|
Loading…
Add table
Add a link
Reference in a new issue