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

120 lines
3.6 KiB
Lua
Raw Normal View History

2025-08-13 16:59:56 +02:00
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)