Skip to content

Commit

Permalink
fix: Fixed coral counting issues
Browse files Browse the repository at this point in the history
When harvesting coral the amount harvested wasn't increasing and a new diving area would never be generated.
  • Loading branch information
zozomanx authored Dec 5, 2024
1 parent b2f8798 commit d7af6a4
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ RegisterNetEvent('qbx_diving:server:sellCoral', function()
end
end
if payout == 0 then
return exports.qbx_core:Notify(locale('error.no_coral'), 'error')
return lib.notify(src, {
type = 'error',
description = 'No coral to sell!',
})
end
player.Functions.AddMoney('cash', payout, 'sold-coral')
end)
Expand All @@ -53,6 +56,15 @@ local function getNewLocation()
end

RegisterNetEvent('qbx_diving:server:takeCoral', function(coralIndex)
local function countTableKeys(tbl)
local count = 0
for _ in pairs(tbl) do
count = count + 1
end
return count
end

print('coralIndex is ', coralIndex)
if pickedUpCoralIndexes[coralIndex] then return end
local src = source
local coralType = config.coralTypes[math.random(1, #config.coralTypes)]
Expand All @@ -61,8 +73,9 @@ RegisterNetEvent('qbx_diving:server:takeCoral', function(coralIndex)
exports.ox_inventory:AddItem(src, coralType.item, amount)
pickedUpCoralIndexes[coralIndex] = true
TriggerClientEvent('qbx_diving:client:coralTaken', -1, coralIndex)
TriggerEvent('qbx_diving:server:coralTaken', sharedConfig.coralLocations[currentAreaIndex].corals[coralIndex].coords)
if #pickedUpCoralIndexes == sharedConfig.coralLocations[currentAreaIndex].maxHarvestAmount then
TriggerEvent('qbx_diving:server:coralTaken', sharedConfig.coralLocations[currentAreaIndex].corals[coralIndex].coords)

if countTableKeys(pickedUpCoralIndexes) == sharedConfig.coralLocations[currentAreaIndex].maxHarvestAmount then
pickedUpCoralIndexes = {}
currentAreaIndex = getNewLocation()
TriggerClientEvent('qbx_diving:client:newLocationSet', -1, currentAreaIndex)
Expand Down

0 comments on commit d7af6a4

Please sign in to comment.