From f1a2d3fb133f83a568330d53ff3fe30110c71292 Mon Sep 17 00:00:00 2001 From: delucecc <31872986+delucecc@users.noreply.github.com> Date: Thu, 26 Oct 2023 10:41:35 -0700 Subject: [PATCH] Added persistent/onplayerload option. --- client/client.lua | 37 +++++++++++++++++++++++++++---------- config.lua | 9 ++++++--- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/client/client.lua b/client/client.lua index 7ee2e4e..b776dfe 100644 --- a/client/client.lua +++ b/client/client.lua @@ -1,4 +1,20 @@ 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() for k, v in pairs(Config.PropLocations) do @@ -6,9 +22,9 @@ function SpawnProps() while not HasModelLoaded(v.model) do Wait(0) 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 - SetEntityHeading(prop, v.coords.w -180) + SetEntityHeading(prop, v.coords.w - 180) FreezeEntityPosition(prop, true) print("^3Prop Spawned:" .. v.coords) end @@ -22,13 +38,14 @@ function DeleteProps() end end -RegisterCommand(Config.DeleteCommand, function() - DeleteProps() -end) - -RegisterCommand(Config.SpawnCommand, function() - SpawnProps() -end) +if Config.debug then + RegisterCommand(Config.DeleteCommand, function() + DeleteProps() + end) + RegisterCommand(Config.SpawnCommand, function() + SpawnProps() + end) +end AddEventHandler('onResourceStop', function(resourceName) if (GetCurrentResourceName() ~= resourceName) then return end @@ -37,4 +54,4 @@ AddEventHandler('onResourceStop', function(resourceName) DeleteEntity(entity) end end -end) \ No newline at end of file +end) diff --git a/config.lua b/config.lua index d82b8e8..1fc5cb7 100644 --- a/config.lua +++ b/config.lua @@ -1,9 +1,12 @@ 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.DeleteCommand = 'deleteprops' Config.PropLocations = { - [1] = { coords = vector4(-1652.76, -3143.40, 13.99, 76), model = `YOURPROPNAMEHERE` }, - [2] = { coords = vector4(-1658.76, -3143.40, 13.99, 76), model = `YOURPROPNAMEHERE` }, -} \ No newline at end of file + [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 = `hei_prop_heist_box` }, +}