From a375c26f9fc42203216e4410444e8dd310a5f031 Mon Sep 17 00:00:00 2001 From: Nordi98 Date: Wed, 13 Aug 2025 16:59:56 +0200 Subject: [PATCH] ed --- resources/[standalone]/start_train/client.lua | 119 +++++++++++++++ .../[standalone]/start_train/fxmanifest.lua | 20 +++ resources/[standalone]/start_train/server.lua | 139 ++++++++++++++++++ 3 files changed, 278 insertions(+) create mode 100644 resources/[standalone]/start_train/client.lua create mode 100644 resources/[standalone]/start_train/fxmanifest.lua create mode 100644 resources/[standalone]/start_train/server.lua diff --git a/resources/[standalone]/start_train/client.lua b/resources/[standalone]/start_train/client.lua new file mode 100644 index 000000000..54d3ddafb --- /dev/null +++ b/resources/[standalone]/start_train/client.lua @@ -0,0 +1,119 @@ +local QBCore = exports['qb-core']:GetCoreObject() + +-- Lokale Variablen +local showMarkers = false +local trainLocations = {} +local isNearLocation = false + +-- 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') + else + QBCore.Functions.Notify('Train Marker deaktiviert', 'error') + end +end, false) + +-- Hauptschleife für Marker und Interaktion +CreateThread(function() + while true do + local sleep = 1000 + + if showMarkers and #trainLocations > 0 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 + 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) + + -- 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 IsControlJustPressed(0, 38) then -- E Taste + 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) diff --git a/resources/[standalone]/start_train/fxmanifest.lua b/resources/[standalone]/start_train/fxmanifest.lua new file mode 100644 index 000000000..cd37876af --- /dev/null +++ b/resources/[standalone]/start_train/fxmanifest.lua @@ -0,0 +1,20 @@ +fx_version 'cerulean' +game 'gta5' + +author 'Dein Name' +description 'QBCore Train Scenario Trigger Script' +version '1.0.0' + +server_scripts { + 'server.lua' +} + +client_scripts { + 'client.lua' +} + +dependencies { + 'qb-core' +} + +lua54 'yes' diff --git a/resources/[standalone]/start_train/server.lua b/resources/[standalone]/start_train/server.lua new file mode 100644 index 000000000..c350b24e6 --- /dev/null +++ b/resources/[standalone]/start_train/server.lua @@ -0,0 +1,139 @@ +local QBCore = exports['qb-core']:GetCoreObject() + +-- Definiere die Orte wo das Event gestartet werden kann +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) + 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 an einer Location ist (50 Meter Radius) + if closestDistance <= 50.0 then + TriggerClientEvent('train:startscenario', source, 'Welcome') + TriggerClientEvent('QBCore:Notify', source, 'Train scenario gestartet bei: ' .. closestLocation.name, 'success', 5000) + else + TriggerClientEvent('QBCore:Notify', source, 'Du bist zu weit von einer Train-Location entfernt!', 'error', 5000) + end +end) + +-- 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 ==="} + }) + + 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) .. ")"} + }) + end +end) + +-- Server Event für E-Taste Trigger +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 +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)