Skip to content

Commit

Permalink
Merge pull request #100 from t0r3tto/main
Browse files Browse the repository at this point in the history
feat/fix: RemoveDivingGear config option + fixed negative DrawText when bottle empty...
  • Loading branch information
GhzGarage authored Jun 10, 2024
2 parents fe55cfa + 1b9b322 commit 4911e08
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 106 deletions.
176 changes: 83 additions & 93 deletions client/main.lua
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
local QBCore = exports['qb-core']:GetCoreObject()
local isLoggedIn = LocalPlayer.state['isLoggedIn']
local zones = {}
local currentArea = 0
local Zones = {}
local CurrentArea = 0
local inSellerZone = false
local iswearingsuit = false
local oxgenlevell = 0
local isWearingSuit = false
local OxygenLevel = 0

local currentDivingLocation = {
local CurrentDivingLocation = {
area = 0,
blip = {
radius = nil,
label = nil
}
}
local currentGear = {

local CurrentGear = {
mask = 0,
tank = 0,
oxygen = 0,
Expand All @@ -30,28 +31,30 @@ local function callCops()
TriggerServerEvent('qb-diving:server:CallCops', coords)
end
end

local function deleteGear()
if currentGear.mask ~= 0 then
DetachEntity(currentGear.mask, 0, 1)
DeleteEntity(currentGear.mask)
currentGear.mask = 0
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, 0, 1)
DeleteEntity(currentGear.tank)
currentGear.tank = 0
if CurrentGear.tank ~= 0 then
DetachEntity(CurrentGear.tank, false, true)
DeleteEntity(CurrentGear.tank)
CurrentGear.tank = 0
end

end

local function gearAnim()
RequestAnimDict("clothingshirt")
while not HasAnimDictLoaded("clothingshirt") do
Wait(0)
end
TaskPlayAnim(PlayerPedId(), "clothingshirt", "try_shirt_positive_d", 8.0, 1.0, -1, 49, 0, 0, 0, 0)
end

local function takeCoral(coral)
if Config.CoralLocations[currentDivingLocation.area].coords.Coral[coral].PickedUp then return end
if Config.CoralLocations[CurrentDivingLocation.area].coords.Coral[coral].PickedUp then return end
local ped = PlayerPedId()
local times = math.random(2, 5)
if math.random() > Config.CopsChance then callCops() end
Expand All @@ -66,32 +69,33 @@ local function takeCoral(coral)
anim = "plant_floor",
flags = 16,
}, {}, {}, function() -- Done
Config.CoralLocations[currentDivingLocation.area].coords.Coral[coral].PickedUp = true
TriggerServerEvent('qb-diving:server:TakeCoral', currentDivingLocation.area, coral, true)
Config.CoralLocations[CurrentDivingLocation.area].coords.Coral[coral].PickedUp = true
TriggerServerEvent('qb-diving:server:TakeCoral', CurrentDivingLocation.area, coral, true)
ClearPedTasks(ped)
FreezeEntityPosition(ped, false)
end, function() -- Cancel
ClearPedTasks(ped)
FreezeEntityPosition(ped, false)
end)
end

