local QBCore = exports['qb-core']:GetCoreObject() -- Debug Print print("^2[TRAIN-TRIGGER]^7 Server Script wird geladen...") -- Einfache Locations local triggerLocations = { {x = 215.3, y = -810.1, z = 30.7, name = "Legion Square"}, {x = -265.0, y = -957.3, z = 31.2, name = "Pillbox Hospital"}, } -- Einfacher Test Command RegisterCommand('traintest', function(source, args, rawCommand) print("^3[TRAIN-TRIGGER]^7 Command traintest ausgeführt von Spieler: " .. source) local Player = QBCore.Functions.GetPlayer(source) if Player then print("^2[TRAIN-TRIGGER]^7 QBCore Player gefunden: " .. Player.PlayerData.name) TriggerClientEvent('train:startscenario', source, 'Welcome') TriggerClientEvent('QBCore:Notify', source, 'Train Test erfolgreich!', 'success') else print("^1[TRAIN-TRIGGER]^7 FEHLER: QBCore Player nicht gefunden!") TriggerClientEvent('chatMessage', source, "SYSTEM", "error", "QBCore Player nicht gefunden!") end end, false) -- Einfacher Location Command RegisterCommand('starttrain', function(source, args, rawCommand) print("^3[TRAIN-TRIGGER]^7 starttrain Command von Spieler: " .. source) local playerPed = GetPlayerPed(source) local playerCoords = GetEntityCoords(playerPed) print("^3[TRAIN-TRIGGER]^7 Spieler Position: " .. playerCoords.x .. ", " .. playerCoords.y .. ", " .. playerCoords.z) -- Finde nächste Location local closestDistance = 999999 local closestLocation = nil for i, location in ipairs(triggerLocations) do local distance = #(playerCoords - vector3(location.x, location.y, location.z)) print("^3[TRAIN-TRIGGER]^7 Distanz zu " .. location.name .. ": " .. distance) if distance < closestDistance then closestDistance = distance closestLocation = location end end if closestDistance <= 100.0 then -- Größerer Radius zum Testen print("^2[TRAIN-TRIGGER]^7 Triggering Event für Spieler: " .. source) TriggerClientEvent('train:startscenario', source, 'Welcome') TriggerClientEvent('QBCore:Notify', source, 'Train gestartet bei: ' .. closestLocation.name, 'success') else print("^1[TRAIN-TRIGGER]^7 Spieler zu weit weg. Nächste Distanz: " .. closestDistance) TriggerClientEvent('QBCore:Notify', source, 'Zu weit weg! Nächste Distanz: ' .. math.floor(closestDistance) .. 'm', 'error') end end, false) -- Locations anzeigen RegisterCommand('trainlocs', function(source, args, rawCommand) TriggerClientEvent('chatMessage', source, "TRAIN-LOCATIONS", "info", "=== Train Locations ===") for i, location in ipairs(triggerLocations) do TriggerClientEvent('chatMessage', source, "TRAIN", "normal", i .. ". " .. location.name .. " (" .. math.floor(location.x) .. ", " .. math.floor(location.y) .. ", " .. math.floor(location.z) .. ")") end end, false) -- Event Handler RegisterNetEvent('train:requestStart', function() local source = source print("^3[TRAIN-TRIGGER]^7 train:requestStart Event von Spieler: " .. source) TriggerClientEvent('train:startscenario', source, 'Welcome') TriggerClientEvent('QBCore:Notify', source, 'Train via Event gestartet!', 'success') end) print("^2[TRAIN-TRIGGER]^7 Server Script geladen! Commands: /traintest, /starttrain, /trainlocs")