forked from Simnation/Main
ed
This commit is contained in:
parent
a375c26f9f
commit
59ff443f0e
2 changed files with 91 additions and 194 deletions
|
@ -1,119 +1,78 @@
|
||||||
local QBCore = exports['qb-core']:GetCoreObject()
|
local QBCore = exports['qb-core']:GetCoreObject()
|
||||||
|
|
||||||
-- Lokale Variablen
|
print("^2[TRAIN-TRIGGER]^7 Client Script wird geladen...")
|
||||||
local showMarkers = false
|
|
||||||
local trainLocations = {}
|
|
||||||
local isNearLocation = false
|
|
||||||
|
|
||||||
-- Beim Script Start Locations vom Server holen
|
-- Test ob QBCore funktioniert
|
||||||
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
|
CreateThread(function()
|
||||||
TriggerServerEvent('train:getLocations')
|
Wait(2000)
|
||||||
end)
|
if QBCore then
|
||||||
|
print("^2[TRAIN-TRIGGER]^7 QBCore erfolgreich geladen auf Client")
|
||||||
-- 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
|
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
|
||||||
end, false)
|
end, false)
|
||||||
|
|
||||||
-- Hauptschleife für Marker und Interaktion
|
-- Marker Loop
|
||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
while true do
|
while true do
|
||||||
local sleep = 1000
|
local sleep = 1000
|
||||||
|
|
||||||
if showMarkers and #trainLocations > 0 then
|
if showMarkers then
|
||||||
local playerCoords = GetEntityCoords(PlayerPedId())
|
local playerCoords = GetEntityCoords(PlayerPedId())
|
||||||
local nearAnyLocation = false
|
|
||||||
|
|
||||||
for i, location in ipairs(trainLocations) do
|
for i, location in ipairs(trainLocations) do
|
||||||
local distance = #(playerCoords - vector3(location.x, location.y, location.z))
|
local distance = #(playerCoords - vector3(location.x, location.y, location.z))
|
||||||
|
|
||||||
if distance < 100.0 then
|
if distance < 200.0 then
|
||||||
sleep = 0
|
sleep = 0
|
||||||
-- Zeichne Marker
|
-- 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, 2.0, 2.0, 1.0, 46, 125, 50, 100, false, true, 2, nil, nil, false)
|
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 < 20.0 then
|
||||||
if distance < 10.0 then
|
-- 3D Text
|
||||||
nearAnyLocation = true
|
local onScreen, _x, _y = World3dToScreen2d(location.x, location.y, location.z + 2.0)
|
||||||
DrawText3D(location.x, location.y, location.z + 1.0, "[E] Train Scenario starten\n" .. location.name)
|
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')
|
TriggerServerEvent('train:requestStart')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
isNearLocation = nearAnyLocation
|
|
||||||
end
|
end
|
||||||
|
|
||||||
Wait(sleep)
|
Wait(sleep)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Hilfe Text anzeigen
|
print("^2[TRAIN-TRIGGER]^7 Client Script geladen! Commands: /togglemarkers")
|
||||||
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)
|
|
||||||
|
|
|
@ -1,139 +1,77 @@
|
||||||
local QBCore = exports['qb-core']:GetCoreObject()
|
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 = {
|
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 = 215.3, y = -810.1, z = 30.7, name = "Legion Square"},
|
||||||
{x = -265.0, y = -957.3, z = 31.2, name = "Pillbox Hospital"},
|
{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
|
-- Einfacher Test Command
|
||||||
QBCore.Commands.Add('starttrain', 'Starte Train Scenario', {}, false, function(source, args)
|
RegisterCommand('traintest', function(source, args, rawCommand)
|
||||||
|
print("^3[TRAIN-TRIGGER]^7 Command traintest ausgeführt von Spieler: " .. source)
|
||||||
|
|
||||||
local Player = QBCore.Functions.GetPlayer(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 playerPed = GetPlayerPed(source)
|
||||||
local playerCoords = GetEntityCoords(playerPed)
|
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 closestLocation = nil
|
||||||
local closestDistance = math.huge
|
|
||||||
|
|
||||||
for i, location in ipairs(triggerLocations) do
|
for i, location in ipairs(triggerLocations) do
|
||||||
local distance = #(playerCoords - vector3(location.x, location.y, location.z))
|
local distance = #(playerCoords - vector3(location.x, location.y, location.z))
|
||||||
|
print("^3[TRAIN-TRIGGER]^7 Distanz zu " .. location.name .. ": " .. distance)
|
||||||
|
|
||||||
if distance < closestDistance then
|
if distance < closestDistance then
|
||||||
closestDistance = distance
|
closestDistance = distance
|
||||||
closestLocation = location
|
closestLocation = location
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Prüfe ob der Spieler nah genug an einer Location ist (50 Meter Radius)
|
if closestDistance <= 100.0 then -- Größerer Radius zum Testen
|
||||||
if closestDistance <= 50.0 then
|
print("^2[TRAIN-TRIGGER]^7 Triggering Event für Spieler: " .. source)
|
||||||
TriggerClientEvent('train:startscenario', source, 'Welcome')
|
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
|
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)
|
end, false)
|
||||||
|
|
||||||
-- Command um eine neue Location hinzuzufügen (nur für Admins)
|
-- Locations anzeigen
|
||||||
QBCore.Commands.Add('addtrainloc', 'Füge neue Train Location hinzu', {{name = 'name', help = 'Name der Location (optional)'}}, false, function(source, args)
|
RegisterCommand('trainlocs', function(source, args, rawCommand)
|
||||||
local Player = QBCore.Functions.GetPlayer(source)
|
TriggerClientEvent('chatMessage', source, "TRAIN-LOCATIONS", "info", "=== Train Locations ===")
|
||||||
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
|
for i, location in ipairs(triggerLocations) do
|
||||||
TriggerClientEvent('chat:addMessage', source, {
|
TriggerClientEvent('chatMessage', source, "TRAIN", "normal", i .. ". " .. location.name .. " (" .. math.floor(location.x) .. ", " .. math.floor(location.y) .. ", " .. math.floor(location.z) .. ")")
|
||||||
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
|
||||||
end)
|
end, false)
|
||||||
|
|
||||||
-- Server Event für E-Taste Trigger
|
-- Event Handler
|
||||||
RegisterNetEvent('train:requestStart', function()
|
RegisterNetEvent('train:requestStart', function()
|
||||||
local source = source
|
local source = source
|
||||||
local Player = QBCore.Functions.GetPlayer(source)
|
print("^3[TRAIN-TRIGGER]^7 train:requestStart Event von Spieler: " .. 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('train:startscenario', source, 'Welcome')
|
||||||
TriggerClientEvent('QBCore:Notify', source, 'Train scenario gestartet!', 'success')
|
TriggerClientEvent('QBCore:Notify', source, 'Train via Event gestartet!', 'success')
|
||||||
end
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Event um Locations an Client zu senden
|
print("^2[TRAIN-TRIGGER]^7 Server Script geladen! Commands: /traintest, /starttrain, /trainlocs")
|
||||||
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)
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue