forked from Simnation/Main
ed
This commit is contained in:
parent
d714c6bb8b
commit
d11ff6ab63
4 changed files with 0 additions and 805 deletions
|
@ -1,521 +0,0 @@
|
||||||
local QBCore = exports['qb-core']:GetCoreObject()
|
|
||||||
local lib = exports.ox_lib
|
|
||||||
local PlayerData = {}
|
|
||||||
|
|
||||||
-- Zug Status
|
|
||||||
local currentTrain = nil
|
|
||||||
local isRiding = false
|
|
||||||
local trainAtStation = {}
|
|
||||||
local cinemaCam = nil
|
|
||||||
local waitingForTrain = false
|
|
||||||
|
|
||||||
-- Beim Laden des Scripts
|
|
||||||
CreateThread(function()
|
|
||||||
Wait(1000)
|
|
||||||
CreateStationBlips()
|
|
||||||
print("^2[TRAIN] Blips erstellt^7")
|
|
||||||
end)
|
|
||||||
|
|
||||||
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
|
|
||||||
PlayerData = QBCore.Functions.GetPlayerData()
|
|
||||||
Wait(2000)
|
|
||||||
CreateStationBlips()
|
|
||||||
print("^2[TRAIN] Player loaded - Blips erstellt^7")
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- Bahnhof Blips erstellen
|
|
||||||
function CreateStationBlips()
|
|
||||||
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)
|
|
||||||
SetBlipSprite(blip, station.blip.sprite)
|
|
||||||
SetBlipDisplay(blip, 4)
|
|
||||||
SetBlipScale(blip, station.blip.scale)
|
|
||||||
SetBlipColour(blip, station.blip.color)
|
|
||||||
BeginTextCommandSetBlipName("STRING")
|
|
||||||
AddTextComponentString("🚂 " .. station.name)
|
|
||||||
EndTextCommandSetBlipName(blip)
|
|
||||||
|
|
||||||
print("^2[TRAIN] Blip erstellt für: " .. station.name .. "^7")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Bahnhof Interaktionen - Haupt-Loop
|
|
||||||
CreateThread(function()
|
|
||||||
print("^2[TRAIN] Interaktions-Loop gestartet^7")
|
|
||||||
|
|
||||||
while true do
|
|
||||||
local sleep = 1000
|
|
||||||
local playerPed = PlayerPedId()
|
|
||||||
local playerCoords = GetEntityCoords(playerPed)
|
|
||||||
|
|
||||||
if not isRiding then
|
|
||||||
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
|
|
||||||
|
|
||||||
-- DrawText anzeigen
|
|
||||||
DrawText3D(interactionPoint.x, interactionPoint.y, interactionPoint.z + 1.0,
|
|
||||||
Config.DrawText.stationText)
|
|
||||||
|
|
||||||
-- Debug Info
|
|
||||||
if Config.Debug then
|
|
||||||
DrawText3D(interactionPoint.x, interactionPoint.y, interactionPoint.z + 2.0,
|
|
||||||
"Station: " .. station.name .. " | Dist: " .. math.floor(distance))
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Interaktion
|
|
||||||
if IsControlJustPressed(0, 38) then -- E
|
|
||||||
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
|
|
||||||
sleep = 0
|
|
||||||
DrawText3D(trainCoords.x, trainCoords.y, trainCoords.z + 2.0, Config.DrawText.boardText)
|
|
||||||
|
|
||||||
if IsControlJustPressed(0, 38) then -- E
|
|
||||||
print("^3[TRAIN] Einsteigen in Zug^7")
|
|
||||||
BoardTrain(train, station)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
Wait(sleep)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- Bahnhof Menü öffnen
|
|
||||||
function OpenStationMenu(station)
|
|
||||||
print("^3[TRAIN] Öffne Menü für Station: " .. station.name .. "^7")
|
|
||||||
|
|
||||||
local options = {}
|
|
||||||
|
|
||||||
-- Verfügbare Ziele anzeigen
|
|
||||||
if station.destinations then
|
|
||||||
for _, destinationId in pairs(station.destinations) do
|
|
||||||
local destination = GetStationById(destinationId)
|
|
||||||
if destination then
|
|
||||||
local price = CalculatePrice(station, destination)
|
|
||||||
local icon = GetStationIcon(destination.name)
|
|
||||||
|
|
||||||
table.insert(options, {
|
|
||||||
title = icon .. " " .. destination.name,
|
|
||||||
description = destination.description .. " - Preis: $" .. price,
|
|
||||||
icon = 'train',
|
|
||||||
onSelect = function()
|
|
||||||
print("^3[TRAIN] Ziel gewählt: " .. destination.name .. "^7")
|
|
||||||
CallTrainToStation(station, destination, price)
|
|
||||||
end,
|
|
||||||
metadata = {
|
|
||||||
{label = "Preis", value = "$" .. price},
|
|
||||||
{label = "Entfernung", value = math.floor(GetDistanceBetweenStations(station, destination)) .. "m"}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if #options == 0 then
|
|
||||||
table.insert(options, {
|
|
||||||
title = "Keine Ziele verfügbar",
|
|
||||||
description = "Momentan keine Verbindungen",
|
|
||||||
disabled = true
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
table.insert(options, {
|
|
||||||
title = "❌ Abbrechen",
|
|
||||||
description = "Menü schließen",
|
|
||||||
icon = 'xmark'
|
|
||||||
})
|
|
||||||
|
|
||||||
lib:registerContext({
|
|
||||||
id = 'station_menu',
|
|
||||||
title = "🚉 " .. station.name,
|
|
||||||
options = options,
|
|
||||||
position = Config.Menu.position
|
|
||||||
})
|
|
||||||
|
|
||||||
lib:showContext('station_menu')
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Zug zum Bahnhof rufen
|
|
||||||
function CallTrainToStation(station, destination, price)
|
|
||||||
print("^3[TRAIN] Rufe Zug für " .. station.name .. " -> " .. destination.name .. "^7")
|
|
||||||
|
|
||||||
-- Geld prüfen
|
|
||||||
QBCore.Functions.TriggerCallback('train:server:canAfford', function(canAfford)
|
|
||||||
if canAfford then
|
|
||||||
waitingForTrain = true
|
|
||||||
|
|
||||||
lib:notify({
|
|
||||||
title = '🚂 ' .. Config.Menu.texts.trainComing,
|
|
||||||
description = 'Der Zug fährt zum Bahnhof',
|
|
||||||
type = 'info',
|
|
||||||
duration = Config.Notifications.duration.medium
|
|
||||||
})
|
|
||||||
|
|
||||||
-- Zug spawnen und heranfahren lassen
|
|
||||||
SpawnAndMoveTrainToStation(station, destination)
|
|
||||||
else
|
|
||||||
lib:notify({
|
|
||||||
title = 'Nicht genug Geld',
|
|
||||||
description = "Benötigt: $" .. price,
|
|
||||||
type = 'error',
|
|
||||||
duration = Config.Notifications.duration.short
|
|
||||||
})
|
|
||||||
end
|
|
||||||
end, price)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Zug spawnen und zum Bahnhof fahren lassen
|
|
||||||
function SpawnAndMoveTrainToStation(station, destination)
|
|
||||||
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
|
|
||||||
local train = SpawnTrainAtLocation(spawnPoint)
|
|
||||||
|
|
||||||
if not train then
|
|
||||||
waitingForTrain = false
|
|
||||||
lib:notify({
|
|
||||||
title = 'Fehler',
|
|
||||||
description = 'Zug konnte nicht gespawnt werden',
|
|
||||||
type = 'error'
|
|
||||||
})
|
|
||||||
print("^1[TRAIN] Fehler beim Spawnen des Zugs^7")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
print("^2[TRAIN] Zug gespawnt, ID: " .. train .. "^7")
|
|
||||||
|
|
||||||
-- Zug zum Bahnhof fahren lassen
|
|
||||||
local targetCoords = vector3(station.coords.x, station.coords.y, station.coords.z)
|
|
||||||
local arrived = false
|
|
||||||
|
|
||||||
-- Zug in Bewegung setzen
|
|
||||||
SetTrainSpeed(train, Config.TrainArrival.approachSpeed)
|
|
||||||
SetTrainCruiseSpeed(train, Config.TrainArrival.approachSpeed)
|
|
||||||
|
|
||||||
lib:notify({
|
|
||||||
title = '🚂 ' .. Config.Menu.texts.trainArriving,
|
|
||||||
description = 'Der Zug nähert sich dem Bahnhof',
|
|
||||||
type = 'info',
|
|
||||||
duration = Config.Notifications.duration.short
|
|
||||||
})
|
|
||||||
|
|
||||||
-- Warten bis Zug am Bahnhof ankommt
|
|
||||||
while not arrived and DoesEntityExist(train) do
|
|
||||||
local trainCoords = GetEntityCoords(train)
|
|
||||||
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
|
|
||||||
-- Langsamer werden
|
|
||||||
SetTrainSpeed(train, Config.TrainArrival.arrivalSpeed)
|
|
||||||
SetTrainCruiseSpeed(train, Config.TrainArrival.arrivalSpeed)
|
|
||||||
end
|
|
||||||
|
|
||||||
if distance < 30 then
|
|
||||||
-- Ankunft
|
|
||||||
SetTrainSpeed(train, 0)
|
|
||||||
SetTrainCruiseSpeed(train, 0)
|
|
||||||
arrived = true
|
|
||||||
|
|
||||||
print("^2[TRAIN] Zug angekommen am Bahnhof: " .. station.name .. "^7")
|
|
||||||
|
|
||||||
-- Zug am Bahnhof registrieren
|
|
||||||
trainAtStation[station.id] = train
|
|
||||||
waitingForTrain = false
|
|
||||||
|
|
||||||
lib:notify({
|
|
||||||
title = '🚂 ' .. Config.Menu.texts.trainWaiting,
|
|
||||||
description = 'Zug wartet am Bahnhof - [E] zum Einsteigen',
|
|
||||||
type = 'success',
|
|
||||||
duration = Config.Notifications.duration.long
|
|
||||||
})
|
|
||||||
|
|
||||||
-- Zug nach Wartezeit entfernen wenn niemand einsteigt
|
|
||||||
if Config.TrainArrival.despawnAfterWait then
|
|
||||||
SetTimeout(Config.TrainArrival.waitTime, function()
|
|
||||||
if trainAtStation[station.id] == train and not isRiding then
|
|
||||||
print("^3[TRAIN] Zug fährt ab - keine Passagiere^7")
|
|
||||||
|
|
||||||
lib:notify({
|
|
||||||
title = '🚂 Zug fährt ab',
|
|
||||||
description = 'Der Zug verlässt den Bahnhof',
|
|
||||||
type = 'warning',
|
|
||||||
duration = Config.Notifications.duration.short
|
|
||||||
})
|
|
||||||
|
|
||||||
-- Zug wegfahren lassen
|
|
||||||
SetTrainSpeed(train, 15.0)
|
|
||||||
SetTrainCruiseSpeed(train, 15.0)
|
|
||||||
|
|
||||||
SetTimeout(10000, function()
|
|
||||||
if DoesEntityExist(train) then
|
|
||||||
DeleteMissionTrain(train)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
trainAtStation[station.id] = nil
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
Wait(1000)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- In Zug einsteigen
|
|
||||||
function BoardTrain(train, station)
|
|
||||||
local playerPed = PlayerPedId()
|
|
||||||
SetPedIntoVehicle(playerPed, train, 1)
|
|
||||||
isRiding = true
|
|
||||||
currentTrain = train
|
|
||||||
|
|
||||||
lib:notify({
|
|
||||||
title = '🚂 Willkommen an Bord',
|
|
||||||
description = 'Die Fahrt beginnt in Kürze',
|
|
||||||
type = 'success',
|
|
||||||
duration = Config.Notifications.duration.medium
|
|
||||||
})
|
|
||||||
|
|
||||||
-- 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
|
|
||||||
|
|
||||||
-- KORRIGIERTE Zug Spawn-Funktion
|
|
||||||
function SpawnTrainAtLocation(spawnPoint)
|
|
||||||
print("^3[TRAIN] Versuche Zug zu spawnen bei: " .. spawnPoint.x .. ", " .. spawnPoint.y .. ", " .. spawnPoint.z .. "^7")
|
|
||||||
|
|
||||||
-- Alle Models vorladen
|
|
||||||
local mainModel = GetHashKey(Config.TrainCars.main)
|
|
||||||
print("^3[TRAIN] Lade Hauptmodel: " .. Config.TrainCars.main .. " (Hash: " .. mainModel .. ")^7")
|
|
||||||
|
|
||||||
RequestModel(mainModel)
|
|
||||||
local timeout = 0
|
|
||||||
while not HasModelLoaded(mainModel) and timeout < 10000 do
|
|
||||||
Wait(100)
|
|
||||||
timeout = timeout + 100
|
|
||||||
end
|
|
||||||
|
|
||||||
if not HasModelLoaded(mainModel) then
|
|
||||||
print("^1[TRAIN] Hauptmodel konnte nicht geladen werden: " .. Config.TrainCars.main .. "^7")
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Waggon-Models vorladen
|
|
||||||
local carModels = {}
|
|
||||||
for _, carName in pairs(Config.TrainCars.cars) do
|
|
||||||
local carHash = GetHashKey(carName)
|
|
||||||
print("^3[TRAIN] Lade Waggon-Model: " .. carName .. " (Hash: " .. carHash .. ")^7")
|
|
||||||
|
|
||||||
RequestModel(carHash)
|
|
||||||
timeout = 0
|
|
||||||
while not HasModelLoaded(carHash) and timeout < 5000 do
|
|
||||||
Wait(100)
|
|
||||||
timeout = timeout + 100
|
|
||||||
end
|
|
||||||
|
|
||||||
if HasModelLoaded(carHash) then
|
|
||||||
table.insert(carModels, carHash)
|
|
||||||
print("^2[TRAIN] Waggon-Model geladen: " .. carName .. "^7")
|
|
||||||
else
|
|
||||||
print("^1[TRAIN] Waggon-Model konnte nicht geladen werden: " .. carName .. "^7")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Zug erstellen
|
|
||||||
local train = CreateMissionTrain(24, spawnPoint.x, spawnPoint.y, spawnPoint.z, true)
|
|
||||||
|
|
||||||
if DoesEntityExist(train) then
|
|
||||||
print("^2[TRAIN] Zug erfolgreich erstellt, ID: " .. train .. "^7")
|
|
||||||
|
|
||||||
SetEntityHeading(train, spawnPoint.w)
|
|
||||||
SetTrainSpeed(train, 0.0)
|
|
||||||
SetTrainCruiseSpeed(train, 0.0)
|
|
||||||
|
|
||||||
-- Waggons hinzufügen (nur die erfolgreich geladenen)
|
|
||||||
CreateThread(function()
|
|
||||||
Wait(2000) -- Länger warten
|
|
||||||
|
|
||||||
for _, carHash in pairs(carModels) do
|
|
||||||
print("^3[TRAIN] Füge Waggon hinzu: " .. carHash .. "^7")
|
|
||||||
local success = CreateMissionTrainCar(train, carHash, false, false, false)
|
|
||||||
if success then
|
|
||||||
print("^2[TRAIN] Waggon erfolgreich hinzugefügt^7")
|
|
||||||
else
|
|
||||||
print("^1[TRAIN] Fehler beim Hinzufügen des Waggons^7")
|
|
||||||
end
|
|
||||||
Wait(1000)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
return train
|
|
||||||
else
|
|
||||||
print("^1[TRAIN] CreateMissionTrain fehlgeschlagen^7")
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Hilfsfunktionen (bleiben gleich)
|
|
||||||
function GetStationById(id)
|
|
||||||
for _, station in pairs(Config.TrainStations) do
|
|
||||||
if station.id == id then
|
|
||||||
return station
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
|
|
||||||
function CalculatePrice(fromStation, toStation)
|
|
||||||
local distance = GetDistanceBetweenStations(fromStation, toStation)
|
|
||||||
local price = Config.PriceCalculation.basePrice + (distance * Config.PriceCalculation.pricePerKm / 100)
|
|
||||||
|
|
||||||
for _, freeStation in pairs(Config.PriceCalculation.freeStations) do
|
|
||||||
if fromStation.id == freeStation then
|
|
||||||
price = price * 0.5
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return math.min(math.floor(price), Config.PriceCalculation.maxPrice)
|
|
||||||
end
|
|
||||||
|
|
||||||
function GetDistanceBetweenStations(station1, station2)
|
|
||||||
local coords1 = vector3(station1.coords.x, station1.coords.y, station1.coords.z)
|
|
||||||
local coords2 = vector3(station2.coords.x, station2.coords.y, station2.coords.z)
|
|
||||||
return #(coords1 - coords2)
|
|
||||||
end
|
|
||||||
|
|
||||||
function GetStationIcon(stationName)
|
|
||||||
if string.find(stationName:lower(), "depot") then
|
|
||||||
return Config.Menu.stationIcons.depot
|
|
||||||
elseif string.find(stationName:lower(), "island") then
|
|
||||||
return Config.Menu.stationIcons.port
|
|
||||||
elseif string.find(stationName:lower(), "terminal") then
|
|
||||||
return Config.Menu.stationIcons.industrial
|
|
||||||
elseif string.find(stationName:lower(), "bay") then
|
|
||||||
return Config.Menu.stationIcons.rural
|
|
||||||
elseif string.find(stationName:lower(), "hauptbahnhof") then
|
|
||||||
return Config.Menu.stationIcons.main
|
|
||||||
else
|
|
||||||
return Config.Menu.stationIcons.city
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function DrawText3D(x, y, z, text)
|
|
||||||
local onScreen, _x, _y = World3dToScreen2d(x, y, z)
|
|
||||||
|
|
||||||
if onScreen then
|
|
||||||
SetTextScale(Config.DrawText.scale, Config.DrawText.scale)
|
|
||||||
SetTextFont(Config.DrawText.font)
|
|
||||||
SetTextProportional(1)
|
|
||||||
SetTextColour(Config.DrawText.color.r, Config.DrawText.color.g, Config.DrawText.color.b, Config.DrawText.color.a)
|
|
||||||
SetTextEntry("STRING")
|
|
||||||
SetTextCentre(1)
|
|
||||||
AddTextComponentString(text)
|
|
||||||
DrawText(_x, _y)
|
|
||||||
|
|
||||||
local factor = (string.len(text)) / 370
|
|
||||||
DrawRect(_x, _y + 0.0125, 0.015 + factor, 0.03,
|
|
||||||
Config.DrawText.backgroundColor.r,
|
|
||||||
Config.DrawText.backgroundColor.g,
|
|
||||||
Config.DrawText.backgroundColor.b,
|
|
||||||
Config.DrawText.backgroundColor.a)
|
|
||||||
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)
|
|
||||||
|
|
||||||
RegisterCommand('testtrainspawn', function()
|
|
||||||
local playerCoords = GetEntityCoords(PlayerPedId())
|
|
||||||
local playerHeading = GetEntityHeading(PlayerPedId())
|
|
||||||
local spawnPoint = vector4(playerCoords.x + 10, playerCoords.y, playerCoords.z, playerHeading)
|
|
||||||
|
|
||||||
local train = SpawnTrainAtLocation(spawnPoint)
|
|
||||||
if train then
|
|
||||||
print("^2[TRAIN] Test-Zug gespawnt!^7")
|
|
||||||
else
|
|
||||||
print("^1[TRAIN] Test-Zug spawn fehlgeschlagen!^7")
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- Cleanup
|
|
||||||
AddEventHandler('onResourceStop', function(resourceName)
|
|
||||||
if GetCurrentResourceName() == resourceName then
|
|
||||||
for stationId, train in pairs(trainAtStation) do
|
|
||||||
if DoesEntityExist(train) then
|
|
||||||
DeleteMissionTrain(train)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
|
@ -1,227 +0,0 @@
|
||||||
Config = {}
|
|
||||||
|
|
||||||
-- Debug aktivieren
|
|
||||||
Config.Debug = true
|
|
||||||
Config.DefaultCurrency = 'cash'
|
|
||||||
Config.InteractionDistance = 5.0
|
|
||||||
Config.StationInteractionDistance = 10.0
|
|
||||||
|
|
||||||
-- Zug Ankunft Einstellungen
|
|
||||||
Config.TrainArrival = {
|
|
||||||
enabled = true,
|
|
||||||
spawnDistance = 500.0,
|
|
||||||
approachSpeed = 15.0,
|
|
||||||
arrivalSpeed = 5.0,
|
|
||||||
waitTime = 30000,
|
|
||||||
despawnAfterWait = true
|
|
||||||
}
|
|
||||||
|
|
||||||
-- Korrigierte Zug Konfiguration - Nur funktionierende Models
|
|
||||||
Config.TrainCars = {
|
|
||||||
main = "freight", -- Hauptlok
|
|
||||||
cars = {"freightcar"} -- Nur ein funktionierender Waggon
|
|
||||||
}
|
|
||||||
|
|
||||||
-- Alle verfügbaren Zug-Models (zum Testen)
|
|
||||||
Config.AvailableTrainModels = {
|
|
||||||
"freight", -- Güterzug Lok
|
|
||||||
"freightcar", -- Güterwagon
|
|
||||||
"freightcont1", -- Container 1
|
|
||||||
"freightcont2", -- Container 2
|
|
||||||
"freightgrain", -- Getreide Waggon
|
|
||||||
"tankercar", -- Tankwagon
|
|
||||||
"metrotrain", -- Metro
|
|
||||||
"freight2" -- Alternative Lok
|
|
||||||
}
|
|
||||||
|
|
||||||
-- Rest der Config bleibt gleich...
|
|
||||||
Config.TrainStations = {
|
|
||||||
{
|
|
||||||
id = "sandy_depot",
|
|
||||||
coords = vector4(2533.0, 2833.0, 38.0, 0.0),
|
|
||||||
name = "Sandy Shores Depot",
|
|
||||||
description = "Hauptdepot in Sandy Shores",
|
|
||||||
trainSpawnPoint = vector4(2033.0, 2833.0, 38.0, 0.0),
|
|
||||||
interactionPoint = vector3(2535.0, 2835.0, 38.0),
|
|
||||||
blip = {
|
|
||||||
sprite = 795,
|
|
||||||
color = 2,
|
|
||||||
scale = 0.8
|
|
||||||
},
|
|
||||||
destinations = {
|
|
||||||
"sandy_north", "ls_depot", "elysian", "terminal", "downtown", "paleto"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id = "sandy_north",
|
|
||||||
coords = vector4(2606.0, 2927.0, 40.0, 90.0),
|
|
||||||
name = "Sandy Shores Nord",
|
|
||||||
description = "Nördlicher Bahnhof von Sandy Shores",
|
|
||||||
trainSpawnPoint = vector4(2106.0, 2927.0, 40.0, 90.0),
|
|
||||||
interactionPoint = vector3(2608.0, 2929.0, 40.0),
|
|
||||||
blip = {
|
|
||||||
sprite = 795,
|
|
||||||
color = 3,
|
|
||||||
scale = 0.7
|
|
||||||
},
|
|
||||||
destinations = {
|
|
||||||
"sandy_depot", "ls_depot", "elysian", "terminal", "downtown", "paleto"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id = "ls_depot",
|
|
||||||
coords = vector4(1164.0, -3250.0, 7.0, 180.0),
|
|
||||||
name = "Los Santos Hauptbahnhof",
|
|
||||||
description = "Zentraler Bahnhof in Los Santos",
|
|
||||||
trainSpawnPoint = vector4(1164.0, -2750.0, 7.0, 180.0),
|
|
||||||
interactionPoint = vector3(1166.0, -3252.0, 7.0),
|
|
||||||
blip = {
|
|
||||||
sprite = 795,
|
|
||||||
color = 1,
|
|
||||||
scale = 0.9
|
|
||||||
},
|
|
||||||
destinations = {
|
|
||||||
"sandy_depot", "sandy_north", "elysian", "terminal", "downtown", "paleto"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id = "elysian",
|
|
||||||
coords = vector4(219.0, -2487.0, 6.0, 270.0),
|
|
||||||
name = "Elysian Island",
|
|
||||||
description = "Industriegebiet am Hafen",
|
|
||||||
trainSpawnPoint = vector4(719.0, -2487.0, 6.0, 270.0),
|
|
||||||
interactionPoint = vector3(217.0, -2489.0, 6.0),
|
|
||||||
blip = {
|
|
||||||
sprite = 795,
|
|
||||||
color = 4,
|
|
||||||
scale = 0.7
|
|
||||||
},
|
|
||||||
destinations = {
|
|
||||||
"sandy_depot", "sandy_north", "ls_depot", "terminal", "downtown", "paleto"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id = "terminal",
|
|
||||||
coords = vector4(-1100.0, -2724.0, 13.0, 0.0),
|
|
||||||
name = "Fracht Terminal",
|
|
||||||
description = "Großes Frachtterminal",
|
|
||||||
trainSpawnPoint = vector4(-1600.0, -2724.0, 13.0, 0.0),
|
|
||||||
interactionPoint = vector3(-1098.0, -2726.0, 13.0),
|
|
||||||
blip = {
|
|
||||||
sprite = 795,
|
|
||||||
color = 5,
|
|
||||||
scale = 0.8
|
|
||||||
},
|
|
||||||
destinations = {
|
|
||||||
"sandy_depot", "sandy_north", "ls_depot", "elysian", "downtown", "paleto"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id = "downtown",
|
|
||||||
coords = vector4(-500.0, -1500.0, 10.0, 45.0),
|
|
||||||
name = "Downtown Station",
|
|
||||||
description = "Bahnhof in der Innenstadt",
|
|
||||||
trainSpawnPoint = vector4(-1000.0, -1500.0, 10.0, 45.0),
|
|
||||||
interactionPoint = vector3(-498.0, -1502.0, 10.0),
|
|
||||||
blip = {
|
|
||||||
sprite = 795,
|
|
||||||
color = 6,
|
|
||||||
scale = 0.7
|
|
||||||
},
|
|
||||||
destinations = {
|
|
||||||
"sandy_depot", "sandy_north", "ls_depot", "elysian", "terminal", "paleto"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id = "paleto",
|
|
||||||
coords = vector4(100.0, 6500.0, 32.0, 180.0),
|
|
||||||
name = "Paleto Bay",
|
|
||||||
description = "Kleiner Bahnhof in Paleto Bay",
|
|
||||||
trainSpawnPoint = vector4(100.0, 6000.0, 32.0, 180.0),
|
|
||||||
interactionPoint = vector3(102.0, 6502.0, 32.0),
|
|
||||||
blip = {
|
|
||||||
sprite = 795,
|
|
||||||
color = 7,
|
|
||||||
scale = 0.7
|
|
||||||
},
|
|
||||||
destinations = {
|
|
||||||
"sandy_depot", "sandy_north", "ls_depot", "elysian", "terminal", "downtown"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
-- Preise basierend auf Entfernung
|
|
||||||
Config.PriceCalculation = {
|
|
||||||
basePrice = 25,
|
|
||||||
pricePerKm = 0.5,
|
|
||||||
maxPrice = 300,
|
|
||||||
freeStations = {"sandy_depot"}
|
|
||||||
}
|
|
||||||
|
|
||||||
-- Menü Einstellungen
|
|
||||||
Config.Menu = {
|
|
||||||
title = "🚂 Zugfahrkarten",
|
|
||||||
subtitle = "Wählen Sie Ihr Reiseziel",
|
|
||||||
position = "top-right",
|
|
||||||
|
|
||||||
texts = {
|
|
||||||
callTrain = "Zug rufen",
|
|
||||||
selectDestination = "Ziel auswählen",
|
|
||||||
trainComing = "Zug wird gerufen...",
|
|
||||||
trainArriving = "Zug fährt ein",
|
|
||||||
trainWaiting = "Zug wartet am Bahnhof",
|
|
||||||
boardTrain = "Zug besteigen",
|
|
||||||
trainLeaving = "Zug fährt ab",
|
|
||||||
noDestinations = "Keine Ziele verfügbar",
|
|
||||||
cancel = "Abbrechen"
|
|
||||||
},
|
|
||||||
|
|
||||||
stationIcons = {
|
|
||||||
depot = "🏭",
|
|
||||||
city = "🏢",
|
|
||||||
industrial = "🏗️",
|
|
||||||
port = "⚓",
|
|
||||||
rural = "🌾",
|
|
||||||
main = "🚉"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
-- DrawText Einstellungen
|
|
||||||
Config.DrawText = {
|
|
||||||
font = 4,
|
|
||||||
scale = 0.35,
|
|
||||||
color = {r = 255, g = 255, b = 255, a = 215},
|
|
||||||
backgroundColor = {r = 41, g = 128, b = 185, a = 100},
|
|
||||||
stationText = "[E] Zug rufen",
|
|
||||||
boardText = "[E] Einsteigen",
|
|
||||||
emergencyText = "[F] Notfall-Ausstieg"
|
|
||||||
}
|
|
||||||
|
|
||||||
-- Kamera Einstellungen
|
|
||||||
Config.CinemaCamera = {
|
|
||||||
enabled = true,
|
|
||||||
switchInterval = {min = 8000, max = 12000},
|
|
||||||
positions = {
|
|
||||||
{
|
|
||||||
offset = vector3(15.0, 5.0, 5.0),
|
|
||||||
rotation = vector3(-10.0, 0.0, 90.0)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
offset = vector3(10.0, 15.0, 8.0),
|
|
||||||
rotation = vector3(-15.0, 0.0, 45.0)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
offset = vector3(-10.0, -15.0, 6.0),
|
|
||||||
rotation = vector3(-5.0, 0.0, -135.0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
-- Benachrichtigungen
|
|
||||||
Config.Notifications = {
|
|
||||||
duration = {
|
|
||||||
short = 3000,
|
|
||||||
medium = 5000,
|
|
||||||
long = 8000
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,24 +0,0 @@
|
||||||
fx_version 'cerulean'
|
|
||||||
game 'gta5'
|
|
||||||
|
|
||||||
description 'QBCore Train System with ox_lib'
|
|
||||||
version '2.0.0'
|
|
||||||
|
|
||||||
shared_scripts {
|
|
||||||
'config.lua'
|
|
||||||
}
|
|
||||||
|
|
||||||
client_scripts {
|
|
||||||
'client.lua'
|
|
||||||
}
|
|
||||||
|
|
||||||
server_scripts {
|
|
||||||
'server.lua'
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
'qb-core',
|
|
||||||
'ox_lib'
|
|
||||||
}
|
|
||||||
|
|
||||||
lua54 'yes'
|
|
|
@ -1,33 +0,0 @@
|
||||||
local QBCore = exports['qb-core']:GetCoreObject()
|
|
||||||
|
|
||||||
-- Geld prüfen
|
|
||||||
QBCore.Functions.CreateCallback('train:server:canAfford', function(source, cb, price)
|
|
||||||
local Player = QBCore.Functions.GetPlayer(source)
|
|
||||||
if Player then
|
|
||||||
local money = Player.PlayerData.money[Config.DefaultCurrency]
|
|
||||||
if money >= price then
|
|
||||||
Player.Functions.RemoveMoney(Config.DefaultCurrency, price)
|
|
||||||
cb(true)
|
|
||||||
else
|
|
||||||
cb(false)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
cb(false)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- Journey Log
|
|
||||||
RegisterNetEvent('train:server:logJourney', function(from, to, price)
|
|
||||||
if not Config.DebugOptions.logJourneys then return end
|
|
||||||
|
|
||||||
local src = source
|
|
||||||
local Player = QBCore.Functions.GetPlayer(src)
|
|
||||||
|
|
||||||
if Player then
|
|
||||||
print(string.format("[TRAIN] %s (%s) - %s → %s ($%d)",
|
|
||||||
Player.PlayerData.charinfo.firstname .. " " .. Player.PlayerData.charinfo.lastname,
|
|
||||||
Player.PlayerData.citizenid,
|
|
||||||
from, to, price
|
|
||||||
))
|
|
||||||
end
|
|
||||||
end)
|
|
Loading…
Add table
Add a link
Reference in a new issue