diff --git a/resources/[standalone]/start_train/client.lua b/resources/[standalone]/start_train/client.lua index 54d3ddafb..2d1301a45 100644 --- a/resources/[standalone]/start_train/client.lua +++ b/resources/[standalone]/start_train/client.lua @@ -1,119 +1,78 @@ local QBCore = exports['qb-core']:GetCoreObject() --- Lokale Variablen -local showMarkers = false -local trainLocations = {} -local isNearLocation = false +print("^2[TRAIN-TRIGGER]^7 Client Script wird geladen...") --- Beim Script Start Locations vom Server holen -RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function() - TriggerServerEvent('train:getLocations') -end) - --- Locations vom Server empfangen -RegisterNetEvent('train:receiveLocations', function(locations) - trainLocations = locations -end) - --- Locations updaten -RegisterNetEvent('train:updateLocations', function(locations) - trainLocations = locations -end) - --- Command um Marker ein/auszuschalten -RegisterCommand('toggletrainmarkers', function() - showMarkers = not showMarkers - - if showMarkers then - QBCore.Functions.Notify('Train Marker aktiviert', 'success') +-- Test ob QBCore funktioniert +CreateThread(function() + Wait(2000) + if QBCore then + print("^2[TRAIN-TRIGGER]^7 QBCore erfolgreich geladen auf Client") else - QBCore.Functions.Notify('Train Marker deaktiviert', 'error') + print("^1[TRAIN-TRIGGER]^7 FEHLER: QBCore nicht gefunden auf Client!") + end +end) + +-- Einfache Locations (gleiche wie Server) +local trainLocations = { + {x = 215.3, y = -810.1, z = 30.7, name = "Legion Square"}, + {x = -265.0, y = -957.3, z = 31.2, name = "Pillbox Hospital"}, +} + +local showMarkers = false + +-- Test Command +RegisterCommand('togglemarkers', function() + showMarkers = not showMarkers + print("^3[TRAIN-TRIGGER]^7 Markers: " .. tostring(showMarkers)) + + if QBCore and QBCore.Functions and QBCore.Functions.Notify then + QBCore.Functions.Notify('Markers: ' .. tostring(showMarkers), 'primary') + else + TriggerEvent('chatMessage', "SYSTEM", "normal", "Markers: " .. tostring(showMarkers)) end end, false) --- Hauptschleife für Marker und Interaktion +-- Marker Loop CreateThread(function() while true do local sleep = 1000 - if showMarkers and #trainLocations > 0 then + if showMarkers then local playerCoords = GetEntityCoords(PlayerPedId()) - local nearAnyLocation = false for i, location in ipairs(trainLocations) do local distance = #(playerCoords - vector3(location.x, location.y, location.z)) - if distance < 100.0 then + if distance < 200.0 then sleep = 0 - -- Zeichne Marker - DrawMarker(1, location.x, location.y, location.z - 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 2.0, 1.0, 46, 125, 50, 100, false, true, 2, nil, nil, false) + -- Grüner Marker + DrawMarker(1, location.x, location.y, location.z - 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 3.0, 2.0, 0, 255, 0, 150, false, true, 2, nil, nil, false) - -- Zeige Text wenn nah genug - if distance < 10.0 then - nearAnyLocation = true - DrawText3D(location.x, location.y, location.z + 1.0, "[E] Train Scenario starten\n" .. location.name) + if distance < 20.0 then + -- 3D Text + local onScreen, _x, _y = World3dToScreen2d(location.x, location.y, location.z + 2.0) + if onScreen then + SetTextScale(0.4, 0.4) + SetTextFont(4) + SetTextProportional(1) + SetTextColour(255, 255, 255, 215) + SetTextEntry("STRING") + SetTextCentre(1) + AddTextComponentString("[E] " .. location.name .. "\nDistanz: " .. math.floor(distance) .. "m") + DrawText(_x, _y) + end - if IsControlJustPressed(0, 38) then -- E Taste + if IsControlJustPressed(0, 38) then -- E + print("^3[TRAIN-TRIGGER]^7 E gedrückt bei " .. location.name) TriggerServerEvent('train:requestStart') end end end end - - isNearLocation = nearAnyLocation end Wait(sleep) end end) --- Hilfe Text anzeigen -CreateThread(function() - while true do - Wait(0) - - if isNearLocation then - DisplayHelpText("Drücke ~INPUT_CONTEXT~ um das Train Scenario zu starten") - end - end -end) - --- 3D Text Funktion -function DrawText3D(x, y, z, text) - local onScreen, _x, _y = World3dToScreen2d(x, y, z) - local px, py, pz = table.unpack(GetGameplayCamCoords()) - local dist = GetDistanceBetweenCoords(px, py, pz, x, y, z, 1) - - local scale = (1 / dist) * 2 - local fov = (1 / GetGameplayCamFov()) * 100 - scale = scale * fov - - if onScreen then - SetTextScale(0.0 * scale, 0.55 * scale) - SetTextFont(0) - SetTextProportional(1) - SetTextColour(255, 255, 255, 255) - SetTextDropshadow(0, 0, 0, 0, 255) - SetTextEdge(2, 0, 0, 0, 150) - SetTextDropShadow() - SetTextOutline() - SetTextEntry("STRING") - SetTextCentre(1) - AddTextComponentString(text) - DrawText(_x, _y) - end -end - -function DisplayHelpText(text) - SetTextComponentFormat("STRING") - AddTextComponentString(text) - DisplayHelpTextFromStringLabel(0, 0, 1, -1) -end - --- Beim Resource Start Locations holen -AddEventHandler('onResourceStart', function(resourceName) - if GetCurrentResourceName() == resourceName then - Wait(1000) -- Kurz warten damit QBCore geladen ist - TriggerServerEvent('train:getLocations') - end -end) +print("^2[TRAIN-TRIGGER]^7 Client Script geladen! Commands: /togglemarkers") diff --git a/resources/[standalone]/start_train/server.lua b/resources/[standalone]/start_train/server.lua index c350b24e6..b4a3c21e2 100644 --- a/resources/[standalone]/start_train/server.lua +++ b/resources/[standalone]/start_train/server.lua @@ -1,139 +1,77 @@ local QBCore = exports['qb-core']:GetCoreObject() --- Definiere die Orte wo das Event gestartet werden kann +-- Debug Print +print("^2[TRAIN-TRIGGER]^7 Server Script wird geladen...") + +-- Einfache Locations local triggerLocations = { - {x = -1037.8, y = -2737.9, z = 20.2, name = "Los Santos Airport"}, {x = 215.3, y = -810.1, z = 30.7, name = "Legion Square"}, {x = -265.0, y = -957.3, z = 31.2, name = "Pillbox Hospital"}, - {x = 425.1, y = -979.5, z = 30.7, name = "LSPD"}, - {x = -1100.0, y = 2711.0, z = 19.0, name = "Sandy Shores Airfield"}, - {x = 1747.0, y = 3273.0, z = 41.0, name = "Sandy Shores"}, - -- Füge hier weitere Orte hinzu } --- Command um das Event an der nächsten Location zu triggern -QBCore.Commands.Add('starttrain', 'Starte Train Scenario', {}, false, function(source, args) +-- 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 not Player then return end + 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) - -- Finde die nächste Location + print("^3[TRAIN-TRIGGER]^7 Spieler Position: " .. playerCoords.x .. ", " .. playerCoords.y .. ", " .. playerCoords.z) + + -- Finde nächste Location + local closestDistance = 999999 local closestLocation = nil - local closestDistance = math.huge 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 - -- Prüfe ob der Spieler nah genug an einer Location ist (50 Meter Radius) - if closestDistance <= 50.0 then + 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 scenario gestartet bei: ' .. closestLocation.name, 'success', 5000) + TriggerClientEvent('QBCore:Notify', source, 'Train gestartet bei: ' .. closestLocation.name, 'success') else - TriggerClientEvent('QBCore:Notify', source, 'Du bist zu weit von einer Train-Location entfernt!', 'error', 5000) + 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) +end, false) --- Command um eine neue Location hinzuzufügen (nur für Admins) -QBCore.Commands.Add('addtrainloc', 'Füge neue Train Location hinzu', {{name = 'name', help = 'Name der Location (optional)'}}, false, function(source, args) - local Player = QBCore.Functions.GetPlayer(source) - if not Player then return end - - -- Prüfe Admin Berechtigung - if not QBCore.Functions.HasPermission(source, 'admin') then - TriggerClientEvent('QBCore:Notify', source, 'Du hast keine Berechtigung für diesen Command!', 'error') - return - end - - local playerPed = GetPlayerPed(source) - local playerCoords = GetEntityCoords(playerPed) - - local locationName = table.concat(args, " ") - if locationName == "" then - locationName = "Custom Location " .. (#triggerLocations + 1) - end - - table.insert(triggerLocations, { - x = playerCoords.x, - y = playerCoords.y, - z = playerCoords.z, - name = locationName - }) - - TriggerClientEvent('QBCore:Notify', source, 'Neue Train-Location hinzugefügt: ' .. locationName, 'success') - TriggerClientEvent('train:updateLocations', -1, triggerLocations) -- Update für alle Clients - - print("^2[TRAIN-TRIGGER]^7 Neue Location hinzugefügt: " .. locationName .. " bei " .. math.floor(playerCoords.x) .. ", " .. math.floor(playerCoords.y) .. ", " .. math.floor(playerCoords.z)) -end, 'admin') - --- Command um alle Locations anzuzeigen -QBCore.Commands.Add('trainlocs', 'Zeige alle Train Locations', {}, false, function(source, args) - local Player = QBCore.Functions.GetPlayer(source) - if not Player then return end - - TriggerClientEvent('QBCore:Notify', source, 'Schaue in die F8 Konsole für alle Locations', 'primary') - - TriggerClientEvent('chat:addMessage', source, { - color = {255, 215, 0}, - multiline = true, - args = {"^3[TRAIN]", "^7=== Train Locations ==="} - }) +-- Locations anzeigen +RegisterCommand('trainlocs', function(source, args, rawCommand) + TriggerClientEvent('chatMessage', source, "TRAIN-LOCATIONS", "info", "=== Train Locations ===") for i, location in ipairs(triggerLocations) do - TriggerClientEvent('chat:addMessage', source, { - color = {255, 255, 255}, - multiline = true, - args = {"^3[TRAIN]", "^7" .. i .. ". ^2" .. location.name .. " ^7(" .. math.floor(location.x) .. ", " .. math.floor(location.y) .. ", " .. math.floor(location.z) .. ")"} - }) + TriggerClientEvent('chatMessage', source, "TRAIN", "normal", i .. ". " .. location.name .. " (" .. math.floor(location.x) .. ", " .. math.floor(location.y) .. ", " .. math.floor(location.z) .. ")") end -end) +end, false) --- Server Event für E-Taste Trigger +-- Event Handler RegisterNetEvent('train:requestStart', function() local source = source - local Player = QBCore.Functions.GetPlayer(source) - if not Player then return end - - local playerPed = GetPlayerPed(source) - local playerCoords = GetEntityCoords(playerPed) - - -- Finde die nächste Location - local closestLocation = nil - local closestDistance = math.huge - - for i, location in ipairs(triggerLocations) do - local distance = #(playerCoords - vector3(location.x, location.y, location.z)) - if distance < closestDistance then - closestDistance = distance - closestLocation = location - end - end - - -- Prüfe ob der Spieler nah genug ist (10 Meter für E-Taste) - if closestDistance <= 10.0 then - TriggerClientEvent('train:startscenario', source, 'Welcome') - TriggerClientEvent('QBCore:Notify', source, 'Train scenario gestartet!', 'success') - end + 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) --- Event um Locations an Client zu senden -RegisterNetEvent('train:getLocations', function() - local source = source - TriggerClientEvent('train:receiveLocations', source, triggerLocations) -end) - --- Beim Server Start alle Locations loggen -AddEventHandler('onResourceStart', function(resourceName) - if GetCurrentResourceName() == resourceName then - print("^2[TRAIN-TRIGGER]^7 Resource gestartet mit " .. #triggerLocations .. " Locations") - for i, location in ipairs(triggerLocations) do - print("^3[TRAIN-TRIGGER]^7 " .. i .. ". " .. location.name) - end - end -end) +print("^2[TRAIN-TRIGGER]^7 Server Script geladen! Commands: /traintest, /starttrain, /trainlocs")