Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(client/main): fix structure and move config out of client lua #2

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
94 changes: 45 additions & 49 deletions main.lua → client/main.lua
Original file line number Diff line number Diff line change
@@ -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)
solareon marked this conversation as resolved.
Show resolved Hide resolved
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)
11 changes: 11 additions & 0 deletions config/client.lua
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These could benefit from explanation comments. peds/scenario can be a bit confusing.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
return {
-- 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.)
}
9 changes: 8 additions & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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'