Skip to content

Commit

Permalink
refactor: split config
Browse files Browse the repository at this point in the history
  • Loading branch information
mafewtm authored Nov 24, 2023
1 parent 3d405ab commit ae89350
Show file tree
Hide file tree
Showing 11 changed files with 281 additions and 271 deletions.
14 changes: 8 additions & 6 deletions client/hospital.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local config = require 'config.client'
local sharedConfig = require 'config.shared'
local bedObject = nil
local bedOccupyingData = nil
local cam = nil
Expand Down Expand Up @@ -57,7 +59,7 @@ local function putPlayerInBed(hospitalName, bedIndex, isRevive, skipOpenCheck)

hospitalOccupying = hospitalName
bedIndexOccupying = bedIndex
bedOccupyingData = Config.Locations.hospitals[hospitalName].beds[bedIndex]
bedOccupyingData = sharedConfig.locations.hospitals[hospitalName].beds[bedIndex]
IsInHospitalBed = true
exports.qbx_medical:DisableDamageEffects()
exports.qbx_medical:disableRespawn()
Expand All @@ -67,7 +69,7 @@ local function putPlayerInBed(hospitalName, bedIndex, isRevive, skipOpenCheck)
Wait(5)
if isRevive then
exports.qbx_core:Notify(Lang:t('success.being_helped'), 'success')
Wait(Config.AIHealTimer * 1000)
Wait(config.aiHealTime * 1000)
TriggerEvent("hospital:client:Revive")
else
CanLeaveBed = true
Expand Down Expand Up @@ -116,9 +118,9 @@ local function checkIn(hospitalName)
end

---Set up check-in and getting into beds using either target or zones
if Config.UseTarget then
if config.useTarget then
CreateThread(function()
for hospitalName, hospital in pairs(Config.Locations.hospitals) do
for hospitalName, hospital in pairs(sharedConfig.locations.hospitals) do
if hospital.checkIn then
exports.ox_target:addBoxZone({
name = hospitalName.."_checkin",
Expand Down Expand Up @@ -163,12 +165,12 @@ if Config.UseTarget then
end)
else
CreateThread(function()
for hospitalName, hospital in pairs(Config.Locations.hospitals) do
for hospitalName, hospital in pairs(sharedConfig.locations.hospitals) do

if hospital.checkIn then
local function enterCheckInZone()
local numDoctors = lib.callback.await('qbx_ambulancejob:server:getNumDoctors')
if numDoctors >= Config.MinimalDoctors then
if numDoctors >= config.minForCheckIn then
lib.showTextUI(Lang:t('text.call_doc'))
else
lib.showTextUI(Lang:t('text.check_in'))
Expand Down
52 changes: 27 additions & 25 deletions client/job.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local config = require 'config.client'
local sharedConfig = require 'config.shared'
local checkVehicle = false
local WEAPONS = exports.qbx_core:GetWeapons()

Expand All @@ -15,7 +17,7 @@ local function takeOutVehicle(data)
TriggerEvent("vehiclekeys:client:SetOwner", GetPlate(veh))
SetVehicleEngineOn(veh, true, true, true)

local settings = Config.VehicleSettings[data.vehicleName]
local settings = config.vehicleSettings[data.vehicleName]
if not settings then return end

if settings.extra then
Expand Down Expand Up @@ -201,7 +203,7 @@ end
---Opens the hospital armory.
local function openArmory()
if QBX.PlayerData.job.onduty then
TriggerServerEvent("inventory:server:OpenInventory", "shop", "hospital", Config.Items)
TriggerServerEvent("inventory:server:OpenInventory", "shop", "hospital", config.items)
end
end

Expand Down Expand Up @@ -246,12 +248,12 @@ end

---Teleports the player to main elevator
local function teleportToMainElevator()
teleportPlayerWithFade(Config.Locations.main[1])
teleportPlayerWithFade(sharedConfig.locations.main[1])
end

---Teleports the player to roof elevator
local function teleportToRoofElevator()
teleportPlayerWithFade(Config.Locations.roof[1])
teleportPlayerWithFade(sharedConfig.locations.roof[1])
end

---Toggles the on duty status of the player.
Expand Down Expand Up @@ -293,22 +295,22 @@ end

---Creates air and land garages to spawn vehicles at for EMS personnel
CreateThread(function()
for _, coords in pairs(Config.Locations.vehicle) do
createGarage(Config.AuthorizedVehicles, Lang:t('info.amb_plate'), coords)
for _, coords in pairs(sharedConfig.locations.vehicle) do
createGarage(config.authorizedVehicles, Lang:t('info.amb_plate'), coords)
end

for _, coords in pairs(Config.Locations.helicopter) do
createGarage(Config.AuthorizedHelicopters, Lang:t('info.heli_plate'), coords)
for _, coords in pairs(sharedConfig.locations.helicopter) do
createGarage(config.authorizedHelicopters, Lang:t('info.heli_plate'), coords)
end
end)

---Sets up duty toggle, stash, armory, and elevator interactions using either target or zones.
if Config.UseTarget then
if config.useTarget then
CreateThread(function()
for i = 1, #Config.Locations.duty do
for i = 1, #sharedConfig.locations.duty do
exports.ox_target:addBoxZone({
name = "duty" .. i,
coords = Config.Locations.duty[i],
coords = sharedConfig.locations.duty[i],
size = vec3(1.5, 1, 2),
rotation = 71,
debug = false,
Expand All @@ -324,10 +326,10 @@ if Config.UseTarget then
}
})
end
for i = 1, #Config.Locations.stash do
for i = 1, #sharedConfig.locations.stash do
exports.ox_target:addBoxZone({
name = "stash" .. i,
coords = Config.Locations.stash[i],
coords = sharedConfig.locations.stash[i],
size = vec3(1, 1, 2),
rotation = -20,
debug = false,
Expand All @@ -343,10 +345,10 @@ if Config.UseTarget then
}
})
end
for i = 1, #Config.Locations.armory do
for i = 1, #sharedConfig.locations.armory do
exports.ox_target:addBoxZone({
name = "armory" .. i,
coords = Config.Locations.armory[i],
coords = sharedConfig.locations.armory[i],
size = vec3(1, 1, 2),
rotation = -20,
debug = false,
Expand All @@ -364,7 +366,7 @@ if Config.UseTarget then
end
exports.ox_target:addBoxZone({
name = "roof1",
coords = Config.Locations.roof[1],
coords = sharedConfig.locations.roof[1],
size = vec3(1, 2, 2),
rotation = -20,
debug = false,
Expand All @@ -381,7 +383,7 @@ if Config.UseTarget then
})
exports.ox_target:addBoxZone({
name = "main1",
coords = Config.Locations.main[1],
coords = sharedConfig.locations.main[1],
size = vec3(2, 1, 2),
rotation = -20,
debug = false,
Expand All @@ -399,7 +401,7 @@ if Config.UseTarget then
end)
else
CreateThread(function()
for i = 1, #Config.Locations.duty do
for i = 1, #sharedConfig.locations.duty do
local function enteredSignInZone()
if not QBX.PlayerData.job.onduty then
lib.showTextUI(Lang:t('text.onduty_button'))
Expand All @@ -417,7 +419,7 @@ else
end

lib.zones.box({
coords = Config.Locations.duty[i],
coords = sharedConfig.locations.duty[i],
size = vec3(1, 1, 2),
rotation = -20,
debug = false,
Expand All @@ -427,7 +429,7 @@ else
})
end

for i = 1, #Config.Locations.stash do
for i = 1, #sharedConfig.locations.stash do
local function enteredStashZone()
if QBX.PlayerData.job.onduty then
lib.showTextUI(Lang:t('text.pstash_button'))
Expand All @@ -443,7 +445,7 @@ else
end

lib.zones.box({
coords = Config.Locations.stash[i],
coords = sharedConfig.locations.stash[i],
size = vec3(1, 1, 2),
rotation = -20,
debug = false,
Expand All @@ -453,7 +455,7 @@ else
})
end

for i = 1, #Config.Locations.armory do
for i = 1, #sharedConfig.locations.armory do
local function enteredArmoryZone()
if QBX.PlayerData.job.onduty then
lib.showTextUI(Lang:t('text.armory_button'))
Expand All @@ -469,7 +471,7 @@ else
end

lib.zones.box({
coords = Config.Locations.armory[i],
coords = sharedConfig.locations.armory[i],
size = vec3(1, 1, 2),
rotation = -20,
debug = false,
Expand All @@ -496,7 +498,7 @@ else
end

lib.zones.box({
coords = Config.Locations.roof[1],
coords = sharedConfig.locations.roof[1],
size = vec3(1, 1, 2),
rotation = -20,
debug = false,
Expand All @@ -522,7 +524,7 @@ else
end

lib.zones.box({
coords = Config.Locations.main[1],
coords = sharedConfig.locations.main[1],
size = vec3(1, 1, 2),
rotation = -20,
debug = false,
Expand Down
3 changes: 2 additions & 1 deletion client/main.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local sharedConfig = require 'config.shared'
InBedDict = "anim@gangops@morgue@table@"
InBedAnim = "body_search"
IsInHospitalBed = false
Expand Down Expand Up @@ -85,7 +86,7 @@ end)

---sets blips for stations on map
CreateThread(function()
for _, station in pairs(Config.Locations.stations) do
for _, station in pairs(sharedConfig.locations.stations) do
local blip = AddBlipForCoord(station.coords.x, station.coords.y, station.coords.z)
SetBlipSprite(blip, 61)
SetBlipAsShortRange(blip, true)
Expand Down
6 changes: 4 additions & 2 deletions client/setdownedstate.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local config = require 'config.client'
local sharedConfig = require 'config.shared'
local doctorCount = 0

local function getDoctorCount()
Expand All @@ -9,7 +11,7 @@ local function displayRespawnText()
if deathTime > 0 and doctorCount > 0 then
DrawText2D(Lang:t('info.respawn_txt', { deathtime = math.ceil(deathTime) }), vec2(1.0, 1.44), 1.0, 1.0, 0.6, 4, 255, 255, 255, 255)
else
DrawText2D(Lang:t('info.respawn_revive', { holdtime = exports.qbx_medical:getRespawnHoldTimeDeprecated(), cost = Config.BillCost }), vec2(1.0, 1.44), 1.0, 1.0, 0.6, 4, 255, 255, 255, 255)
DrawText2D(Lang:t('info.respawn_revive', { holdtime = exports.qbx_medical:getRespawnHoldTimeDeprecated(), cost = sharedConfig.checkInCost }), vec2(1.0, 1.44), 1.0, 1.0, 0.6, 4, 255, 255, 255, 255)
end
end

Expand Down Expand Up @@ -49,7 +51,7 @@ end

local function handleLastStand()
local laststandTime = exports.qbx_medical:getLaststandTime()
if laststandTime > Config.LaststandMinimumRevive or doctorCount == 0 then
if laststandTime > config.laststandTimer or doctorCount == 0 then
DrawText2D(Lang:t('info.bleed_out', { time = math.ceil(laststandTime) }), vec2(1.0, 1.44), 1.0, 1.0, 0.6, 4, 255, 255, 255, 255)
else
DrawText2D(Lang:t('info.bleed_out_help', { time = math.ceil(laststandTime) }), vec2(1.0, 1.44), 1.0, 1.0, 0.6, 4, 255, 255, 255, 255)
Expand Down
3 changes: 2 additions & 1 deletion client/wounding.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local config = require 'config.client'
local painkillerAmount = 0

-- Events
Expand Down Expand Up @@ -116,7 +117,7 @@ end)

local function consumePainKiller()
painkillerAmount -= 1
Wait(Config.PainkillerInterval * 1000)
Wait(config.painkillerInterval * 1000)
if painkillerAmount > 0 then return end
painkillerAmount = 0
OnPainKillers = false
Expand Down
Loading

0 comments on commit ae89350

Please sign in to comment.