Added persistent/onplayerload option.

This commit is contained in:
delucecc 2023-10-26 10:41:35 -07:00
parent 7108f3fed8
commit f1a2d3fb13
2 changed files with 33 additions and 13 deletions

View File

@ -1,4 +1,20 @@
local entity_ids = {} local entity_ids = {}
if Config.Persistent then
if Config.Framework == 'qb' then
QBCore = exports['qb-core']:GetCoreObject()
AddEventHandler('QBCore:Client:OnPlayerLoaded', function()
Wait(1500)
SpawnProps()
end)
elseif Config.Framework == 'esx' then
local ESX = exports["es_extended"]:getSharedObject()
RegisterNetEvent('esx:playerLoaded')
AddEventHandler('esx:playerLoaded', function()
Wait(1500)
SpawnProps()
end)
end
end
function SpawnProps() function SpawnProps()
for k, v in pairs(Config.PropLocations) do for k, v in pairs(Config.PropLocations) do
@ -6,9 +22,9 @@ function SpawnProps()
while not HasModelLoaded(v.model) do while not HasModelLoaded(v.model) do
Wait(0) Wait(0)
end end
local prop = CreateObject(v.model, v.coords.x, v.coords.y, v.coords.z - 1, true, true, false) local prop = CreateObject(v.model, v.coords.x, v.coords.y, v.coords.z - 1, false, true, false)
entity_ids[#entity_ids + 1] = prop entity_ids[#entity_ids + 1] = prop
SetEntityHeading(prop, v.coords.w -180) SetEntityHeading(prop, v.coords.w - 180)
FreezeEntityPosition(prop, true) FreezeEntityPosition(prop, true)
print("^3Prop Spawned:" .. v.coords) print("^3Prop Spawned:" .. v.coords)
end end
@ -22,13 +38,14 @@ function DeleteProps()
end end
end end
RegisterCommand(Config.DeleteCommand, function() if Config.debug then
DeleteProps() RegisterCommand(Config.DeleteCommand, function()
end) DeleteProps()
end)
RegisterCommand(Config.SpawnCommand, function() RegisterCommand(Config.SpawnCommand, function()
SpawnProps() SpawnProps()
end) end)
end
AddEventHandler('onResourceStop', function(resourceName) AddEventHandler('onResourceStop', function(resourceName)
if (GetCurrentResourceName() ~= resourceName) then return end if (GetCurrentResourceName() ~= resourceName) then return end
@ -37,4 +54,4 @@ AddEventHandler('onResourceStop', function(resourceName)
DeleteEntity(entity) DeleteEntity(entity)
end end
end end
end) end)

View File

@ -1,9 +1,12 @@
Config = {} Config = {}
Config.Persistent = true --Spawn props on player load.
Config.FrameWork = 'qb' --qb or esx
Config.debug = false --Enables prints and commands below.
Config.SpawnCommand = 'spawnprops' Config.SpawnCommand = 'spawnprops'
Config.DeleteCommand = 'deleteprops' Config.DeleteCommand = 'deleteprops'
Config.PropLocations = { Config.PropLocations = {
[1] = { coords = vector4(-1652.76, -3143.40, 13.99, 76), model = `YOURPROPNAMEHERE` }, [1] = { coords = vector4(-1652.76, -3143.40, 13.99, 76), model = `bkr_prop_clubhouse_jukebox_02a` },
[2] = { coords = vector4(-1658.76, -3143.40, 13.99, 76), model = `YOURPROPNAMEHERE` }, [2] = { coords = vector4(-1658.76, -3143.40, 13.99, 76), model = `hei_prop_heist_box` },
} }