1
0
Fork 0
forked from Simnation/Main
This commit is contained in:
Nordi98 2025-08-13 17:06:31 +02:00
parent a375c26f9f
commit 59ff443f0e
2 changed files with 91 additions and 194 deletions

View file

@ -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")