From 5e06e1f6e32cc574251aaff5399e42f150bac040 Mon Sep 17 00:00:00 2001 From: Manason Date: Wed, 8 Nov 2023 18:38:02 -0800 Subject: [PATCH] feat: move dive gear into a new resource --- client/suit.lua | 144 ------------------------------------------------ config.lua | 1 - locales/en.lua | 13 ----- server/suit.lua | 11 ---- 4 files changed, 169 deletions(-) delete mode 100644 client/suit.lua delete mode 100644 server/suit.lua diff --git a/client/suit.lua b/client/suit.lua deleted file mode 100644 index d1eab3d..0000000 --- a/client/suit.lua +++ /dev/null @@ -1,144 +0,0 @@ -local currentGear = { - mask = 0, - tank = 0, - oxygen = 0, - enabled = false -} - -local isWearingSuit = false -local oxygenLevel = 0 - -RegisterNetEvent("qb-diving:client:setoxygenlevel", function() - if oxygenLevel == 0 then - oxygenLevel = Config.OxygenLevel - exports.qbx_core:Notify(Lang:t("success.tube_filled"), 'success') - TriggerServerEvent('qb-diving:server:removeItemAfterFill') - return - end - - exports.qbx_core:Notify(Lang:t("error.oxygenlevel", {oxygenlevel = oxygenLevel}), 'error') -end) - -local function deleteGear() - if currentGear.mask ~= 0 then - DetachEntity(currentGear.mask, false, true) - DeleteEntity(currentGear.mask) - currentGear.mask = 0 - end - - if currentGear.tank ~= 0 then - DetachEntity(currentGear.tank, false, true) - DeleteEntity(currentGear.tank) - currentGear.tank = 0 - end -end - -RegisterNetEvent('qb-diving:client:UseGear', function() - if isWearingSuit then - if lib.progressBar({ - duration = 5000, - label = Lang:t("info.pullout_suit"), - useWhileDead = false, - canCancel = true, - anim = { - dict = "clothingshirt", - clip = "try_shirt_positive_d", - blendIn = 8.0 - } - }) then - SetEnableScuba(cache.ped, false) - 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) - isWearingSuit = false - oxygenLevel = oxygenLevel - end - - ClearPedTasks(cache.ped) - else - if oxygenLevel <= 0 then - exports.qbx_core:Notify(Lang:t("error.need_otube"), 'error') - return - end - - isWearingSuit = true - - if IsPedSwimming(cache.ped) or cache.vehicle then - exports.qbx_core:Notify(Lang:t("error.not_standing_up"), 'error') - return - end - - if lib.progressBar({ - duration = 5000, - label = Lang:t("info.put_suit"), - useWhileDead = false, - canCancel = true, - anim = { - dict = "clothingshirt", - clip = "try_shirt_positive_d", - blendIn = 8.0 - } - }) then - deleteGear() - 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) - SetEnableScuba(cache.ped, true) - SetPedMaxTimeUnderwater(cache.ped, 2000.00) - currentGear.enabled = true - TriggerServerEvent("InteractSound_SV:PlayOnSource", "breathdivingsuit", 0.25) - 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) - elseif oxygenLevel == 0 then - SetEnableScuba(cache.ped, false) - SetPedMaxTimeUnderwater(cache.ped, 1.00) - currentGear.enabled = false - isWearingSuit = false - TriggerServerEvent("InteractSound_SV:PlayOnSource", nil, 0.25) - end - end - Wait(1000) - end - end) - end - - ClearPedTasks(cache.ped) - 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 - -CreateThread(function() - while true do - if currentGear.enabled and isWearingSuit then - if IsPedSwimmingUnderWater(cache.ped) then - DrawText(oxygenLevel..'⏱') - end - end - Wait(0) - end -end) diff --git a/config.lua b/config.lua index 46038a9..ecee7dc 100644 --- a/config.lua +++ b/config.lua @@ -1,7 +1,6 @@ Config = {} Config.UseTarget = GetConvar('UseTarget', 'false') == 'true' -- Use qb-target interactions (don't change this, go to your server.cfg and add `setr UseTarget true` to use this and just that from true to false or the other way around) Config.CopsChance = 0.5 -- The chance of the cops getting called when a coral gets picked up, this ranges from 0.0 to 1.0 -Config.OxygenLevel = 100 -- in seconds Config.Debug = false -- shows outline of box zones ---@class Coral diff --git a/locales/en.lua b/locales/en.lua index 97f8f42..00ba4ac 100644 --- a/locales/en.lua +++ b/locales/en.lua @@ -3,13 +3,6 @@ local Translations = { canceled = "Canceled", ["911_chatmessage"] = "911 MESSAGE", no_coral = "You don't have any coral to sell...", - 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!", - oxygenlevel = "Your air level is %{oxygenlevel}, it must be at 0 to refill!", - }, - success = { - took_out = "You took your diving gear off.", - tube_filled = "You've successfully refilled your air tank!" }, info = { collecting_coral = "Collecting coral", @@ -20,15 +13,9 @@ local Translations = { sell_coral = "Sell Coral", sell_coral_dt = "[E] - Sell Coral", blip_text = "911 - Dive Site", - put_suit = "Putting on your diving suit...", - pullout_suit = "Taking off your diving suit...", cop_msg = "This coral looks freshly stolen...", cop_title = "Illegal Diving", }, - warning = { - oxygen_one_minute = "You have less than one minute of air remaining!", - oxygen_running_out = "Your air tank is running out of air!", - }, } Lang = Lang or Locale:new({ diff --git a/server/suit.lua b/server/suit.lua deleted file mode 100644 index 524db63..0000000 --- a/server/suit.lua +++ /dev/null @@ -1,11 +0,0 @@ -exports.qbx_core:CreateUseableItem("diving_gear", function(source) - TriggerClientEvent("qb-diving:client:UseGear", source) -end) - -exports.qbx_core:CreateUseableItem("diving_fill", function(source) - TriggerClientEvent("qb-diving:client:setoxygenlevel", source) -end) - -RegisterNetEvent('qb-diving:server:removeItemAfterFill', function() - exports.ox_inventory:RemoveItem(source, 'diving_fill', 1) -end) \ No newline at end of file