From d169d5be70674d33379cb4397e61b1586c0708f8 Mon Sep 17 00:00:00 2001 From: Solareon <769465+solareon@users.noreply.github.com> Date: Wed, 10 Jul 2024 21:43:33 +0200 Subject: [PATCH 1/2] refactor(client/main): fix structure and move config out of client lua --- README.md | 4 ++ main.lua => client/main.lua | 94 ++++++++++++++++++------------------- config/client.lua | 7 +++ fxmanifest.lua | 9 +++- 4 files changed, 64 insertions(+), 50 deletions(-) rename main.lua => client/main.lua (87%) create mode 100644 config/client.lua diff --git a/README.md b/README.md index b349908..af13380 100644 --- a/README.md +++ b/README.md @@ -13,3 +13,7 @@ Population management for qbox. ``` ensure qbx_density ``` + +## Configuration +- Adjust variables in `config/client.lua` for permanent changes +- Utilize `exports.qbx_density:SetDensity(type, value)` to adjust at runtime \ No newline at end of file diff --git a/main.lua b/client/main.lua similarity index 87% rename from main.lua rename to client/main.lua index 36b2f55..f6e6dd0 100644 --- a/main.lua +++ b/client/main.lua @@ -1,50 +1,46 @@ -SetRelationshipBetweenGroups(1, `AMBIENT_GANG_HILLBILLY`, `PLAYER`) -SetRelationshipBetweenGroups(1, `AMBIENT_GANG_BALLAS`, `PLAYER`) -SetRelationshipBetweenGroups(1, `AMBIENT_GANG_MEXICAN`, `PLAYER`) -SetRelationshipBetweenGroups(1, `AMBIENT_GANG_FAMILY`, `PLAYER`) -SetRelationshipBetweenGroups(1, `AMBIENT_GANG_MARABUNTE`, `PLAYER`) -SetRelationshipBetweenGroups(1, `AMBIENT_GANG_SALVA`, `PLAYER`) -SetRelationshipBetweenGroups(1, `AMBIENT_GANG_LOST`, `PLAYER`) -SetRelationshipBetweenGroups(1, `GANG_1`, `PLAYER`) -SetRelationshipBetweenGroups(1, `GANG_2`, `PLAYER`) -SetRelationshipBetweenGroups(1, `GANG_9`, `PLAYER`) -SetRelationshipBetweenGroups(1, `GANG_10`, `PLAYER`) -SetRelationshipBetweenGroups(1, `FIREMAN`, `PLAYER`) -SetRelationshipBetweenGroups(1, `MEDIC`, `PLAYER`) -SetRelationshipBetweenGroups(1, `COP`, `PLAYER`) -SetRelationshipBetweenGroups(1, `PRISONER`, `PLAYER`) - -local density = { - parked = 0.8, - vehicle = 0.8, - multiplier = 0.8, - peds = 0.8, - scenario = 0.8, -} - -local function decorSet(type, value) - if type == 'parked' then - density.parked = value - elseif type == 'vehicle' then - density.vehicle = value - elseif type == 'multiplier' then - density.multiplier = value - elseif type == 'peds' then - density.peds = value - elseif type == 'scenario' then - density.scenario = value - end -end - -exports('DecorSet', decorSet) - -CreateThread(function() - while true do - SetParkedVehicleDensityMultiplierThisFrame(density.parked) - SetVehicleDensityMultiplierThisFrame(density.vehicle) - SetRandomVehicleDensityMultiplierThisFrame(density.multiplier) - SetPedDensityMultiplierThisFrame(density.peds) - SetScenarioPedDensityMultiplierThisFrame(density.scenario, density.scenario) -- Walking NPC Density - Wait(0) - end +SetRelationshipBetweenGroups(1, `AMBIENT_GANG_HILLBILLY`, `PLAYER`) +SetRelationshipBetweenGroups(1, `AMBIENT_GANG_BALLAS`, `PLAYER`) +SetRelationshipBetweenGroups(1, `AMBIENT_GANG_MEXICAN`, `PLAYER`) +SetRelationshipBetweenGroups(1, `AMBIENT_GANG_FAMILY`, `PLAYER`) +SetRelationshipBetweenGroups(1, `AMBIENT_GANG_MARABUNTE`, `PLAYER`) +SetRelationshipBetweenGroups(1, `AMBIENT_GANG_SALVA`, `PLAYER`) +SetRelationshipBetweenGroups(1, `AMBIENT_GANG_LOST`, `PLAYER`) +SetRelationshipBetweenGroups(1, `GANG_1`, `PLAYER`) +SetRelationshipBetweenGroups(1, `GANG_2`, `PLAYER`) +SetRelationshipBetweenGroups(1, `GANG_9`, `PLAYER`) +SetRelationshipBetweenGroups(1, `GANG_10`, `PLAYER`) +SetRelationshipBetweenGroups(1, `FIREMAN`, `PLAYER`) +SetRelationshipBetweenGroups(1, `MEDIC`, `PLAYER`) +SetRelationshipBetweenGroups(1, `COP`, `PLAYER`) +SetRelationshipBetweenGroups(1, `PRISONER`, `PLAYER`) + +local density = lib.load('qbx_density.config') + +local function setDensity(type, value) + if type == 'parked' then + density.parked = value + elseif type == 'vehicle' then + density.vehicle = value + elseif type == 'multiplier' then + density.multiplier = value + elseif type == 'peds' then + density.peds = value + elseif type == 'scenario' then + density.scenario = value + end +end + +---@deprecated use SetDensity instead +exports('DecorSet', setDensity) +exports('SetDensity', setDensity) + +CreateThread(function() + while true do + SetParkedVehicleDensityMultiplierThisFrame(density.parked) + SetVehicleDensityMultiplierThisFrame(density.vehicle) + SetRandomVehicleDensityMultiplierThisFrame(density.multiplier) + SetPedDensityMultiplierThisFrame(density.peds) + SetScenarioPedDensityMultiplierThisFrame(density.scenario, density.scenario) -- Walking NPC Density + Wait(0) + end end) \ No newline at end of file diff --git a/config/client.lua b/config/client.lua new file mode 100644 index 0000000..2cd02b0 --- /dev/null +++ b/config/client.lua @@ -0,0 +1,7 @@ +return { + parked = 0.8, + vehicle = 0.8, + multiplier = 0.8, + peds = 0.8, + scenario = 0.8, +} \ No newline at end of file diff --git a/fxmanifest.lua b/fxmanifest.lua index dec8ed3..467e811 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -6,7 +6,14 @@ description 'Population management' repository 'https://github.com/Qbox-project/qbx_density' version '1.0.0' -client_script 'main.lua' +client_scripts { + '@ox_lib/init.lua', + 'client/main.lua' +} + +files { + 'config/client.lua' +} lua54 'yes' use_experimental_fxv2_oal 'yes' From 182e13c67123ecc3a5dddd90ddccc7db9a12be8c Mon Sep 17 00:00:00 2001 From: Solareon <769465+solareon@users.noreply.github.com> Date: Wed, 10 Jul 2024 21:59:13 +0200 Subject: [PATCH 2/2] chore(client/main): add descriptive comments --- config/client.lua | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/config/client.lua b/config/client.lua index 2cd02b0..47f9b57 100644 --- a/config/client.lua +++ b/config/client.lua @@ -1,7 +1,11 @@ return { - parked = 0.8, - vehicle = 0.8, - multiplier = 0.8, - peds = 0.8, - scenario = 0.8, + -- Density of various things in the world + -- Minimum value is 0.0, maximum value is 1.0 + -- Value of 1.0 represents GTA Online populate rates + -- Value of 0.0 removes all of that type + parked = 0.8, -- Density of parked vehicles + vehicle = 0.8, -- Density of vehicles + randomvehicles = 0.8, -- Density of random vehicles + peds = 0.8, -- Density of random peds (civilians, etc.) + scenario = 0.8, -- Density of scenario peds (bikers, gangsters, etc.) } \ No newline at end of file