forked from Simnation/Main
Update main.lua
This commit is contained in:
parent
ad0bf1b083
commit
0b8ab3c19a
1 changed files with 122 additions and 47 deletions
|
@ -1,21 +1,34 @@
|
||||||
local QBCore = exports['qb-core']:GetCoreObject()
|
local QBCore = exports['qb-core']:GetCoreObject()
|
||||||
local currentVehicle = nil
|
local currentVehicle = nil
|
||||||
|
|
||||||
|
-- Boot-Klassen für spezielle Behandlung
|
||||||
|
local boatClasses = {
|
||||||
|
[14] = true, -- Boats
|
||||||
|
[15] = true, -- Helicopters (falls gewünscht)
|
||||||
|
[16] = true -- Planes (falls gewünscht)
|
||||||
|
}
|
||||||
|
|
||||||
-- Sitz-Namen für bessere Anzeige
|
-- Sitz-Namen für bessere Anzeige
|
||||||
local seatNames = {
|
local seatNames = {
|
||||||
[-1] = "Fahrer",
|
[-1] = "Kapitän",
|
||||||
[0] = "Beifahrer",
|
[0] = "Beifahrer",
|
||||||
[1] = "Hinten Links",
|
[1] = "Hinten Links",
|
||||||
[2] = "Hinten Rechts",
|
[2] = "Hinten Rechts",
|
||||||
[3] = "Hinten Mitte",
|
[3] = "Hinten Mitte",
|
||||||
[4] = "Extra 1",
|
[4] = "Deck 1",
|
||||||
[5] = "Extra 2",
|
[5] = "Deck 2",
|
||||||
[6] = "Extra 3",
|
[6] = "Deck 3",
|
||||||
[7] = "Extra 4",
|
[7] = "Deck 4",
|
||||||
[8] = "Extra 5",
|
[8] = "Deck 5",
|
||||||
[9] = "Extra 6"
|
[9] = "Deck 6"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- Prüfe ob Fahrzeug ein Boot ist
|
||||||
|
local function isBoat(vehicle)
|
||||||
|
local vehicleClass = GetVehicleClass(vehicle)
|
||||||
|
return boatClasses[vehicleClass] or false
|
||||||
|
end
|
||||||
|
|
||||||
-- Funktion um verfügbare Sitze zu bekommen
|
-- Funktion um verfügbare Sitze zu bekommen
|
||||||
local function getAvailableSeats(vehicle)
|
local function getAvailableSeats(vehicle)
|
||||||
local seats = {}
|
local seats = {}
|
||||||
|
@ -23,10 +36,11 @@ local function getAvailableSeats(vehicle)
|
||||||
|
|
||||||
-- Fahrersitz (-1)
|
-- Fahrersitz (-1)
|
||||||
if IsVehicleSeatFree(vehicle, -1) then
|
if IsVehicleSeatFree(vehicle, -1) then
|
||||||
|
local seatName = isBoat(vehicle) and seatNames[-1] or "Fahrer"
|
||||||
table.insert(seats, {
|
table.insert(seats, {
|
||||||
index = -1,
|
index = -1,
|
||||||
name = seatNames[-1],
|
name = seatName,
|
||||||
icon = "fas fa-steering-wheel"
|
icon = isBoat(vehicle) and "fas fa-anchor" or "fas fa-steering-wheel"
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -63,11 +77,12 @@ local function getOccupiedSeats(vehicle)
|
||||||
playerName = "NPC"
|
playerName = "NPC"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local seatName = isBoat(vehicle) and seatNames[-1] or "Fahrer"
|
||||||
table.insert(occupiedSeats, {
|
table.insert(occupiedSeats, {
|
||||||
index = -1,
|
index = -1,
|
||||||
name = seatNames[-1],
|
name = seatName,
|
||||||
occupant = playerName,
|
occupant = playerName,
|
||||||
icon = "fas fa-steering-wheel"
|
icon = isBoat(vehicle) and "fas fa-anchor" or "fas fa-steering-wheel"
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -98,7 +113,39 @@ local function getOccupiedSeats(vehicle)
|
||||||
return occupiedSeats
|
return occupiedSeats
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Funktion zum Einsteigen
|
-- Funktion zum direkten Einsteigen (für Boote)
|
||||||
|
local function teleportToSeat(vehicle, seatIndex)
|
||||||
|
local playerPed = PlayerPedId()
|
||||||
|
|
||||||
|
if IsPedInAnyVehicle(playerPed, false) then
|
||||||
|
QBCore.Functions.Notify('Du bist bereits in einem Fahrzeug!', 'error')
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if not IsVehicleSeatFree(vehicle, seatIndex) then
|
||||||
|
QBCore.Functions.Notify('Dieser Sitz ist bereits belegt!', 'error')
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Prüfe ob Fahrzeug abgeschlossen ist
|
||||||
|
if GetVehicleDoorLockStatus(vehicle) == 2 then
|
||||||
|
QBCore.Functions.Notify('Das Fahrzeug ist abgeschlossen!', 'error')
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Direkte Teleportation ohne Animation
|
||||||
|
SetPedIntoVehicle(playerPed, vehicle, seatIndex)
|
||||||
|
currentVehicle = vehicle
|
||||||
|
|
||||||
|
local seatName = seatNames[seatIndex] or "Sitz " .. (seatIndex + 1)
|
||||||
|
if isBoat(vehicle) then
|
||||||
|
QBCore.Functions.Notify('Willkommen an Bord! (' .. seatName .. ')', 'success')
|
||||||
|
else
|
||||||
|
QBCore.Functions.Notify('Du bist eingestiegen (' .. seatName .. ')', 'success')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Funktion zum normalen Einsteigen (für Autos)
|
||||||
local function enterVehicleSeat(vehicle, seatIndex)
|
local function enterVehicleSeat(vehicle, seatIndex)
|
||||||
local playerPed = PlayerPedId()
|
local playerPed = PlayerPedId()
|
||||||
|
|
||||||
|
@ -139,11 +186,15 @@ local function switchSeat(vehicle, newSeatIndex)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
TaskShuffleToNextVehicleSeat(playerPed, vehicle)
|
-- Für Boote: Direkte Teleportation
|
||||||
Wait(100)
|
if isBoat(vehicle) then
|
||||||
|
SetPedIntoVehicle(playerPed, vehicle, newSeatIndex)
|
||||||
-- Setze auf gewünschten Sitz
|
else
|
||||||
SetPedIntoVehicle(playerPed, vehicle, newSeatIndex)
|
-- Für Autos: Normale Animation
|
||||||
|
TaskShuffleToNextVehicleSeat(playerPed, vehicle)
|
||||||
|
Wait(100)
|
||||||
|
SetPedIntoVehicle(playerPed, vehicle, newSeatIndex)
|
||||||
|
end
|
||||||
|
|
||||||
local seatName = seatNames[newSeatIndex] or "Sitz " .. (newSeatIndex + 1)
|
local seatName = seatNames[newSeatIndex] or "Sitz " .. (newSeatIndex + 1)
|
||||||
QBCore.Functions.Notify('Gewechselt zu: ' .. seatName, 'success')
|
QBCore.Functions.Notify('Gewechselt zu: ' .. seatName, 'success')
|
||||||
|
@ -155,6 +206,7 @@ local function showSeatMenu(vehicle)
|
||||||
local isInVehicle = IsPedInVehicle(playerPed, vehicle, false)
|
local isInVehicle = IsPedInVehicle(playerPed, vehicle, false)
|
||||||
local availableSeats = getAvailableSeats(vehicle)
|
local availableSeats = getAvailableSeats(vehicle)
|
||||||
local occupiedSeats = getOccupiedSeats(vehicle)
|
local occupiedSeats = getOccupiedSeats(vehicle)
|
||||||
|
local isVehicleBoat = isBoat(vehicle)
|
||||||
local options = {}
|
local options = {}
|
||||||
|
|
||||||
-- Header
|
-- Header
|
||||||
|
@ -164,24 +216,37 @@ local function showSeatMenu(vehicle)
|
||||||
vehicleLabel = vehicleName
|
vehicleLabel = vehicleName
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Boot-spezifische Anzeige
|
||||||
|
if isVehicleBoat then
|
||||||
|
vehicleLabel = "⛵ " .. vehicleLabel
|
||||||
|
else
|
||||||
|
vehicleLabel = "🚗 " .. vehicleLabel
|
||||||
|
end
|
||||||
|
|
||||||
-- Verfügbare Sitze
|
-- Verfügbare Sitze
|
||||||
if #availableSeats > 0 then
|
if #availableSeats > 0 then
|
||||||
|
local headerText = isVehicleBoat and '🟢 Verfügbare Plätze' or '🟢 Verfügbare Sitze'
|
||||||
table.insert(options, {
|
table.insert(options, {
|
||||||
title = '🟢 Verfügbare Sitze',
|
title = headerText,
|
||||||
description = 'Freie Sitzplätze',
|
description = isVehicleBoat and 'Freie Plätze an Bord' or 'Freie Sitzplätze',
|
||||||
disabled = true
|
disabled = true
|
||||||
})
|
})
|
||||||
|
|
||||||
for _, seat in pairs(availableSeats) do
|
for _, seat in pairs(availableSeats) do
|
||||||
|
local actionText = isInVehicle and 'Zu diesem Platz wechseln' or (isVehicleBoat and 'An Bord gehen' or 'In das Fahrzeug einsteigen')
|
||||||
table.insert(options, {
|
table.insert(options, {
|
||||||
title = seat.name,
|
title = seat.name,
|
||||||
description = isInVehicle and 'Zu diesem Sitz wechseln' or 'In das Fahrzeug einsteigen',
|
description = actionText,
|
||||||
icon = seat.icon,
|
icon = seat.icon,
|
||||||
onSelect = function()
|
onSelect = function()
|
||||||
if isInVehicle then
|
if isInVehicle then
|
||||||
switchSeat(vehicle, seat.index)
|
switchSeat(vehicle, seat.index)
|
||||||
else
|
else
|
||||||
enterVehicleSeat(vehicle, seat.index)
|
if isVehicleBoat then
|
||||||
|
teleportToSeat(vehicle, seat.index)
|
||||||
|
else
|
||||||
|
enterVehicleSeat(vehicle, seat.index)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
@ -190,9 +255,10 @@ local function showSeatMenu(vehicle)
|
||||||
|
|
||||||
-- Belegte Sitze anzeigen
|
-- Belegte Sitze anzeigen
|
||||||
if #occupiedSeats > 0 then
|
if #occupiedSeats > 0 then
|
||||||
|
local headerText = isVehicleBoat and '🔴 Belegte Plätze' or '🔴 Belegte Sitze'
|
||||||
table.insert(options, {
|
table.insert(options, {
|
||||||
title = '🔴 Belegte Sitze',
|
title = headerText,
|
||||||
description = 'Bereits besetzte Sitzplätze',
|
description = isVehicleBoat and 'Bereits besetzte Plätze' or 'Bereits besetzte Sitzplätze',
|
||||||
disabled = true
|
disabled = true
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -208,13 +274,16 @@ local function showSeatMenu(vehicle)
|
||||||
|
|
||||||
-- Aussteigen Option (nur wenn im Fahrzeug)
|
-- Aussteigen Option (nur wenn im Fahrzeug)
|
||||||
if isInVehicle then
|
if isInVehicle then
|
||||||
|
local exitText = isVehicleBoat and '🚪 Von Bord gehen' or '🚪 Aussteigen'
|
||||||
|
local exitDesc = isVehicleBoat and 'Das Boot verlassen' or 'Das Fahrzeug verlassen'
|
||||||
table.insert(options, {
|
table.insert(options, {
|
||||||
title = '🚪 Aussteigen',
|
title = exitText,
|
||||||
description = 'Das Fahrzeug verlassen',
|
description = exitDesc,
|
||||||
icon = 'fas fa-door-open',
|
icon = 'fas fa-door-open',
|
||||||
onSelect = function()
|
onSelect = function()
|
||||||
TaskLeaveVehicle(playerPed, vehicle, 0)
|
TaskLeaveVehicle(playerPed, vehicle, 0)
|
||||||
QBCore.Functions.Notify('Du steigst aus dem Fahrzeug aus...', 'primary')
|
local exitMsg = isVehicleBoat and 'Du gehst von Bord...' or 'Du steigst aus dem Fahrzeug aus...'
|
||||||
|
QBCore.Functions.Notify(exitMsg, 'primary')
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
@ -236,7 +305,7 @@ local function showSeatMenu(vehicle)
|
||||||
|
|
||||||
lib.registerContext({
|
lib.registerContext({
|
||||||
id = 'vehicle_seat_menu',
|
id = 'vehicle_seat_menu',
|
||||||
title = '🚗 ' .. vehicleLabel,
|
title = vehicleLabel,
|
||||||
options = options
|
options = options
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -255,48 +324,54 @@ function showVehicleInfo(vehicle)
|
||||||
local maxSeats = GetVehicleMaxNumberOfPassengers(vehicle) + 1 -- +1 für Fahrer
|
local maxSeats = GetVehicleMaxNumberOfPassengers(vehicle) + 1 -- +1 für Fahrer
|
||||||
local engineHealth = math.floor(GetVehicleEngineHealth(vehicle) / 10)
|
local engineHealth = math.floor(GetVehicleEngineHealth(vehicle) / 10)
|
||||||
local bodyHealth = math.floor(GetVehicleBodyHealth(vehicle) / 10)
|
local bodyHealth = math.floor(GetVehicleBodyHealth(vehicle) / 10)
|
||||||
local fuelLevel = math.floor(GetVehicleFuelLevel(vehicle))
|
local isVehicleBoat = isBoat(vehicle)
|
||||||
|
|
||||||
local options = {
|
local options = {
|
||||||
{
|
{
|
||||||
title = 'Fahrzeug: ' .. vehicleLabel,
|
title = (isVehicleBoat and 'Boot: ' or 'Fahrzeug: ') .. vehicleLabel,
|
||||||
description = 'Kennzeichen: ' .. (vehicleProps.plate or 'Unbekannt'),
|
description = 'Kennzeichen: ' .. (vehicleProps.plate or 'Unbekannt'),
|
||||||
icon = 'fas fa-car',
|
icon = isVehicleBoat and 'fas fa-ship' or 'fas fa-car',
|
||||||
disabled = true
|
disabled = true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title = 'Sitzplätze: ' .. maxSeats,
|
title = (isVehicleBoat and 'Plätze: ' or 'Sitzplätze: ') .. maxSeats,
|
||||||
description = 'Maximale Anzahl Personen',
|
description = 'Maximale Anzahl Personen',
|
||||||
icon = 'fas fa-users',
|
icon = 'fas fa-users',
|
||||||
disabled = true
|
disabled = true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title = 'Motor: ' .. engineHealth .. '%',
|
title = (isVehicleBoat and 'Motor: ' or 'Motor: ') .. engineHealth .. '%',
|
||||||
description = 'Zustand des Motors',
|
description = 'Zustand des Motors',
|
||||||
icon = 'fas fa-cog',
|
icon = 'fas fa-cog',
|
||||||
disabled = true
|
disabled = true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title = 'Karosserie: ' .. bodyHealth .. '%',
|
title = (isVehicleBoat and 'Rumpf: ' or 'Karosserie: ') .. bodyHealth .. '%',
|
||||||
description = 'Zustand der Karosserie',
|
description = isVehicleBoat and 'Zustand des Rumpfes' or 'Zustand der Karosserie',
|
||||||
icon = 'fas fa-car-crash',
|
icon = isVehicleBoat and 'fas fa-ship' or 'fas fa-car-crash',
|
||||||
disabled = true
|
disabled = true
|
||||||
},
|
}
|
||||||
{
|
}
|
||||||
|
|
||||||
|
-- Kraftstoff nur für Nicht-Boote (Boote haben oft keinen Kraftstoff-Wert)
|
||||||
|
if not isVehicleBoat then
|
||||||
|
local fuelLevel = math.floor(GetVehicleFuelLevel(vehicle))
|
||||||
|
table.insert(options, {
|
||||||
title = 'Kraftstoff: ' .. fuelLevel .. '%',
|
title = 'Kraftstoff: ' .. fuelLevel .. '%',
|
||||||
description = 'Aktueller Tankstand',
|
description = 'Aktueller Tankstand',
|
||||||
icon = 'fas fa-gas-pump',
|
icon = 'fas fa-gas-pump',
|
||||||
disabled = true
|
disabled = true
|
||||||
},
|
})
|
||||||
{
|
end
|
||||||
title = '← Zurück',
|
|
||||||
description = 'Zurück zum Sitzmenü',
|
table.insert(options, {
|
||||||
icon = 'fas fa-arrow-left',
|
title = '← Zurück',
|
||||||
onSelect = function()
|
description = 'Zurück zum Sitzmenü',
|
||||||
showSeatMenu(vehicle)
|
icon = 'fas fa-arrow-left',
|
||||||
end
|
onSelect = function()
|
||||||
}
|
showSeatMenu(vehicle)
|
||||||
}
|
end
|
||||||
|
})
|
||||||
|
|
||||||
lib.registerContext({
|
lib.registerContext({
|
||||||
id = 'vehicle_info_menu',
|
id = 'vehicle_info_menu',
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue