refactor: general improvement and cleanup
This commit is contained in:
+25
-39
@@ -5,18 +5,17 @@ local currentGear = {
|
|||||||
enabled = false
|
enabled = false
|
||||||
}
|
}
|
||||||
|
|
||||||
local isWearingSuit = false
|
|
||||||
local oxygenLevel = 0
|
local oxygenLevel = 0
|
||||||
|
|
||||||
RegisterNetEvent("qb-diving:client:setoxygenlevel", function()
|
lib.callback.register('qbx_divegear:client:fillTank', function()
|
||||||
if oxygenLevel == 0 then
|
if oxygenLevel ~= 0 then
|
||||||
oxygenLevel = Config.OxygenLevel
|
exports.qbx_core:Notify(Lang:t("error.oxygenlevel", {oxygenlevel = oxygenLevel}), 'error')
|
||||||
exports.qbx_core:Notify(Lang:t("success.tube_filled"), 'success')
|
return false
|
||||||
TriggerServerEvent('qb-diving:server:removeItemAfterFill')
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
|
||||||
exports.qbx_core:Notify(Lang:t("error.oxygenlevel", {oxygenlevel = oxygenLevel}), 'error')
|
oxygenLevel = Config.OxygenLevel
|
||||||
|
exports.qbx_core:Notify(Lang:t("success.tube_filled"), 'success')
|
||||||
|
return true
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local function deleteGear()
|
local function deleteGear()
|
||||||
@@ -33,8 +32,7 @@ local function deleteGear()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
RegisterNetEvent('qb-diving:client:UseGear', function()
|
local function takeOffSuit()
|
||||||
if isWearingSuit then
|
|
||||||
if lib.progressBar({
|
if lib.progressBar({
|
||||||
duration = 5000,
|
duration = 5000,
|
||||||
label = Lang:t("info.pullout_suit"),
|
label = Lang:t("info.pullout_suit"),
|
||||||
@@ -52,19 +50,17 @@ RegisterNetEvent('qb-diving:client:UseGear', function()
|
|||||||
deleteGear()
|
deleteGear()
|
||||||
exports.qbx_core:Notify(Lang:t("success.took_out"))
|
exports.qbx_core:Notify(Lang:t("success.took_out"))
|
||||||
TriggerServerEvent("InteractSound_SV:PlayOnSource", nil, 0.25)
|
TriggerServerEvent("InteractSound_SV:PlayOnSource", nil, 0.25)
|
||||||
isWearingSuit = false
|
|
||||||
oxygenLevel = oxygenLevel
|
|
||||||
end
|
end
|
||||||
|
|
||||||
ClearPedTasks(cache.ped)
|
ClearPedTasks(cache.ped)
|
||||||
else
|
end
|
||||||
|
|
||||||
|
local function putOnSuit()
|
||||||
if oxygenLevel <= 0 then
|
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
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
isWearingSuit = true
|
|
||||||
|
|
||||||
if IsPedSwimming(cache.ped) or cache.vehicle then
|
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
|
return
|
||||||
@@ -105,40 +101,30 @@ RegisterNetEvent('qb-diving:client:UseGear', function()
|
|||||||
elseif oxygenLevel == 0 then
|
elseif oxygenLevel == 0 then
|
||||||
SetEnableScuba(cache.ped, false)
|
SetEnableScuba(cache.ped, false)
|
||||||
SetPedMaxTimeUnderwater(cache.ped, 1.00)
|
SetPedMaxTimeUnderwater(cache.ped, 1.00)
|
||||||
currentGear.enabled = false
|
|
||||||
isWearingSuit = false
|
|
||||||
TriggerServerEvent("InteractSound_SV:PlayOnSource", nil, 0.25)
|
TriggerServerEvent("InteractSound_SV:PlayOnSource", nil, 0.25)
|
||||||
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Wait(1000)
|
Wait(1000)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
CreateThread(function()
|
||||||
|
while currentGear.enabled do
|
||||||
|
if IsPedSwimmingUnderWater(cache.ped) then
|
||||||
|
DrawText2D(oxygenLevel..'⏱', vec2(0.45, 0.90), 1.0, 1.0, 0.45)
|
||||||
|
end
|
||||||
|
Wait(0)
|
||||||
|
end
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
ClearPedTasks(cache.ped)
|
ClearPedTasks(cache.ped)
|
||||||
end
|
end
|
||||||
end)
|
|
||||||
|
|
||||||
local function DrawText(text)
|
RegisterNetEvent('qbx_divegear:client:useGear', function()
|
||||||
SetTextFont(4)
|
if currentGear.enabled then
|
||||||
SetTextProportional(true)
|
takeOffSuit()
|
||||||
SetTextScale(0.0, 0.45)
|
else
|
||||||
SetTextDropshadow(1, 0, 0, 0, 255)
|
putOnSuit()
|
||||||
SetTextEdge(1, 0, 0, 0, 255)
|
|
||||||
SetTextDropShadow()
|
|
||||||
SetTextOutline()
|
|
||||||
BeginTextCommandDisplayText("STRING")
|
|
||||||
AddTextComponentSubstringPlayerName(text)
|
|
||||||
EndTextCommandDisplayText(0.45, 0.90)
|
|
||||||
end
|
|
||||||
|
|
||||||
CreateThread(function()
|
|
||||||
while true do
|
|
||||||
if currentGear.enabled and isWearingSuit then
|
|
||||||
if IsPedSwimmingUnderWater(cache.ped) then
|
|
||||||
DrawText(oxygenLevel..'⏱')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
Wait(0)
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
@@ -10,6 +10,8 @@ shared_script {
|
|||||||
'locales/en.lua',
|
'locales/en.lua',
|
||||||
'locales/*.lua',
|
'locales/*.lua',
|
||||||
'config.lua',
|
'config.lua',
|
||||||
|
'@qbx_core/import.lua',
|
||||||
|
'qbx_core:utils',
|
||||||
}
|
}
|
||||||
|
|
||||||
server_scripts {
|
server_scripts {
|
||||||
|
|||||||
+4
-5
@@ -1,11 +1,10 @@
|
|||||||
exports.qbx_core:CreateUseableItem("diving_gear", function(source)
|
exports.qbx_core:CreateUseableItem("diving_gear", function(source)
|
||||||
TriggerClientEvent("qb-diving:client:UseGear", source)
|
TriggerClientEvent('qbx_divegear:client:useGear', source)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
exports.qbx_core:CreateUseableItem("diving_fill", function(source)
|
exports.qbx_core:CreateUseableItem("diving_fill", function(source)
|
||||||
TriggerClientEvent("qb-diving:client:setoxygenlevel", source)
|
local success = lib.callback.await('qbx_divegear:client:fillTank', source)
|
||||||
end)
|
if success then
|
||||||
|
|
||||||
RegisterNetEvent('qb-diving:server:removeItemAfterFill', function()
|
|
||||||
exports.ox_inventory:RemoveItem(source, 'diving_fill', 1)
|
exports.ox_inventory:RemoveItem(source, 'diving_fill', 1)
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
Reference in New Issue
Block a user