From a0a4c022cd2f2ce0ffc04f3ce61d49f3b45a5ac7 Mon Sep 17 00:00:00 2001 From: Miho931 <98314142+Miho931@users.noreply.github.com> Date: Wed, 25 Jun 2025 13:05:25 +0200 Subject: [PATCH] Update main.lua --- .../[carscripts]/mh_garage/client/main.lua | 40 ++++++++++++------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/resources/[carscripts]/mh_garage/client/main.lua b/resources/[carscripts]/mh_garage/client/main.lua index 22d54ec79..ae0475b95 100644 --- a/resources/[carscripts]/mh_garage/client/main.lua +++ b/resources/[carscripts]/mh_garage/client/main.lua @@ -5,6 +5,9 @@ npcHandle = nil isNPCSpawned = false CurrentZone = nil +CurrentActionData = {} +hasAlreadyEnteredMarker = false + Citizen.CreateThread(function() while Player == nil do Player = exports['qb-core']:GetPlayerData() @@ -72,28 +75,35 @@ end -- Hauptthread zum Überprüfen der Spieler-Position CreateThread(function() while true do - local playerPed = PlayerPedId() - local playerCoords = GetEntityCoords(playerPed) + wait(0) + local ped = PlayerPedId() + local coords = GetEntityCoords(ped) + + local isInMarker = false for k, v in pairs(Config.Zonen) do local dist = #(playerCoords - vector3(v.NPC.spawn.x, v.NPC.spawn.y, v.NPC.spawn.z)) local spawnDistance = v.NPC.distance - - if dist < spawnDistance and not isNPCSpawned then - isNPCSpawned = true - print(isNPCSpawned) + + if dist <= spawnDistance then + isInMarker = true + CurrentZone = v - SpawnGuardNPC(v.NPC) - AddTargetOptions() - elseif dist > spawnDistance and isNPCSpawned then - isNPCSpawned = false - CurrentZone = nil - exports['qb-target']:RemoveTargetEntity(npcHandle) - RemoveGuardNPC() end end - - Wait(0) -- Überprüfung jede Sekunde + + if isInMarker and not hasAlreadyEnteredMarker then + hasAlreadyEnteredMarker = true + SpawnGuardNPC(CurrentZone.NPC) + AddTargetOptions() + end + + if not isInMarker and hasAlreadyEnteredMarker then + hasAlreadyEnteredMarker = false + CurrentZone = nil + exports['qb-target']:RemoveTargetEntity(npcHandle) + RemoveGuardNPC() + end end end)