forked from Simnation/Main
142 lines
4 KiB
Lua
142 lines
4 KiB
Lua
local QBCore = exports['qb-core']:GetCoreObject()
|
|
local PlayerData = {}
|
|
local isInTrainingZone = false
|
|
local currentZone = nil
|
|
local isInScenario = false
|
|
|
|
-- Events
|
|
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
|
|
PlayerData = QBCore.Functions.GetPlayerData()
|
|
CreateTrainingZones()
|
|
end)
|
|
|
|
RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
|
|
PlayerData = {}
|
|
end)
|
|
|
|
-- Erstelle Training Zones
|
|
function CreateTrainingZones()
|
|
for k, v in pairs(Config.TrainingZones) do
|
|
local blip = AddBlipForCoord(v.coords.x, v.coords.y, v.coords.z)
|
|
SetBlipSprite(blip, v.blip.sprite)
|
|
SetBlipDisplay(blip, 4)
|
|
SetBlipScale(blip, v.blip.scale)
|
|
SetBlipColour(blip, v.blip.color)
|
|
SetBlipAsShortRange(blip, true)
|
|
BeginTextCommandSetBlipName("STRING")
|
|
AddTextComponentSubstringPlayerName(v.blip.label)
|
|
EndTextCommandSetBlipName(blip)
|
|
end
|
|
end
|
|
|
|
-- Main Thread für Zone Detection
|
|
CreateThread(function()
|
|
while true do
|
|
local sleep = 1000
|
|
local ped = PlayerPedId()
|
|
local coords = GetEntityCoords(ped)
|
|
|
|
for k, v in pairs(Config.TrainingZones) do
|
|
local distance = #(coords - vector3(v.coords.x, v.coords.y, v.coords.z))
|
|
|
|
if distance < v.radius then
|
|
sleep = 0
|
|
if not isInTrainingZone then
|
|
isInTrainingZone = true
|
|
currentZone = k
|
|
ShowHelpText()
|
|
end
|
|
|
|
if IsControlJustReleased(0, 38) then -- E Key
|
|
StartTrainingScenario(v.scenario)
|
|
end
|
|
elseif isInTrainingZone and currentZone == k then
|
|
isInTrainingZone = false
|
|
currentZone = nil
|
|
end
|
|
end
|
|
|
|
Wait(sleep)
|
|
end
|
|
end)
|
|
|
|
-- Zeige Help Text
|
|
function ShowHelpText()
|
|
CreateThread(function()
|
|
while isInTrainingZone do
|
|
local zoneData = Config.TrainingZones[currentZone]
|
|
QBCore.Functions.DrawText3D(zoneData.coords.x, zoneData.coords.y, zoneData.coords.z + 1.0,
|
|
'[E] - ' .. zoneData.label)
|
|
Wait(0)
|
|
end
|
|
end)
|
|
end
|
|
|
|
-- Starte Training Scenario
|
|
function StartTrainingScenario(scenario)
|
|
if isInScenario then
|
|
QBCore.Functions.Notify('Du bist bereits in einem Szenario!', 'error')
|
|
return
|
|
end
|
|
|
|
local ped = PlayerPedId()
|
|
|
|
-- Prüfe ob Szenario existiert
|
|
if not DoesScenarioExist(scenario) then
|
|
QBCore.Functions.Notify('Szenario existiert nicht!', 'error')
|
|
return
|
|
end
|
|
|
|
isInScenario = true
|
|
TaskStartScenarioInPlace(ped, scenario, 0, true)
|
|
|
|
QBCore.Functions.Notify('Szenario gestartet! Drücke [X] zum Beenden', 'success')
|
|
|
|
-- Thread zum Beenden des Szenarios
|
|
CreateThread(function()
|
|
while isInScenario do
|
|
if IsControlJustReleased(0, 73) then -- X Key
|
|
StopTrainingScenario()
|
|
break
|
|
end
|
|
Wait(0)
|
|
end
|
|
end)
|
|
end
|
|
|
|
-- Stoppe Training Scenario
|
|
function StopTrainingScenario()
|
|
if not isInScenario then return end
|
|
|
|
local ped = PlayerPedId()
|
|
ClearPedTasks(ped)
|
|
isInScenario = false
|
|
|
|
QBCore.Functions.Notify('Szenario beendet!', 'primary')
|
|
end
|
|
|
|
-- Event Handler für externe Triggers
|
|
RegisterNetEvent('train:startscenario', function(scenario)
|
|
if not scenario then
|
|
QBCore.Functions.Notify('Kein Szenario angegeben!', 'error')
|
|
return
|
|
end
|
|
|
|
StartTrainingScenario(scenario)
|
|
end)
|
|
|
|
-- Utility Functions
|
|
QBCore.Functions.DrawText3D = function(x, y, z, text)
|
|
SetTextScale(0.35, 0.35)
|
|
SetTextFont(4)
|
|
SetTextProportional(1)
|
|
SetTextColour(255, 255, 255, 215)
|
|
SetTextEntry("STRING")
|
|
SetTextCentre(true)
|
|
AddTextComponentString(text)
|
|
SetDrawOrigin(x, y, z, 0)
|
|
DrawText(0.0, 0.0)
|
|
local factor = (string.len(text)) / 370
|
|
DrawRect(0.0, 0.0+0.0125, 0.017+ factor, 0.03, 0, 0, 0, 75)
|
|
ClearDrawOrigin()
|
|
end
|