ngd-propspawner/client/client.lua

58 lines
1.6 KiB
Lua
Raw Permalink Normal View History

2023-06-03 21:31:53 -05:00
local entity_ids = {}
2023-10-26 12:41:35 -05:00
if Config.Persistent then
2023-11-13 00:22:40 -06:00
if Config.FrameWork == 'qb' then
2023-10-26 12:41:35 -05:00
QBCore = exports['qb-core']:GetCoreObject()
AddEventHandler('QBCore:Client:OnPlayerLoaded', function()
Wait(1500)
SpawnProps()
end)
2023-11-13 00:22:40 -06:00
elseif Config.FrameWork == 'esx' then
2023-10-26 12:41:35 -05:00
local ESX = exports["es_extended"]:getSharedObject()
RegisterNetEvent('esx:playerLoaded')
AddEventHandler('esx:playerLoaded', function()
Wait(1500)
SpawnProps()
end)
end
end
2023-06-03 21:31:53 -05:00
function SpawnProps()
for k, v in pairs(Config.PropLocations) do
RequestModel(v.model)
while not HasModelLoaded(v.model) do
Wait(0)
end
2023-10-26 12:41:35 -05:00
local prop = CreateObject(v.model, v.coords.x, v.coords.y, v.coords.z - 1, false, true, false)
2023-06-03 21:31:53 -05:00
entity_ids[#entity_ids + 1] = prop
2023-10-26 12:41:35 -05:00
SetEntityHeading(prop, v.coords.w - 180)
2023-06-03 21:31:53 -05:00
FreezeEntityPosition(prop, true)
print("^3Prop Spawned:" .. v.coords)
end
end
function DeleteProps()
for _, entity in pairs(entity_ids) do
if DoesEntityExist(entity) then
DeleteEntity(entity)
end
end
end
2023-10-26 12:41:35 -05:00
if Config.debug then
RegisterCommand(Config.DeleteCommand, function()
DeleteProps()
end)
RegisterCommand(Config.SpawnCommand, function()
SpawnProps()
end)
end
2023-06-03 21:31:53 -05:00
AddEventHandler('onResourceStop', function(resourceName)
if (GetCurrentResourceName() ~= resourceName) then return end
for _, entity in pairs(entity_ids) do
if DoesEntityExist(entity) then
DeleteEntity(entity)
end
end
2023-10-26 12:41:35 -05:00
end)