1
0
Fork 0
forked from Simnation/Main
Main/resources/[standalone]/start_train/server/server.lua

78 lines
3.3 KiB
Lua
Raw Normal View History

2025-08-13 16:59:56 +02:00
local QBCore = exports['qb-core']:GetCoreObject()
2025-08-13 17:06:31 +02:00
-- Debug Print
print("^2[TRAIN-TRIGGER]^7 Server Script wird geladen...")
-- Einfache Locations
2025-08-13 16:59:56 +02:00
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"},
}
2025-08-13 17:06:31 +02:00
-- Einfacher Test Command
RegisterCommand('traintest', function(source, args, rawCommand)
print("^3[TRAIN-TRIGGER]^7 Command traintest ausgeführt von Spieler: " .. source)
2025-08-13 16:59:56 +02:00
local Player = QBCore.Functions.GetPlayer(source)
2025-08-13 17:06:31 +02:00
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)
2025-08-13 16:59:56 +02:00
local playerPed = GetPlayerPed(source)
local playerCoords = GetEntityCoords(playerPed)
2025-08-13 17:06:31 +02:00
print("^3[TRAIN-TRIGGER]^7 Spieler Position: " .. playerCoords.x .. ", " .. playerCoords.y .. ", " .. playerCoords.z)
-- Finde nächste Location
local closestDistance = 999999
2025-08-13 16:59:56 +02:00
local closestLocation = nil
for i, location in ipairs(triggerLocations) do
local distance = #(playerCoords - vector3(location.x, location.y, location.z))
2025-08-13 17:06:31 +02:00
print("^3[TRAIN-TRIGGER]^7 Distanz zu " .. location.name .. ": " .. distance)
2025-08-13 16:59:56 +02:00
if distance < closestDistance then
closestDistance = distance
closestLocation = location
end
end
2025-08-13 17:06:31 +02:00
if closestDistance <= 100.0 then -- Größerer Radius zum Testen
print("^2[TRAIN-TRIGGER]^7 Triggering Event für Spieler: " .. source)
2025-08-13 16:59:56 +02:00
TriggerClientEvent('train:startscenario', source, 'Welcome')
2025-08-13 17:06:31 +02:00
TriggerClientEvent('QBCore:Notify', source, 'Train gestartet bei: ' .. closestLocation.name, 'success')
2025-08-13 16:59:56 +02:00
else
2025-08-13 17:06:31 +02:00
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')
2025-08-13 16:59:56 +02:00
end
2025-08-13 17:06:31 +02:00
end, false)
2025-08-13 16:59:56 +02:00
2025-08-13 17:06:31 +02:00
-- Locations anzeigen
RegisterCommand('trainlocs', function(source, args, rawCommand)
TriggerClientEvent('chatMessage', source, "TRAIN-LOCATIONS", "info", "=== Train Locations ===")
2025-08-13 16:59:56 +02:00
for i, location in ipairs(triggerLocations) do
2025-08-13 17:06:31 +02:00
TriggerClientEvent('chatMessage', source, "TRAIN", "normal", i .. ". " .. location.name .. " (" .. math.floor(location.x) .. ", " .. math.floor(location.y) .. ", " .. math.floor(location.z) .. ")")
2025-08-13 16:59:56 +02:00
end
2025-08-13 17:06:31 +02:00
end, false)
2025-08-13 16:59:56 +02:00
2025-08-13 17:06:31 +02:00
-- Event Handler
2025-08-13 16:59:56 +02:00
RegisterNetEvent('train:requestStart', function()
local source = source
2025-08-13 17:06:31 +02:00
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')
2025-08-13 16:59:56 +02:00
end)
2025-08-13 17:06:31 +02:00
print("^2[TRAIN-TRIGGER]^7 Server Script geladen! Commands: /traintest, /starttrain, /trainlocs")