forked from Simnation/Main
Update client.lua
This commit is contained in:
parent
33075c6a84
commit
22e4719062
1 changed files with 165 additions and 74 deletions
|
@ -9,15 +9,27 @@ local trainAtStation = {}
|
||||||
local cinemaCam = nil
|
local cinemaCam = nil
|
||||||
local waitingForTrain = false
|
local waitingForTrain = false
|
||||||
|
|
||||||
|
-- Beim Laden des Scripts
|
||||||
|
CreateThread(function()
|
||||||
|
Wait(1000) -- Kurz warten bis alles geladen ist
|
||||||
|
CreateStationBlips()
|
||||||
|
print("^2[TRAIN] Blips erstellt^7")
|
||||||
|
end)
|
||||||
|
|
||||||
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
|
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
|
||||||
PlayerData = QBCore.Functions.GetPlayerData()
|
PlayerData = QBCore.Functions.GetPlayerData()
|
||||||
|
Wait(2000)
|
||||||
CreateStationBlips()
|
CreateStationBlips()
|
||||||
CreateStationInteractionPoints()
|
print("^2[TRAIN] Player loaded - Blips erstellt^7")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Bahnhof Blips erstellen
|
-- Bahnhof Blips erstellen
|
||||||
function CreateStationBlips()
|
function CreateStationBlips()
|
||||||
for _, station in pairs(Config.TrainStations) do
|
print("^3[TRAIN] Erstelle Blips für " .. #Config.TrainStations .. " Bahnhöfe^7")
|
||||||
|
|
||||||
|
for i, station in pairs(Config.TrainStations) do
|
||||||
|
print("^3[TRAIN] Erstelle Blip für: " .. station.name .. " bei " .. station.coords.x .. ", " .. station.coords.y .. "^7")
|
||||||
|
|
||||||
local blip = AddBlipForCoord(station.coords.x, station.coords.y, station.coords.z)
|
local blip = AddBlipForCoord(station.coords.x, station.coords.y, station.coords.z)
|
||||||
SetBlipSprite(blip, station.blip.sprite)
|
SetBlipSprite(blip, station.blip.sprite)
|
||||||
SetBlipDisplay(blip, 4)
|
SetBlipDisplay(blip, 4)
|
||||||
|
@ -26,86 +38,107 @@ function CreateStationBlips()
|
||||||
BeginTextCommandSetBlipName("STRING")
|
BeginTextCommandSetBlipName("STRING")
|
||||||
AddTextComponentString("🚂 " .. station.name)
|
AddTextComponentString("🚂 " .. station.name)
|
||||||
EndTextCommandSetBlipName(blip)
|
EndTextCommandSetBlipName(blip)
|
||||||
|
|
||||||
|
print("^2[TRAIN] Blip erstellt für: " .. station.name .. "^7")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Bahnhof Interaktionspunkte erstellen
|
-- Bahnhof Interaktionen - Haupt-Loop
|
||||||
function CreateStationInteractionPoints()
|
CreateThread(function()
|
||||||
CreateThread(function()
|
print("^2[TRAIN] Interaktions-Loop gestartet^7")
|
||||||
while true do
|
|
||||||
local sleep = 1000
|
while true do
|
||||||
local playerPed = PlayerPedId()
|
local sleep = 1000
|
||||||
local playerCoords = GetEntityCoords(playerPed)
|
local playerPed = PlayerPedId()
|
||||||
|
local playerCoords = GetEntityCoords(playerPed)
|
||||||
if not isRiding then
|
|
||||||
for stationId, station in pairs(Config.TrainStations) do
|
if not isRiding then
|
||||||
local distance = #(playerCoords - station.interactionPoint)
|
for i, station in pairs(Config.TrainStations) do
|
||||||
|
local interactionPoint = station.interactionPoint or vector3(station.coords.x, station.coords.y, station.coords.z)
|
||||||
|
local distance = #(playerCoords - interactionPoint)
|
||||||
|
|
||||||
|
if distance <= Config.StationInteractionDistance then
|
||||||
|
sleep = 0
|
||||||
|
|
||||||
if distance <= Config.StationInteractionDistance then
|
-- DrawText anzeigen
|
||||||
sleep = 0
|
DrawText3D(interactionPoint.x, interactionPoint.y, interactionPoint.z + 1.0,
|
||||||
|
Config.DrawText.stationText)
|
||||||
-- DrawText anzeigen
|
|
||||||
DrawText3D(station.interactionPoint.x, station.interactionPoint.y, station.interactionPoint.z + 1.0,
|
-- Debug Info
|
||||||
Config.DrawText.stationText)
|
if Config.Debug then
|
||||||
|
DrawText3D(interactionPoint.x, interactionPoint.y, interactionPoint.z + 2.0,
|
||||||
-- Interaktion
|
"Station: " .. station.name .. " | Dist: " .. math.floor(distance))
|
||||||
if IsControlJustPressed(0, 38) then -- E
|
|
||||||
if not waitingForTrain then
|
|
||||||
OpenStationMenu(station)
|
|
||||||
else
|
|
||||||
lib:notify({
|
|
||||||
title = 'Bitte warten',
|
|
||||||
description = 'Ein Zug ist bereits unterwegs',
|
|
||||||
type = 'warning'
|
|
||||||
})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Prüfen ob Zug am Bahnhof wartet
|
-- Interaktion
|
||||||
if trainAtStation[station.id] then
|
if IsControlJustPressed(0, 38) then -- E
|
||||||
local trainDistance = #(playerCoords - GetEntityCoords(trainAtStation[station.id]))
|
print("^3[TRAIN] E gedrückt bei Station: " .. station.name .. "^7")
|
||||||
|
|
||||||
|
if not waitingForTrain then
|
||||||
|
OpenStationMenu(station)
|
||||||
|
else
|
||||||
|
lib:notify({
|
||||||
|
title = 'Bitte warten',
|
||||||
|
description = 'Ein Zug ist bereits unterwegs',
|
||||||
|
type = 'warning'
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Prüfen ob Zug am Bahnhof wartet
|
||||||
|
if trainAtStation[station.id] then
|
||||||
|
local train = trainAtStation[station.id]
|
||||||
|
if DoesEntityExist(train) then
|
||||||
|
local trainCoords = GetEntityCoords(train)
|
||||||
|
local trainDistance = #(playerCoords - trainCoords)
|
||||||
|
|
||||||
if trainDistance <= 8.0 then
|
if trainDistance <= 8.0 then
|
||||||
sleep = 0
|
sleep = 0
|
||||||
DrawText3D(GetEntityCoords(trainAtStation[station.id]), Config.DrawText.boardText)
|
DrawText3D(trainCoords.x, trainCoords.y, trainCoords.z + 2.0, Config.DrawText.boardText)
|
||||||
|
|
||||||
if IsControlJustPressed(0, 38) then -- E
|
if IsControlJustPressed(0, 38) then -- E
|
||||||
-- Hier würde das Zielmenü für die Fahrt geöffnet
|
print("^3[TRAIN] Einsteigen in Zug^7")
|
||||||
OpenDestinationMenu(trainAtStation[station.id], station)
|
BoardTrain(train, station)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Wait(sleep)
|
|
||||||
end
|
end
|
||||||
end)
|
|
||||||
end
|
Wait(sleep)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
-- Bahnhof Menü öffnen
|
-- Bahnhof Menü öffnen
|
||||||
function OpenStationMenu(station)
|
function OpenStationMenu(station)
|
||||||
|
print("^3[TRAIN] Öffne Menü für Station: " .. station.name .. "^7")
|
||||||
|
|
||||||
local options = {}
|
local options = {}
|
||||||
|
|
||||||
-- Verfügbare Ziele anzeigen
|
-- Verfügbare Ziele anzeigen
|
||||||
for _, destinationId in pairs(station.destinations) do
|
if station.destinations then
|
||||||
local destination = GetStationById(destinationId)
|
for _, destinationId in pairs(station.destinations) do
|
||||||
if destination then
|
local destination = GetStationById(destinationId)
|
||||||
local price = CalculatePrice(station, destination)
|
if destination then
|
||||||
local icon = GetStationIcon(destination.name)
|
local price = CalculatePrice(station, destination)
|
||||||
|
local icon = GetStationIcon(destination.name)
|
||||||
table.insert(options, {
|
|
||||||
title = icon .. " " .. destination.name,
|
table.insert(options, {
|
||||||
description = destination.description .. " - Preis: $" .. price,
|
title = icon .. " " .. destination.name,
|
||||||
icon = 'train',
|
description = destination.description .. " - Preis: $" .. price,
|
||||||
onSelect = function()
|
icon = 'train',
|
||||||
CallTrainToStation(station, destination, price)
|
onSelect = function()
|
||||||
end,
|
print("^3[TRAIN] Ziel gewählt: " .. destination.name .. "^7")
|
||||||
metadata = {
|
CallTrainToStation(station, destination, price)
|
||||||
{label = "Preis", value = "$" .. price},
|
end,
|
||||||
{label = "Entfernung", value = math.floor(GetDistanceBetweenStations(station, destination)) .. "m"}
|
metadata = {
|
||||||
}
|
{label = "Preis", value = "$" .. price},
|
||||||
})
|
{label = "Entfernung", value = math.floor(GetDistanceBetweenStations(station, destination)) .. "m"}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -135,6 +168,8 @@ end
|
||||||
|
|
||||||
-- Zug zum Bahnhof rufen
|
-- Zug zum Bahnhof rufen
|
||||||
function CallTrainToStation(station, destination, price)
|
function CallTrainToStation(station, destination, price)
|
||||||
|
print("^3[TRAIN] Rufe Zug für " .. station.name .. " -> " .. destination.name .. "^7")
|
||||||
|
|
||||||
-- Geld prüfen
|
-- Geld prüfen
|
||||||
QBCore.Functions.TriggerCallback('train:server:canAfford', function(canAfford)
|
QBCore.Functions.TriggerCallback('train:server:canAfford', function(canAfford)
|
||||||
if canAfford then
|
if canAfford then
|
||||||
|
@ -163,8 +198,13 @@ end
|
||||||
-- Zug spawnen und zum Bahnhof fahren lassen
|
-- Zug spawnen und zum Bahnhof fahren lassen
|
||||||
function SpawnAndMoveTrainToStation(station, destination)
|
function SpawnAndMoveTrainToStation(station, destination)
|
||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
|
print("^3[TRAIN] Spawne Zug für Station: " .. station.name .. "^7")
|
||||||
|
|
||||||
|
-- Spawn-Punkt bestimmen
|
||||||
|
local spawnPoint = station.trainSpawnPoint or vector4(station.coords.x - 500, station.coords.y, station.coords.z, station.coords.w)
|
||||||
|
|
||||||
-- Zug am Spawn-Punkt erstellen
|
-- Zug am Spawn-Punkt erstellen
|
||||||
local train = SpawnTrainAtLocation(station.trainSpawnPoint)
|
local train = SpawnTrainAtLocation(spawnPoint)
|
||||||
|
|
||||||
if not train then
|
if not train then
|
||||||
waitingForTrain = false
|
waitingForTrain = false
|
||||||
|
@ -173,9 +213,12 @@ function SpawnAndMoveTrainToStation(station, destination)
|
||||||
description = 'Zug konnte nicht gespawnt werden',
|
description = 'Zug konnte nicht gespawnt werden',
|
||||||
type = 'error'
|
type = 'error'
|
||||||
})
|
})
|
||||||
|
print("^1[TRAIN] Fehler beim Spawnen des Zugs^7")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
print("^2[TRAIN] Zug gespawnt, ID: " .. train .. "^7")
|
||||||
|
|
||||||
-- Zug zum Bahnhof fahren lassen
|
-- Zug zum Bahnhof fahren lassen
|
||||||
local targetCoords = vector3(station.coords.x, station.coords.y, station.coords.z)
|
local targetCoords = vector3(station.coords.x, station.coords.y, station.coords.z)
|
||||||
local arrived = false
|
local arrived = false
|
||||||
|
@ -196,6 +239,10 @@ function SpawnAndMoveTrainToStation(station, destination)
|
||||||
local trainCoords = GetEntityCoords(train)
|
local trainCoords = GetEntityCoords(train)
|
||||||
local distance = #(trainCoords - targetCoords)
|
local distance = #(trainCoords - targetCoords)
|
||||||
|
|
||||||
|
if Config.Debug then
|
||||||
|
print("^3[TRAIN] Zug Entfernung zum Bahnhof: " .. math.floor(distance) .. "m^7")
|
||||||
|
end
|
||||||
|
|
||||||
if distance < 100 then
|
if distance < 100 then
|
||||||
-- Langsamer werden
|
-- Langsamer werden
|
||||||
SetTrainSpeed(train, Config.TrainArrival.arrivalSpeed)
|
SetTrainSpeed(train, Config.TrainArrival.arrivalSpeed)
|
||||||
|
@ -208,6 +255,8 @@ function SpawnAndMoveTrainToStation(station, destination)
|
||||||
SetTrainCruiseSpeed(train, 0)
|
SetTrainCruiseSpeed(train, 0)
|
||||||
arrived = true
|
arrived = true
|
||||||
|
|
||||||
|
print("^2[TRAIN] Zug angekommen am Bahnhof: " .. station.name .. "^7")
|
||||||
|
|
||||||
-- Zug am Bahnhof registrieren
|
-- Zug am Bahnhof registrieren
|
||||||
trainAtStation[station.id] = train
|
trainAtStation[station.id] = train
|
||||||
waitingForTrain = false
|
waitingForTrain = false
|
||||||
|
@ -223,6 +272,8 @@ function SpawnAndMoveTrainToStation(station, destination)
|
||||||
if Config.TrainArrival.despawnAfterWait then
|
if Config.TrainArrival.despawnAfterWait then
|
||||||
SetTimeout(Config.TrainArrival.waitTime, function()
|
SetTimeout(Config.TrainArrival.waitTime, function()
|
||||||
if trainAtStation[station.id] == train and not isRiding then
|
if trainAtStation[station.id] == train and not isRiding then
|
||||||
|
print("^3[TRAIN] Zug fährt ab - keine Passagiere^7")
|
||||||
|
|
||||||
lib:notify({
|
lib:notify({
|
||||||
title = '🚂 Zug fährt ab',
|
title = '🚂 Zug fährt ab',
|
||||||
description = 'Der Zug verlässt den Bahnhof',
|
description = 'Der Zug verlässt den Bahnhof',
|
||||||
|
@ -251,11 +302,12 @@ function SpawnAndMoveTrainToStation(station, destination)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Zielmenü für Fahrt öffnen
|
-- In Zug einsteigen
|
||||||
function OpenDestinationMenu(train, currentStation)
|
function BoardTrain(train, station)
|
||||||
-- Hier das normale Zielmenü wie vorher, aber mit dem wartenden Zug
|
|
||||||
local playerPed = PlayerPedId()
|
local playerPed = PlayerPedId()
|
||||||
SetPedIntoVehicle(playerPed, train, 1)
|
SetPedIntoVehicle(playerPed, train, 1)
|
||||||
|
isRiding = true
|
||||||
|
currentTrain = train
|
||||||
|
|
||||||
lib:notify({
|
lib:notify({
|
||||||
title = '🚂 Willkommen an Bord',
|
title = '🚂 Willkommen an Bord',
|
||||||
|
@ -265,10 +317,30 @@ function OpenDestinationMenu(train, currentStation)
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Hier würde die normale Zugfahrt-Logik weitergehen
|
-- Hier würde die normale Zugfahrt-Logik weitergehen
|
||||||
-- StartTrainJourney(train, destination) etc.
|
-- Für jetzt einfach nach 10 Sekunden wieder aussteigen lassen
|
||||||
|
SetTimeout(10000, function()
|
||||||
|
TaskLeaveVehicle(playerPed, train, 0)
|
||||||
|
isRiding = false
|
||||||
|
currentTrain = nil
|
||||||
|
trainAtStation[station.id] = nil
|
||||||
|
|
||||||
|
lib:notify({
|
||||||
|
title = '🚂 Ankunft',
|
||||||
|
description = 'Sie sind angekommen',
|
||||||
|
type = 'success'
|
||||||
|
})
|
||||||
|
|
||||||
|
-- Zug wegfahren lassen
|
||||||
|
SetTrainSpeed(train, 15.0)
|
||||||
|
SetTimeout(5000, function()
|
||||||
|
if DoesEntityExist(train) then
|
||||||
|
DeleteMissionTrain(train)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Hilfsfunktionen
|
-- Zug spawnen
|
||||||
function SpawnTrainAtLocation(spawnPoint)
|
function SpawnTrainAtLocation(spawnPoint)
|
||||||
local model = GetHashKey(Config.TrainCars.main)
|
local model = GetHashKey(Config.TrainCars.main)
|
||||||
|
|
||||||
|
@ -285,21 +357,24 @@ function SpawnTrainAtLocation(spawnPoint)
|
||||||
SetTrainCruiseSpeed(train, 0.0)
|
SetTrainCruiseSpeed(train, 0.0)
|
||||||
|
|
||||||
-- Waggons hinzufügen
|
-- Waggons hinzufügen
|
||||||
Wait(1000)
|
CreateThread(function()
|
||||||
for _, carModel in pairs(Config.TrainCars.cars) do
|
Wait(1000)
|
||||||
local carHash = GetHashKey(carModel)
|
for _, carModel in pairs(Config.TrainCars.cars) do
|
||||||
RequestModel(carHash)
|
local carHash = GetHashKey(carModel)
|
||||||
while not HasModelLoaded(carHash) do
|
RequestModel(carHash)
|
||||||
Wait(500)
|
while not HasModelLoaded(carHash) do
|
||||||
|
Wait(500)
|
||||||
|
end
|
||||||
|
CreateMissionTrainCar(train, carHash, false, false, false)
|
||||||
end
|
end
|
||||||
CreateMissionTrainCar(train, carHash, false, false, false)
|
end)
|
||||||
end
|
|
||||||
|
|
||||||
return train
|
return train
|
||||||
end
|
end
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Hilfsfunktionen
|
||||||
function GetStationById(id)
|
function GetStationById(id)
|
||||||
for _, station in pairs(Config.TrainStations) do
|
for _, station in pairs(Config.TrainStations) do
|
||||||
if station.id == id then
|
if station.id == id then
|
||||||
|
@ -367,6 +442,22 @@ function DrawText3D(x, y, z, text)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Debug Commands
|
||||||
|
RegisterCommand('trainblips', function()
|
||||||
|
CreateStationBlips()
|
||||||
|
print("^2[TRAIN] Blips neu erstellt^7")
|
||||||
|
end)
|
||||||
|
|
||||||
|
RegisterCommand('traintest', function()
|
||||||
|
local playerCoords = GetEntityCoords(PlayerPedId())
|
||||||
|
print("^3[TRAIN] Player Position: " .. playerCoords.x .. ", " .. playerCoords.y .. ", " .. playerCoords.z .. "^7")
|
||||||
|
|
||||||
|
for i, station in pairs(Config.TrainStations) do
|
||||||
|
local distance = #(playerCoords - vector3(station.coords.x, station.coords.y, station.coords.z))
|
||||||
|
print("^3[TRAIN] " .. station.name .. " - Entfernung: " .. math.floor(distance) .. "m^7")
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
-- Cleanup
|
-- Cleanup
|
||||||
AddEventHandler('onResourceStop', function(resourceName)
|
AddEventHandler('onResourceStop', function(resourceName)
|
||||||
if GetCurrentResourceName() == resourceName then
|
if GetCurrentResourceName() == resourceName then
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue