refactor: split config

This commit is contained in:
Matthew
2023-11-17 22:11:02 -08:00
committed by GitHub
parent d4c5857316
commit b50550abd5
4 changed files with 33 additions and 46 deletions
+25 -38
View File
@@ -1,4 +1,4 @@
local Config = require 'config.client'
local config = require 'config.client'
local currentGear = {
mask = 0,
@@ -20,24 +20,24 @@ end
lib.callback.register('qbx_divegear:client:fillTank', function()
if IsPedSwimmingUnderWater(cache.ped) then
exports.qbx_core:Notify(Lang:t("error.underwater", {oxygenlevel = oxygenLevel}), 'error')
exports.qbx_core:Notify(Lang:t('error.underwater', {oxygenlevel = oxygenLevel}), 'error')
return false
end
if lib.progressBar({
duration = Config.RefillTankTimeMs,
label = Lang:t("info.filling_air"),
duration = config.RefillTankTimeMs,
label = Lang:t('info.filling_air'),
useWhileDead = false,
canCancel = true,
anim = {
dict = "clothingshirt",
clip = "try_shirt_positive_d",
dict = 'clothingshirt',
clip = 'try_shirt_positive_d',
blendIn = 8.0
}
}) then
oxygenLevel = Config.OxygenLevel
exports.qbx_core:Notify(Lang:t("success.tube_filled"), 'success')
oxygenLevel = config.startingOxygenLevel
exports.qbx_core:Notify(Lang:t('success.tube_filled'), 'success')
if currentGear.enabled then
enableScuba()
end
@@ -76,13 +76,13 @@ end
local function takeOffSuit()
if lib.progressBar({
duration = Config.TakeOffSuitTimeMs,
label = Lang:t("info.pullout_suit"),
duration = config.TakeOffSuitTimeMs,
label = Lang:t('info.pullout_suit'),
useWhileDead = false,
canCancel = true,
anim = {
dict = "clothingshirt",
clip = "try_shirt_positive_d",
dict = 'clothingshirt',
clip = 'try_shirt_positive_d',
blendIn = 8.0
}
}) then
@@ -90,29 +90,16 @@ local function takeOffSuit()
SetPedMaxTimeUnderwater(cache.ped, 50.00)
currentGear.enabled = false
deleteGear()
exports.qbx_core:Notify(Lang:t("success.took_out"))
TriggerServerEvent("InteractSound_SV:PlayOnSource", nil, 0.25)
exports.qbx_core:Notify(Lang:t('success.took_out'))
TriggerServerEvent('InteractSound_SV:PlayOnSource', nil, 0.25)
end
end
local function drawText(text)
SetTextFont(4)
SetTextProportional(true)
SetTextScale(0.0, 0.45)
SetTextDropshadow(1, 0, 0, 0, 255)
SetTextEdge(1, 0, 0, 0, 255)
SetTextDropShadow()
SetTextOutline()
BeginTextCommandDisplayText("STRING")
AddTextComponentSubstringPlayerName(text)
EndTextCommandDisplayText(0.45, 0.90)
end
local function startOxygenLevelDrawTextThread()
CreateThread(function()
while currentGear.enabled do
if IsPedSwimmingUnderWater(cache.ped) then
drawText(oxygenLevel..'')
DrawText2D(oxygenLevel..'', vec2(1.0, 1.42), 1.0, 1.0, 0.45, 4)
end
Wait(0)
end
@@ -124,12 +111,12 @@ local function startOxygenLevelDecrementerThread()
while currentGear.enabled do
if IsPedSwimmingUnderWater(cache.ped) and oxygenLevel > 0 then
oxygenLevel -= 1
if oxygenLevel % 10 == 0 and oxygenLevel ~= Config.OxygenLevel then
TriggerServerEvent("InteractSound_SV:PlayOnSource", "breathdivingsuit", 0.25)
if oxygenLevel % 10 == 0 and oxygenLevel ~= config.startingOxygenLevel then
TriggerServerEvent('InteractSound_SV:PlayOnSource', 'breathdivingsuit', 0.25)
end
if oxygenLevel == 0 then
disableScuba()
TriggerServerEvent("InteractSound_SV:PlayOnSource", nil, 0.25)
TriggerServerEvent('InteractSound_SV:PlayOnSource', nil, 0.25)
end
end
Wait(1000)
@@ -139,23 +126,23 @@ end
local function putOnSuit()
if oxygenLevel <= 0 then
exports.qbx_core:Notify(Lang:t("error.need_otube"), 'error')
exports.qbx_core:Notify(Lang:t('error.need_otube'), 'error')
return
end
if IsPedSwimming(cache.ped) or cache.vehicle then
exports.qbx_core:Notify(Lang:t("error.not_standing_up"), 'error')
exports.qbx_core:Notify(Lang:t('error.not_standing_up'), 'error')
return
end
if lib.progressBar({
duration = Config.PutOnSuitTimeMs,
label = Lang:t("info.put_suit"),
duration = config.PutOnSuitTimeMs,
label = Lang:t('info.put_suit'),
useWhileDead = false,
canCancel = true,
anim = {
dict = "clothingshirt",
clip = "try_shirt_positive_d",
dict = 'clothingshirt',
clip = 'try_shirt_positive_d',
blendIn = 8.0
}
}) then
@@ -163,7 +150,7 @@ local function putOnSuit()
attachGear()
enableScuba()
currentGear.enabled = true
TriggerServerEvent("InteractSound_SV:PlayOnSource", "breathdivingsuit", 0.25)
TriggerServerEvent('InteractSound_SV:PlayOnSource', 'breathdivingsuit', 0.25)
startOxygenLevelDecrementerThread()
startOxygenLevelDrawTextThread()
end
+3 -3
View File
@@ -1,6 +1,6 @@
return {
OxygenLevel = 100,
PutOnSuitTimeMs = 5000,
TakeOffSuitTimeMs = 5000,
startingOxygenLevel = 100,
putOnSuitTimeMs = 5000,
takeOffSuitTimeMs = 5000,
RefillTankTimeMs = 5000
}
+3 -3
View File
@@ -2,17 +2,17 @@ local Translations = {
error = {
canceled = "Canceled",
not_standing_up = "You need to be on solid ground to put this on...",
need_otube = "you need to refill your oxygen! Get a replacement air supply!",
need_otube = "You need to refill your oxygen! Get a replacement air supply!",
underwater = "Cannot do this underwater",
},
success = {
took_out = "You took your diving gear off.",
took_out = "You took your diving gear off",
tube_filled = "You've successfully refilled your air tank!"
},
info = {
put_suit = "Putting on your diving suit...",
pullout_suit = "Taking off your diving suit...",
filling_air = "Filling air"
filling_air = "Filling air..."
},
warning = {
oxygen_one_minute = "You have less than one minute of air remaining!",
+2 -2
View File
@@ -1,8 +1,8 @@
exports.qbx_core:CreateUseableItem("diving_gear", function(source)
exports.qbx_core:CreateUseableItem('diving_gear', function(source)
TriggerClientEvent('qbx_divegear:client:useGear', source)
end)
exports.qbx_core:CreateUseableItem("diving_fill", function(source)
exports.qbx_core:CreateUseableItem('diving_fill', function(source)
local success = lib.callback.await('qbx_divegear:client:fillTank', source)
if success then
exports.ox_inventory:RemoveItem(source, 'diving_fill', 1)