local function setDivingLocation(divingLocation)
if currentDivingLocation.area ~= 0 then
for k in pairs(Config.CoralLocations[currentDivingLocation.area].coords.Coral) do
if CurrentDivingLocation.area ~= 0 then
for k in pairs(Config.CoralLocations[CurrentDivingLocation.area].coords.Coral) do
if Config.UseTarget then
exports['qb-target']:RemoveZone(k)
else
if next(zones) then zones[k]:destroy() end
if next(Zones) then Zones[k]:destroy() end
end
end
end
currentDivingLocation.area = divingLocation
for _, blip in pairs(currentDivingLocation.blip) do if blip then RemoveBlip(blip) end end
local radiusBlip = AddBlipForRadius(Config.CoralLocations[currentDivingLocation.area].coords.Area, 100.0)
CurrentDivingLocation.area = divingLocation
for _, blip in pairs(CurrentDivingLocation.blip) do if blip then RemoveBlip(blip) end end
local radiusBlip = AddBlipForRadius(Config.CoralLocations[CurrentDivingLocation.area].coords.Area, 100.0)
SetBlipRotation(radiusBlip, 0)
SetBlipColour(radiusBlip, 47)
currentDivingLocation.blip.radius = radiusBlip
local labelBlip = AddBlipForCoord(Config.CoralLocations[currentDivingLocation.area].coords.Area)
CurrentDivingLocation.blip.radius = radiusBlip
local labelBlip = AddBlipForCoord(Config.CoralLocations[CurrentDivingLocation.area].coords.Area)
SetBlipSprite(labelBlip, 597)
SetBlipDisplay(labelBlip, 4)
SetBlipScale(labelBlip, 0.7)
Expand All @@ -100,8 +104,8 @@ local function setDivingLocation(divingLocation)
BeginTextCommandSetBlipName('STRING')
AddTextComponentSubstringPlayerName(Lang:t("info.diving_area"))
EndTextCommandSetBlipName(labelBlip)
currentDivingLocation.blip.label = labelBlip
for k, v in pairs(Config.CoralLocations[currentDivingLocation.area].coords.Coral) do
CurrentDivingLocation.blip.label = labelBlip
for k, v in pairs(Config.CoralLocations[CurrentDivingLocation.area].coords.Coral) do
if Config.UseTarget then
exports['qb-target']:AddBoxZone('diving_coral_zone_'..k, v.coords, v.length, v.width, {
name = 'diving_coral_zone_'..k,
Expand All @@ -122,19 +126,19 @@ local function setDivingLocation(divingLocation)
distance = 2.0
})
else
zones[k] = BoxZone:Create(v.coords, v.length, v.width, {
Zones[k] = BoxZone:Create(v.coords, v.length, v.width, {
name = 'diving_coral_zone_'..k,
heading = v.heading,
debugPoly = false,
minZ = v.coords.z - 3,
maxZ = v.coords.z + 2
})
zones[k]:onPlayerInOut(function(inside)
Zones[k]:onPlayerInOut(function(inside)
if inside then
currentArea = k
CurrentArea = k
exports['qb-core']:DrawText(Lang:t("info.collect_coral_dt"))
else
currentArea = 0
CurrentArea = 0
exports['qb-core']:HideText()
end
end)
Expand All @@ -160,7 +164,7 @@ end
local function createSeller()
for i = 1, #Config.SellLocations do
local current = Config.SellLocations[i]
current.model = type(current.model) == 'string' and GetHashKey(current.model) or current.model
current.model = type(current.model) == 'string' and joaat(current.model) or current.model
RequestModel(current.model)
while not HasModelLoaded(current.model) do
Wait(0)
Expand Down Expand Up @@ -254,18 +258,19 @@ RegisterNetEvent('qb-diving:client:CallCops', function(coords, msg)
end
end)

RegisterNetEvent("qb-diving:client:setoxygenlevel", function()
if oxgenlevell == 0 then
oxgenlevell = Config.oxygenlevel -- oxygenlevel
RegisterNetEvent("qb-diving:client:SetOxygenLevel", function()
if OxygenLevel == 0 then
OxygenLevel = Config.OxygenLevel -- oxygenlevel
QBCore.Functions.Notify(Lang:t("success.tube_filled"), 'success')
TriggerServerEvent('qb-diving:server:removeItemAfterFill')
else
QBCore.Functions.Notify(Lang:t("error.oxygenlevel", {oxygenlevel = oxgenlevell}), 'error')
QBCore.Functions.Notify(Lang:t("error.oxygenlevel", {oxygenlevel = OxygenLevel}), 'error')
end
end)

function DrawText2(text)
SetTextFont(4)
SetTextProportional(1)
SetTextProportional(true)
SetTextScale(0.0, 0.45)
SetTextDropshadow(1, 0, 0, 0, 255)
SetTextEdge(1, 0, 0, 0, 255)
Expand All @@ -278,10 +283,10 @@ end

RegisterNetEvent('qb-diving:client:UseGear', function()
local ped = PlayerPedId()
if iswearingsuit == false then
if oxgenlevell > 0 then
iswearingsuit = true
if not IsPedSwimming(ped) and not IsPedInAnyVehicle(ped) then
if isWearingSuit == false then
if OxygenLevel > 0 then
isWearingSuit = true
if not IsPedSwimming(ped) and not IsPedInAnyVehicle(ped, false) then
gearAnim()
QBCore.Functions.Progressbar("equip_gear", Lang:t("info.put_suit"), 5000, false, true, {}, {}, {}, {},
function() -- Done
Expand All @@ -292,54 +297,38 @@ RegisterNetEvent('qb-diving:client:UseGear', function()
while not HasModelLoaded(tankModel) do
Wait(0)
end
currentGear.tank = CreateObject(tankModel, 1.0, 1.0, 1.0, 1, 1, 0)
CurrentGear.tank = CreateObject(tankModel, 1.0, 1.0, 1.0, 1, 1, 0)
local bone1 = GetPedBoneIndex(ped, 24818)
AttachEntityToEntity(currentGear.tank, ped, bone1, -0.25, -0.25, 0.0, 180.0, 90.0, 0.0, 1, 1, 0,
0, 2, 1)
AttachEntityToEntity(CurrentGear.tank, ped, bone1, -0.25, -0.25, 0.0, 180.0, 90.0, 0.0, 1, 1, 0, 0, 2, 1)

RequestModel(maskModel)
while not HasModelLoaded(maskModel) do
Wait(0)
end
currentGear.mask = CreateObject(maskModel, 1.0, 1.0, 1.0, 1, 1, 0)
CurrentGear.mask = CreateObject(maskModel, 1.0, 1.0, 1.0, 1, 1, 0)
local bone2 = GetPedBoneIndex(ped, 12844)
AttachEntityToEntity(currentGear.mask, ped, bone2, 0.0, 0.0, 0.0, 180.0, 90.0, 0.0, 1, 1, 0, 0, 2
, 1)
AttachEntityToEntity(CurrentGear.mask, ped, bone2, 0.0, 0.0, 0.0, 180.0, 90.0, 0.0, 1, 1, 0, 0, 2, 1)
SetEnableScuba(ped, true)
SetPedMaxTimeUnderwater(ped, 2000.00)
currentGear.enabled = true
CurrentGear.enabled = true
ClearPedTasks(ped)
TriggerServerEvent("InteractSound_SV:PlayOnSource", "breathdivingsuit", 0.25)
oxgenlevell = oxgenlevell
Citizen.CreateThread(function()
while currentGear.enabled do
OxygenLevel = OxygenLevel
CreateThread(function()
while CurrentGear.enabled do
if IsPedSwimmingUnderWater(PlayerPedId()) then
oxgenlevell = oxgenlevell - 1
if oxgenlevell == 90 then
TriggerServerEvent("InteractSound_SV:PlayOnSource", "breathdivingsuit", 0.25)
elseif oxgenlevell == 80 then
TriggerServerEvent("InteractSound_SV:PlayOnSource", "breathdivingsuit", 0.25)
elseif oxgenlevell == 70 then
TriggerServerEvent("InteractSound_SV:PlayOnSource", "breathdivingsuit", 0.25)
elseif oxgenlevell == 60 then
TriggerServerEvent("InteractSound_SV:PlayOnSource", "breathdivingsuit", 0.25)
elseif oxgenlevell == 50 then
TriggerServerEvent("InteractSound_SV:PlayOnSource", "breathdivingsuit", 0.25)
elseif oxgenlevell == 40 then
TriggerServerEvent("InteractSound_SV:PlayOnSource", "breathdivingsuit", 0.25)
elseif oxgenlevell == 30 then
TriggerServerEvent("InteractSound_SV:PlayOnSource", "breathdivingsuit", 0.25)
elseif oxgenlevell == 20 then
TriggerServerEvent("InteractSound_SV:PlayOnSource", "breathdivingsuit", 0.25)
elseif oxgenlevell == 10 then
OxygenLevel = OxygenLevel - 1

if OxygenLevel % 10 == 0 and OxygenLevel <= 90 and OxygenLevel > 0 then
TriggerServerEvent("InteractSound_SV:PlayOnSource", "breathdivingsuit", 0.25)
elseif oxgenlevell == 0 then
-- deleteGear()
elseif OxygenLevel == 0 then
if Config.RemoveDivingGear then deleteGear() end
SetEnableScuba(ped, false)
SetPedMaxTimeUnderwater(ped, 1.00)
currentGear.enabled = false
iswearingsuit = false
CurrentGear.enabled = false
isWearingSuit = false
TriggerServerEvent("InteractSound_SV:PlayOnSource", nil, 0.25)
return
end
end
Wait(1000)
Expand All @@ -352,20 +341,19 @@ RegisterNetEvent('qb-diving:client:UseGear', function()
else
QBCore.Functions.Notify(Lang:t("error.need_otube"), 'error')
end
elseif iswearingsuit == true then
elseif isWearingSuit == true then
gearAnim()
QBCore.Functions.Progressbar("remove_gear", Lang:t("info.pullout_suit"), 5000, false, true, {}, {}, {}, {},
function() -- Done
SetEnableScuba(ped, false)
SetPedMaxTimeUnderwater(ped, 50.00)
currentGear.enabled = false
ClearPedTasks(ped)
deleteGear()
QBCore.Functions.Notify(Lang:t("success.took_out"))
TriggerServerEvent("InteractSound_SV:PlayOnSource", nil, 0.25)
iswearingsuit = false
oxgenlevell = oxgenlevell
end)
QBCore.Functions.Progressbar("remove_gear", Lang:t("info.pullout_suit"), 5000, false, true, {}, {}, {}, {}, function() -- Done
SetEnableScuba(ped, false)
SetPedMaxTimeUnderwater(ped, 50.00)
CurrentGear.enabled = false
ClearPedTasks(ped)
deleteGear()
QBCore.Functions.Notify(Lang:t("success.took_out"))
TriggerServerEvent("InteractSound_SV:PlayOnSource", nil, 0.25)
isWearingSuit = false
OxygenLevel = OxygenLevel
end)
end
end)

Expand All @@ -379,14 +367,16 @@ CreateThread(function()
createSeller()
end)
end

if Config.UseTarget then return end

while true do
local sleep = 1000
if isLoggedIn then
if currentArea ~= 0 then
if CurrentArea ~= 0 then
sleep = 0
if IsControlJustPressed(0, 51) then -- E
takeCoral(currentArea)
takeCoral(CurrentArea)
exports['qb-core']:KeyPressed()
Wait(500)
exports['qb-core']:HideText()
Expand All @@ -412,10 +402,10 @@ end)
CreateThread(function()
while true do
Wait(0)
if currentGear.enabled == true and iswearingsuit == true then
if IsPedSwimmingUnderWater(PlayerPedId()) then
DrawText2(oxgenlevell..'')
if CurrentGear.enabled == true and isWearingSuit == true and OxygenLevel > 0 then
if IsPedSwimmingUnderWater(PlayerPedId()) then
DrawText2(OxygenLevel..'')
end
end
end
end
end)
7 changes: 5 additions & 2 deletions config.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
Config = Config or {}
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 = 200 -- this is oxygen level you can change this number as you like
Config.OxygenLevel = 200 -- this is oxygen level you can change this number as you like
Config.RemoveDivingGear = false -- Whether or not to remove the diving gear when empty

Config.CoralLocations = {
[1] = {
label = "This is Location 1",
Expand Down Expand Up @@ -284,6 +286,7 @@ Config.BonusTiers = {
maxBonus = 20
}
}

Config.SellLocations = {
[1] = {
coords = vector4(-1684.13, -1068.91, 13.15, 100.0),
Expand All @@ -293,4 +296,4 @@ Config.SellLocations = {
width = 3
}
}
}
}
2 changes: 1 addition & 1 deletion locales/en.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ local Translations = {
["not_wearing"] = "You are not wearing a diving gear ..",
["no_coral"] = "You don't have any coral to sell..",
["not_standing_up"] = "You need to be standing up to put on the diving gear",
["need_otube"] = "you need oxygen tube",
["need_otube"] = "You need an oxygen tube to fill your empty diving gear",
["oxygenlevel"] = 'the gear level is %{oxygenlevel} must be 0%'
},
success = {
Expand Down
Loading

0 comments on commit 4911e08

Please sign in to comment.