forked from Simnation/Main
Update client.lua
This commit is contained in:
parent
ff10efa7d1
commit
aca2e75b3b
1 changed files with 108 additions and 0 deletions
|
@ -822,3 +822,111 @@ CreateThread(function()
|
|||
end
|
||||
end)
|
||||
|
||||
-- Function to spawn NPCs for all fields
|
||||
function spawnFieldNPCs()
|
||||
for fieldId, fieldData in pairs(Config.gameFields) do
|
||||
if fieldData.lobby and fieldData.lobby.npc then
|
||||
local npcData = fieldData.lobby.npc
|
||||
local model = GetHashKey(npcData.model)
|
||||
|
||||
-- Request the model
|
||||
RequestModel(model)
|
||||
while not HasModelLoaded(model) do
|
||||
Wait(10)
|
||||
end
|
||||
|
||||
-- Create the NPC
|
||||
local npc = CreatePed(4, model, npcData.coords.x, npcData.coords.y, npcData.coords.z, npcData.coords.w, false, true)
|
||||
SetEntityAsMissionEntity(npc, true, true)
|
||||
SetBlockingOfNonTemporaryEvents(npc, true)
|
||||
FreezeEntityPosition(npc, true)
|
||||
SetEntityInvincible(npc, true)
|
||||
|
||||
-- Add to spawned NPCs table
|
||||
table.insert(spawnedNPCs, npc)
|
||||
|
||||
-- Add target interaction
|
||||
exports['qb-target']:AddTargetEntity(npc, {
|
||||
options = {
|
||||
{
|
||||
type = "client",
|
||||
event = "tdm:openMenu",
|
||||
icon = "fas fa-gamepad",
|
||||
label = "TeamDeathmatch Menu",
|
||||
fieldId = fieldId
|
||||
}
|
||||
},
|
||||
distance = 2.0
|
||||
})
|
||||
|
||||
debugPrint("Spawned NPC for field: " .. fieldId)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Register event handler for NPC interaction
|
||||
RegisterNetEvent('tdm:openMenu', function(data)
|
||||
if data.fieldId then
|
||||
openMainMenu(data.fieldId)
|
||||
end
|
||||
end)
|
||||
|
||||
-- Spawn NPCs when resource starts
|
||||
CreateThread(function()
|
||||
Wait(1000) -- Wait for everything to load
|
||||
spawnFieldNPCs()
|
||||
end)
|
||||
|
||||
-- Function to create blips for all TDM lobbies
|
||||
function createTDMBlips()
|
||||
for fieldId, fieldData in pairs(Config.gameFields) do
|
||||
if fieldData.lobby and fieldData.lobby.pos then
|
||||
local blip = AddBlipForCoord(fieldData.lobby.pos.x, fieldData.lobby.pos.y, fieldData.lobby.pos.z)
|
||||
SetBlipSprite(blip, 156) -- You can change this to any appropriate sprite
|
||||
SetBlipDisplay(blip, 4)
|
||||
SetBlipScale(blip, 0.8)
|
||||
SetBlipColour(blip, 3)
|
||||
SetBlipAsShortRange(blip, true)
|
||||
BeginTextCommandSetBlipName("STRING")
|
||||
AddTextComponentString("TDM: " .. fieldData.name)
|
||||
EndTextCommandSetBlipName(blip)
|
||||
|
||||
table.insert(tdmBlips, blip)
|
||||
debugPrint("Created blip for TDM field: " .. fieldId)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Call this function when the resource starts
|
||||
CreateThread(function()
|
||||
Wait(2000) -- Wait for everything to load
|
||||
createTDMBlips()
|
||||
end)
|
||||
|
||||
-- Cleanup function
|
||||
function cleanupResources()
|
||||
-- Remove NPCs
|
||||
for _, npc in ipairs(spawnedNPCs) do
|
||||
if DoesEntityExist(npc) then
|
||||
DeleteEntity(npc)
|
||||
end
|
||||
end
|
||||
spawnedNPCs = {}
|
||||
|
||||
-- Remove blips
|
||||
for _, blip in ipairs(tdmBlips) do
|
||||
if DoesBlipExist(blip) then
|
||||
RemoveBlip(blip)
|
||||
end
|
||||
end
|
||||
tdmBlips = {}
|
||||
|
||||
debugPrint("Cleaned up all NPCs and blips")
|
||||
end
|
||||
|
||||
-- Register cleanup when resource stops
|
||||
AddEventHandler('onResourceStop', function(resourceName)
|
||||
if GetCurrentResourceName() == resourceName then
|
||||
cleanupResources()
|
||||
end
|
||||
end)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue