fix(client): can now run out of oxygen & don't need to take off suit to re-fill
This commit is contained in:
+63
-43
@@ -1,12 +1,21 @@
|
|||||||
local currentGear = {
|
local currentGear = {
|
||||||
mask = 0,
|
mask = 0,
|
||||||
tank = 0,
|
tank = 0,
|
||||||
oxygen = 0,
|
|
||||||
enabled = false
|
enabled = false
|
||||||
}
|
}
|
||||||
|
|
||||||
local oxygenLevel = 0
|
local oxygenLevel = 0
|
||||||
|
|
||||||
|
local function enableScuba()
|
||||||
|
SetEnableScuba(cache.ped, true)
|
||||||
|
SetPedMaxTimeUnderwater(cache.ped, 2000.00)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function disableScuba()
|
||||||
|
SetEnableScuba(cache.ped, false)
|
||||||
|
SetPedMaxTimeUnderwater(cache.ped, 1.00)
|
||||||
|
end
|
||||||
|
|
||||||
lib.callback.register('qbx_divegear:client:fillTank', function()
|
lib.callback.register('qbx_divegear:client:fillTank', function()
|
||||||
if oxygenLevel ~= 0 then
|
if oxygenLevel ~= 0 then
|
||||||
exports.qbx_core:Notify(Lang:t("error.oxygenlevel", {oxygenlevel = oxygenLevel}), 'error')
|
exports.qbx_core:Notify(Lang:t("error.oxygenlevel", {oxygenlevel = oxygenLevel}), 'error')
|
||||||
@@ -15,6 +24,9 @@ lib.callback.register('qbx_divegear:client:fillTank', function()
|
|||||||
|
|
||||||
oxygenLevel = Config.OxygenLevel
|
oxygenLevel = Config.OxygenLevel
|
||||||
exports.qbx_core:Notify(Lang:t("success.tube_filled"), 'success')
|
exports.qbx_core:Notify(Lang:t("success.tube_filled"), 'success')
|
||||||
|
if currentGear.enabled then
|
||||||
|
enableScuba()
|
||||||
|
end
|
||||||
return true
|
return true
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -32,6 +44,21 @@ local function deleteGear()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function attachGear()
|
||||||
|
local maskModel = `p_d_scuba_mask_s`
|
||||||
|
local tankModel = `p_s_scuba_tank_s`
|
||||||
|
lib.requestModel(maskModel)
|
||||||
|
lib.requestModel(tankModel)
|
||||||
|
|
||||||
|
currentGear.tank = CreateObject(tankModel, 1.0, 1.0, 1.0, true, true, false)
|
||||||
|
local bone1 = GetPedBoneIndex(cache.ped, 24818)
|
||||||
|
AttachEntityToEntity(currentGear.tank, cache.ped, bone1, -0.25, -0.25, 0.0, 180.0, 90.0, 0.0, true, true, false, false, 2, true)
|
||||||
|
|
||||||
|
currentGear.mask = CreateObject(maskModel, 1.0, 1.0, 1.0, true, true, false)
|
||||||
|
local bone2 = GetPedBoneIndex(cache.ped, 12844)
|
||||||
|
AttachEntityToEntity(currentGear.mask, cache.ped, bone2, 0.0, 0.0, 0.0, 180.0, 90.0, 0.0, true, true, false, false, 2, true)
|
||||||
|
end
|
||||||
|
|
||||||
local function takeOffSuit()
|
local function takeOffSuit()
|
||||||
if lib.progressBar({
|
if lib.progressBar({
|
||||||
duration = 5000,
|
duration = 5000,
|
||||||
@@ -51,12 +78,9 @@ local function takeOffSuit()
|
|||||||
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)
|
||||||
end
|
end
|
||||||
|
|
||||||
ClearPedTasks(cache.ped)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function DrawText(text)
|
local function drawText(text)
|
||||||
ClearPedTasks(cache.ped)
|
|
||||||
SetTextFont(4)
|
SetTextFont(4)
|
||||||
SetTextProportional(true)
|
SetTextProportional(true)
|
||||||
SetTextScale(0.0, 0.45)
|
SetTextScale(0.0, 0.45)
|
||||||
@@ -69,6 +93,36 @@ local function DrawText(text)
|
|||||||
EndTextCommandDisplayText(0.45, 0.90)
|
EndTextCommandDisplayText(0.45, 0.90)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function startOxygenLevelDrawTextThread()
|
||||||
|
CreateThread(function()
|
||||||
|
while currentGear.enabled do
|
||||||
|
if IsPedSwimmingUnderWater(cache.ped) then
|
||||||
|
drawText(oxygenLevel..'⏱')
|
||||||
|
end
|
||||||
|
Wait(0)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function startOxygenLevelDecrementerThread()
|
||||||
|
CreateThread(function()
|
||||||
|
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)
|
||||||
|
end
|
||||||
|
if oxygenLevel == 0 then
|
||||||
|
disableScuba()
|
||||||
|
TriggerServerEvent("InteractSound_SV:PlayOnSource", nil, 0.25)
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
Wait(1000)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
local function putOnSuit()
|
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')
|
||||||
@@ -92,47 +146,13 @@ local function putOnSuit()
|
|||||||
}
|
}
|
||||||
}) then
|
}) then
|
||||||
deleteGear()
|
deleteGear()
|
||||||
local maskModel = `p_d_scuba_mask_s`
|
attachGear()
|
||||||
local tankModel = `p_s_scuba_tank_s`
|
enableScuba()
|
||||||
lib.requestModel(maskModel)
|
|
||||||
lib.requestModel(tankModel)
|
|
||||||
currentGear.tank = CreateObject(tankModel, 1.0, 1.0, 1.0, true, true, false)
|
|
||||||
local bone1 = GetPedBoneIndex(cache.ped, 24818)
|
|
||||||
AttachEntityToEntity(currentGear.tank, cache.ped, bone1, -0.25, -0.25, 0.0, 180.0, 90.0, 0.0, true, true, false, false, 2, true)
|
|
||||||
currentGear.mask = CreateObject(maskModel, 1.0, 1.0, 1.0, true, true, false)
|
|
||||||
local bone2 = GetPedBoneIndex(cache.ped, 12844)
|
|
||||||
AttachEntityToEntity(currentGear.mask, cache.ped, bone2, 0.0, 0.0, 0.0, 180.0, 90.0, 0.0, true, true, false, false, 2, true)
|
|
||||||
SetEnableScuba(cache.ped, true)
|
|
||||||
SetPedMaxTimeUnderwater(cache.ped, 2000.00)
|
|
||||||
currentGear.enabled = true
|
currentGear.enabled = true
|
||||||
TriggerServerEvent("InteractSound_SV:PlayOnSource", "breathdivingsuit", 0.25)
|
TriggerServerEvent("InteractSound_SV:PlayOnSource", "breathdivingsuit", 0.25)
|
||||||
CreateThread(function()
|
startOxygenLevelDecrementerThread()
|
||||||
while currentGear.enabled do
|
startOxygenLevelDrawTextThread()
|
||||||
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)
|
|
||||||
elseif oxygenLevel == 0 then
|
|
||||||
SetEnableScuba(cache.ped, false)
|
|
||||||
SetPedMaxTimeUnderwater(cache.ped, 1.00)
|
|
||||||
TriggerServerEvent("InteractSound_SV:PlayOnSource", nil, 0.25)
|
|
||||||
break
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
Wait(1000)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
CreateThread(function()
|
|
||||||
while currentGear.enabled do
|
|
||||||
if IsPedSwimmingUnderWater(cache.ped) then
|
|
||||||
DrawText(oxygenLevel..'⏱')
|
|
||||||
end
|
|
||||||
Wait(0)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
ClearPedTasks(cache.ped)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
RegisterNetEvent('qbx_divegear:client:useGear', function()
|
RegisterNetEvent('qbx_divegear:client:useGear', function()
|
||||||
|
|||||||
Reference in New Issue
Block a user