forked from Simnation/Main
Garage Angefangen
This commit is contained in:
parent
f3e9937e72
commit
a4d06e39b8
3 changed files with 104 additions and 0 deletions
67
resources/[carscripts]/mh_garage/client/main.lua
Normal file
67
resources/[carscripts]/mh_garage/client/main.lua
Normal file
|
@ -0,0 +1,67 @@
|
|||
QBCore = exports['qb-core']:GetCoreObject()
|
||||
|
||||
Player = nil
|
||||
local npcHandle = nil
|
||||
local isNPCSpawned = false
|
||||
|
||||
Citizen.CreateThread(function()
|
||||
while Player == nil do
|
||||
Player = exports['qb-core']:GetPlayerData()
|
||||
Wait(0)
|
||||
end
|
||||
end)
|
||||
|
||||
-- Funktion zum Spawnen des NPCs
|
||||
local function SpawnGuardNPC(npc)
|
||||
-- Ped Model laden
|
||||
RequestModel(npc.model)
|
||||
while not HasModelLoaded(npc.model) do
|
||||
Wait(1)
|
||||
end
|
||||
|
||||
-- NPC erstellen
|
||||
npcHandle = CreatePed(4, npc.model, npc.spawn, false, true)
|
||||
|
||||
-- NPC Eigenschaften setzen
|
||||
SetEntityAsMissionEntity(npcHandle, true, true)
|
||||
SetBlockingOfNonTemporaryEvents(npcHandle, true)
|
||||
SetPedDiesWhenInjured(npcHandle, false)
|
||||
SetPedCanPlayAmbientAnims(npcHandle, true)
|
||||
SetPedCanRagdollFromPlayerImpact(npcHandle, false)
|
||||
SetEntityInvincible(npcHandle, true)
|
||||
FreezeEntityPosition(npcHandle, true)
|
||||
|
||||
-- Optional: Animation für den NPC
|
||||
TaskStartScenarioInPlace(npcHandle, "WORLD_HUMAN_GUARD_STAND", 0, true)
|
||||
|
||||
isNPCSpawned = true
|
||||
end
|
||||
|
||||
-- Funktion zum Entfernen des NPCs
|
||||
local function RemoveGuardNPC()
|
||||
if DoesEntityExist(npcHandle) then
|
||||
DeleteEntity(npcHandle)
|
||||
isNPCSpawned = false
|
||||
end
|
||||
end
|
||||
|
||||
-- Hauptthread zum Überprüfen der Spieler-Position
|
||||
CreateThread(function()
|
||||
while true do
|
||||
local playerPed = PlayerPedId()
|
||||
local playerCoords = GetEntityCoords(playerPed)
|
||||
|
||||
for k, v in pairs(Config.Zonen) do
|
||||
local dist = #(playerCoords - v.NPC.spawn)
|
||||
local spawnDistance = v.NPC.distance
|
||||
|
||||
if dist < spawnDistance and not isNPCSpawned then
|
||||
SpawnGuardNPC()
|
||||
elseif dist > spawnDistance and isNPCSpawned then
|
||||
RemoveGuardNPC()
|
||||
end
|
||||
end
|
||||
|
||||
Wait(1000) -- Überprüfung jede Sekunde
|
||||
end
|
||||
end)
|
Loading…
Add table
Add a link
Reference in a new issue