From c6ecf784f46d0a55ca74b1e93c3ebc9286a5d2fe Mon Sep 17 00:00:00 2001 From: Madd Date: Mon, 7 Apr 2025 15:37:10 +0930 Subject: [PATCH 1/4] Add multi location to mines --- client/mining.lua | 117 ++++++++++------- config/shared.lua | 327 +++++++++++++++++++++++++++------------------- server/mining.lua | 28 ++-- 3 files changed, 283 insertions(+), 189 deletions(-) diff --git a/client/mining.lua b/client/mining.lua index 7ab3b0e..c85cf36 100644 --- a/client/mining.lua +++ b/client/mining.lua @@ -1,27 +1,28 @@ -- Initialize config(s) -local shared = require 'config.shared' -local client = require 'config.client' -local icons = require 'config.icons' +local shared = require 'config.shared' +local client = require 'config.client' +local icons = require 'config.icons' -- Initialize table to store ores -local ores = {} +local ores = {} -- Initialize variable to store inside mine state -local inside = false +local inside = false +local insideMine = nil -- Localize export -local mining = exports.lation_mining +local mining = exports.lation_mining -- Mine an ore --- @param zoneId number --- @param oreId number -local function mineOre(zoneId, oreId) +local function mineOre(mineId, zoneId, oreId) if not zoneId or not oreId then return end - local zone = shared.mining.zones[zoneId] + local zone = shared.mining[mineId].zones[zoneId] if not zone then return end - local ore = ores[zoneId] and ores[zoneId][oreId] + local ore = ores[mineId][zoneId] and ores[mineId][zoneId][oreId] if not ore or not DoesEntityExist(ore.entity) then return end local level = mining:GetPlayerData('level') @@ -51,7 +52,7 @@ local function mineOre(zoneId, oreId) end local hour = GetClockHours() - local hours = shared.mining.hours + local hours = shared.mining[mineId].hours if hour < hours.min or hour > hours.max then ShowNotification(locale('notify.nighttime'), 'error') return @@ -64,18 +65,18 @@ local function mineOre(zoneId, oreId) if ProgressBar(anim) then DeleteEntity(ore.entity) - ores[zoneId][oreId] = { respawn = GetGameTimer() + zone.respawn } - TriggerServerEvent('lation_mining:minedore', zoneId, oreId) + ores[mineId][zoneId][oreId] = { respawn = GetGameTimer() + zone.respawn } + TriggerServerEvent('lation_mining:minedore', mineId, zoneId, oreId) end end -- Spawn an ore --- @param zoneId number --- @param oreId number -local function spawnOre(zoneId, oreId) - if not zoneId or not oreId then return end +local function spawnOre(mineId, zoneId, oreId) + if not mineId or not zoneId or not oreId then return end - local zone = shared.mining.zones[zoneId] + local zone = shared.mining[mineId].zones[zoneId] if not zone then return end local ore = zone.ores[oreId] @@ -85,12 +86,15 @@ local function spawnOre(zoneId, oreId) local model = models[math.random(#models)] lib.requestModel(model) while not HasModelLoaded(model) do Wait(0) end - local entity = CreateObject(model, ore.x, ore.y, ore.z, false, false, false) + local groundFound, groundZ = GetGroundZFor_3dCoord(ore.x, ore.y, ore.z, false) + local oreZ = groundFound and groundZ or ore.z + local entity = CreateObject(model, ore.x, ore.y, oreZ, false, false, false) + print(ore.x, ore.y, ore.z, oreZ, groundFound) PlaceObjectOnGroundProperly(entity) FreezeEntityPosition(entity, true) AddTargetEntity(entity, { { - name = zoneId .. oreId, + name = mineId .. zoneId .. oreId, label = locale('target.mine-ore'), icon = icons.mine, iconColor = icons.mine_color, @@ -99,40 +103,48 @@ local function spawnOre(zoneId, oreId) return not IsPedInAnyVehicle(cache.ped, true) end, onSelect = function() - mineOre(zoneId, oreId) + mineOre(mineId, zoneId, oreId) end, action = function() - mineOre(zoneId, oreId) + mineOre(mineId, zoneId, oreId) end } }) - ores[zoneId][oreId] = { entity = entity, respawn = nil } + ores[mineId][zoneId][oreId] = { entity = entity, respawn = nil } end -- Setup on mine enter -local function enterMine() +local function enterMine(mineId) inside = not inside - for zoneId, zone in pairs(shared.mining.zones) do - ores[zoneId] = ores[zoneId] or {} + insideMine = mineId + for zoneId, zone in pairs(shared.mining[mineId].zones) do + ores[mineId] = ores[mineId] or {} + ores[mineId][zoneId] = ores[mineId][zoneId] or {} for oreId, _ in pairs(zone.ores) do - spawnOre(zoneId, oreId) + spawnOre(mineId, zoneId, oreId) end end end -- Cleanup on mine exit -local function exitMine() +local function exitMine(mineId) inside = not inside - for zoneId, oreData in pairs(ores) do - for _, data in pairs(oreData) do - if data.entity and DoesEntityExist(data.entity) then - DeleteEntity(data.entity) + insideMine = nil + for id, data in pairs(ores) do + if id == mineId then + for zoneId, oreData in pairs(data) do + for _, data in pairs(oreData) do + if data.entity and DoesEntityExist(data.entity) then + DeleteEntity(data.entity) + end + end + ores[mineId][zoneId] = nil end + ores[mineId] = nil end - ores[zoneId] = nil end - for _, data in pairs(shared.mining.zones) do + for _, data in pairs(shared.mining[mineId].zones) do for _, model in pairs(data.models) do SetModelAsNoLongerNeeded(model) end @@ -142,11 +154,11 @@ end -- Ore respawn management thread CreateThread(function() while true do - if inside then - for zoneId, oreData in pairs(ores) do + if inside and insideMine then + for zoneId, oreData in pairs(ores[insideMine]) do for oreId, data in pairs(oreData) do if data.respawn and GetGameTimer() >= data.respawn then - spawnOre(zoneId, oreId) + spawnOre(insideMine, zoneId, oreId) end end end @@ -159,25 +171,36 @@ end) -- Setup on player loaded AddEventHandler('lation_mining:onPlayerLoaded', function() - lib.zones.sphere({ - coords = shared.mining.center, - radius = 400, - onEnter = enterMine, - onExit = exitMine, - debug = shared.setup.debug - }) + for mineId, data in pairs(shared.mining) do + lib.zones.sphere({ + coords = data.center, + radius = 400, + onEnter = function() + Wait(500) + enterMine(mineId) + end, + onExit = function() + Wait(500) + exitMine(mineId) + end, + debug = shared.setup.debug + }) + end end) -- Cleanup on resource stop --- @param resourceName string AddEventHandler('onResourceStop', function(resourceName) if GetCurrentResourceName() ~= resourceName then return end - for zoneId, oreData in pairs(ores) do - for _, data in pairs(oreData) do - if data.entity and DoesEntityExist(data.entity) then - DeleteEntity(data.entity) + for mineId, oresData in pairs(ores) do + for zoneId, oreData in pairs(oresData) do + for _, data in pairs(oreData) do + if data.entity and DoesEntityExist(data.entity) then + DeleteEntity(data.entity) + end end + ores[mineId][zoneId] = nil end - ores[zoneId] = nil + ores[mineId] = nil end -end) \ No newline at end of file +end) diff --git a/config/shared.lua b/config/shared.lua index a7aa80c..e554ac4 100644 --- a/config/shared.lua +++ b/config/shared.lua @@ -131,7 +131,7 @@ return { [4] = { item = 'ls_silver_ore', price = 10, icon = 'hand-holding-dollar' }, [5] = { item = 'ls_gold_ore', price = 20, icon = 'hand-holding-dollar' }, [6] = { item = 'ls_copper_ingot', price = 35, icon = 'hand-holding-dollar' }, - [7] = { item = 'ls_iron_ingot', price = 60, icon = 'hand-holding-dollar'}, + [7] = { item = 'ls_iron_ingot', price = 60, icon = 'hand-holding-dollar' }, [8] = { item = 'ls_silver_ingot', price = 100, icon = 'hand-holding-dollar' }, [9] = { item = 'ls_gold_ingot', price = 175, icon = 'hand-holding-dollar' }, -- Add or remove items as you wish @@ -139,10 +139,10 @@ return { }, -- Manage blip settings if desired blip = { - enable = true, -- Enable or disable the blip for this shop - sprite = 618, -- Sprite ID (https://docs.fivem.net/docs/game-references/blips/) - color = 5, -- Color (https://docs.fivem.net/docs/game-references/blips/#blip-colors) - scale = 0.9, -- Size/scale + enable = true, -- Enable or disable the blip for this shop + sprite = 618, -- Sprite ID (https://docs.fivem.net/docs/game-references/blips/) + color = 5, -- Color (https://docs.fivem.net/docs/game-references/blips/#blip-colors) + scale = 0.9, -- Size/scale label = 'The Mines' -- Label } }, @@ -152,131 +152,196 @@ return { ---------------------------------------------- mining = { - -- The center-most coords of the entire mining area - center = vec3(2946.6995, 2792.2271, 40.5708), - -- What hours is mining allowed to happen? - -- By default, it's 24/7, but for example - if you wish to only - -- Allow mining during the day, set hours = { min = 6, max = 20 } - hours = { min = 0, max = 24 }, - -- Build individual mining areas with specific ores - zones = { - [1] = { - -- The models spawned in this area - -- You can use one or more models, it will select at random for each ore spawn - models = { 'prop_rock_3_b', 'prop_rock_3_d', 'prop_rock_3_f' }, - -- What level must the player be to mine these? - level = 1, - -- How long it takes to mine these ores (in milliseconds) - duration = { min = 2500, max = 2500 }, - -- A table containing all possible rewards from these rocks - -- item: the item spawn name - -- min: the minimum amount to reward - -- max: the maximum amount to reward - -- chance: optional percentage chance variable - -- (if no chance is set, it will be considered 100%) - reward = { - { item = 'ls_copper_ore', min = 1, max = 2 }, - -- { item = 'example_rare_item', min = 1, max = 1, chance = 5 }, - -- Add or remove items as desired following the format above + [1] = { + -- The center-most coords of the entire mining area + center = vec3(2946.6995, 2792.2271, 40.5708), + -- What hours is mining allowed to happen? + -- By default, it's 24/7, but for example - if you wish to only + -- Allow mining during the day, set hours = { min = 6, max = 20 } + hours = { min = 0, max = 24 }, + -- Build individual mining areas with specific ores + zones = { + [1] = { + -- The models spawned in this area + -- You can use one or more models, it will select at random for each ore spawn + models = { 'prop_rock_3_b', 'prop_rock_3_d', 'prop_rock_3_f' }, + -- What level must the player be to mine these? + level = 1, + -- How long it takes to mine these ores (in milliseconds) + duration = { min = 2500, max = 2500 }, + -- A table containing all possible rewards from these rocks + -- item: the item spawn name + -- min: the minimum amount to reward + -- max: the maximum amount to reward + -- chance: optional percentage chance variable + -- (if no chance is set, it will be considered 100%) + reward = { + { item = 'ls_copper_ore', min = 1, max = 2 }, + -- { item = 'example_rare_item', min = 1, max = 1, chance = 5 }, + -- Add or remove items as desired following the format above + }, + -- How much XP is given for each (x1) ore mined? + xp = { min = 1, max = 3 }, + -- How long after being mined do these ores respawn (in milliseconds) + respawn = 25000, + -- The coordinates these ores spawn at + ores = { + [1] = vec3(2949.8770, 2851.0256, 48.3509), + [2] = vec3(2955.0566, 2850.1597, 47.6026), + [3] = vec3(2959.4751, 2848.0740, 46.8103), + [4] = vec3(2952.2109, 2847.9136, 47.2530), + [5] = vec3(2956.3149, 2845.9241, 46.5613), + [6] = vec3(2947.4197, 2848.0171, 47.7500), + [7] = vec3(2961.4399, 2844.1255, 46.0608), + } }, - -- How much XP is given for each (x1) ore mined? - xp = { min = 1, max = 3 }, - -- How long after being mined do these ores respawn (in milliseconds) - respawn = 25000, - -- The coordinates these ores spawn at - ores = { - [1] = vec3(2949.8770, 2851.0256, 48.3509), - [2] = vec3(2955.0566, 2850.1597, 47.6026), - [3] = vec3(2959.4751, 2848.0740, 46.8103), - [4] = vec3(2952.2109, 2847.9136, 47.2530), - [5] = vec3(2956.3149, 2845.9241, 46.5613), - [6] = vec3(2947.4197, 2848.0171, 47.7500), - [7] = vec3(2961.4399, 2844.1255, 46.0608), - } - }, - [2] = { - models = { 'prop_rock_3_b', 'prop_rock_3_d', 'prop_rock_3_f' }, - level = 1, - duration = { min = 2500, max = 2500 }, - reward = { - { item = 'ls_coal_ore', min = 1, max = 2 }, + [2] = { + models = { 'prop_rock_3_b', 'prop_rock_3_d', 'prop_rock_3_f' }, + level = 1, + duration = { min = 2500, max = 2500 }, + reward = { + { item = 'ls_coal_ore', min = 1, max = 2 }, + }, + xp = { min = 1, max = 3 }, + respawn = 25000, + ores = { + [1] = vec3(2938.3345, 2808.9683, 42.1674), + [2] = vec3(2930.3652, 2811.0193, 43.4722), + [3] = vec3(2925.0359, 2807.3450, 42.9333), + [4] = vec3(2927.2339, 2799.7976, 41.3330), + [5] = vec3(2930.2278, 2794.4519, 40.6447), + [6] = vec3(2935.8081, 2795.5881, 40.6888), + [7] = vec3(2940.8623, 2800.0393, 40.9543), + [8] = vec3(2935.3396, 2802.2466, 41.2976), + [9] = vec3(2932.2173, 2806.7004, 42.2299), + [10] = vec3(2941.5352, 2805.1804, 41.1859), + } }, - xp = { min = 1, max = 3 }, - respawn = 25000, - ores = { - [1] = vec3(2938.3345, 2808.9683, 42.1674), - [2] = vec3(2930.3652, 2811.0193, 43.4722), - [3] = vec3(2925.0359, 2807.3450, 42.9333), - [4] = vec3(2927.2339, 2799.7976, 41.3330), - [5] = vec3(2930.2278, 2794.4519, 40.6447), - [6] = vec3(2935.8081, 2795.5881, 40.6888), - [7] = vec3(2940.8623, 2800.0393, 40.9543), - [8] = vec3(2935.3396, 2802.2466, 41.2976), - [9] = vec3(2932.2173, 2806.7004, 42.2299), - [10] = vec3(2941.5352, 2805.1804, 41.1859), - } - }, - [3] = { - models = { 'prop_rock_3_b', 'prop_rock_3_d', 'prop_rock_3_f' }, - level = 2, - duration = { min = 7500, max = 7500 }, - reward = { - { item = 'ls_iron_ore', min = 1, max = 2 }, + [3] = { + models = { 'prop_rock_3_b', 'prop_rock_3_d', 'prop_rock_3_f' }, + level = 2, + duration = { min = 7500, max = 7500 }, + reward = { + { item = 'ls_iron_ore', min = 1, max = 2 }, + }, + xp = { min = 2, max = 6 }, + respawn = 45000, + ores = { + [1] = vec3(3027.8311, 2772.1812, 55.4793), + [2] = vec3(3030.8904, 2767.5234, 56.4680), + [3] = vec3(3028.2546, 2764.4390, 56.0667), + [4] = vec3(3030.5837, 2760.3337, 57.4613), + [5] = vec3(3025.9062, 2756.8679, 56.0076), + [6] = vec3(3026.0994, 2751.2605, 57.2785), + [7] = vec3(3020.6831, 2748.7808, 55.5372), + } }, - xp = { min = 2, max = 6 }, - respawn = 45000, - ores = { - [1] = vec3(3027.8311, 2772.1812, 55.4793), - [2] = vec3(3030.8904, 2767.5234, 56.4680), - [3] = vec3(3028.2546, 2764.4390, 56.0667), - [4] = vec3(3030.5837, 2760.3337, 57.4613), - [5] = vec3(3025.9062, 2756.8679, 56.0076), - [6] = vec3(3026.0994, 2751.2605, 57.2785), - [7] = vec3(3020.6831, 2748.7808, 55.5372), - } - }, - [4] = { - models = { 'prop_rock_3_b', 'prop_rock_3_d', 'prop_rock_3_f' }, - level = 3, - duration = { min = 7500, max = 7500 }, - reward = { - { item = 'ls_silver_ore', min = 1, max = 2 }, + [4] = { + models = { 'prop_rock_3_b', 'prop_rock_3_d', 'prop_rock_3_f' }, + level = 3, + duration = { min = 7500, max = 7500 }, + reward = { + { item = 'ls_silver_ore', min = 1, max = 2 }, + }, + xp = { min = 3, max = 9 }, + respawn = 75000, + ores = { + [1] = vec3(2969.4246, 2697.7976, 54.5088), + [2] = vec3(2966.6487, 2694.4221, 54.6609), + [3] = vec3(2962.9324, 2697.2637, 54.6642), + [4] = vec3(2953.2451, 2697.2317, 55.1387), + [5] = vec3(2950.2148, 2700.9580, 54.8590), + } }, - xp = { min = 3, max = 9 }, - respawn = 75000, - ores = { - [1] = vec3(2969.4246, 2697.7976, 54.5088), - [2] = vec3(2966.6487, 2694.4221, 54.6609), - [3] = vec3(2962.9324, 2697.2637, 54.6642), - [4] = vec3(2953.2451, 2697.2317, 55.1387), - [5] = vec3(2950.2148, 2700.9580, 54.8590), - } - }, - [5] = { - models = { 'prop_rock_3_b', 'prop_rock_3_d', 'prop_rock_3_f' }, - level = 4, - duration = { min = 13000, max = 13000 }, - reward = { - { item = 'ls_gold_ore', min = 1, max = 2 }, + [5] = { + models = { 'prop_rock_3_b', 'prop_rock_3_d', 'prop_rock_3_f' }, + level = 4, + duration = { min = 13000, max = 13000 }, + reward = { + { item = 'ls_gold_ore', min = 1, max = 2 }, + }, + xp = { min = 4, max = 12 }, + respawn = 120000, + ores = { + [1] = vec3(3041.3960, 2719.4390, 63.1831), + [2] = vec3(3047.6887, 2717.8809, 62.7571), + [3] = vec3(3045.9670, 2722.4072, 63.1737), + [4] = vec3(3052.4326, 2721.9761, 63.1375), + [5] = vec3(3052.2554, 2728.0950, 63.6344), + [6] = vec3(3058.0610, 2731.1460, 64.6821), + [7] = vec3(3055.9949, 2737.5295, 64.3239), + [8] = vec3(3060.6294, 2741.4951, 64.5270), + [9] = vec3(3058.5295, 2746.5312, 64.3540), + [10] = vec3(3060.2603, 2750.5828, 64.3339), + } }, - xp = { min = 4, max = 12 }, - respawn = 120000, - ores = { - [1] = vec3(3041.3960, 2719.4390, 63.1831), - [2] = vec3(3047.6887, 2717.8809, 62.7571), - [3] = vec3(3045.9670, 2722.4072, 63.1737), - [4] = vec3(3052.4326, 2721.9761, 63.1375), - [5] = vec3(3052.2554, 2728.0950, 63.6344), - [6] = vec3(3058.0610, 2731.1460, 64.6821), - [7] = vec3(3055.9949, 2737.5295, 64.3239), - [8] = vec3(3060.6294, 2741.4951, 64.5270), - [9] = vec3(3058.5295, 2746.5312, 64.3540), - [10] = vec3(3060.2603, 2750.5828, 64.3339), + -- You can add or remove zones as you wish + -- Be sure to follow the same format as above + } + }, + -- You can add or remove mines as you wish but there must always be one + -- Be sure to follow the same format as above + [2] = { -- Example second mine + -- The center-most coords of the entire mining area + center = vec3(-879.82, 2818.85, 13.15), + -- What hours is mining allowed to happen? + -- By default, it's 24/7, but for example - if you wish to only + -- Allow mining during the day, set hours = { min = 6, max = 20 } + hours = { min = 0, max = 24 }, + -- Build individual mining areas with specific ores + zones = { + [1] = { + -- The models spawned in this area + -- You can use one or more models, it will select at random for each ore spawn + models = { 'prop_rock_3_b', 'prop_rock_3_d', 'prop_rock_3_f' }, + -- What level must the player be to mine these? + level = 1, + -- How long it takes to mine these ores (in milliseconds) + duration = { min = 2500, max = 2500 }, + -- A table containing all possible rewards from these rocks + -- item: the item spawn name + -- min: the minimum amount to reward + -- max: the maximum amount to reward + -- chance: optional percentage chance variable + -- (if no chance is set, it will be considered 100%) + reward = { + { item = 'ls_copper_ore', min = 1, max = 2 }, + -- { item = 'example_rare_item', min = 1, max = 1, chance = 5 }, + -- Add or remove items as desired following the format above + }, + -- How much XP is given for each (x1) ore mined? + xp = { min = 1, max = 3 }, + -- How long after being mined do these ores respawn (in milliseconds) + respawn = 25000, + -- The coordinates these ores spawn at + ores = { + [1] = vec3(-879.82, 2818.85, 13.15), + [2] = vec3(-885.82, 2818.85, 13.15), + [3] = vec3(-891.82, 2818.85, 13.15), + [4] = vec3(-897.82, 2818.85, 13.15), + [5] = vec3(-903.82, 2818.85, 13.15), + [6] = vec3(-909.82, 2818.85, 13.15), + [7] = vec3(-915.82, 2818.85, 13.15), + } + }, + [2] = { + models = { 'prop_rock_3_b', 'prop_rock_3_d', 'prop_rock_3_f' }, + level = 2, + duration = { min = 2500, max = 2500 }, + reward = { + { item = 'ls_iron_ore', min = 1, max = 2 }, + }, + xp = { min = 2, max = 4 }, + respawn = 50000, + ores = { + [1] = vec3(-865.21, 2780.07, 11.08), + [2] = vec3(-869.21, 2780.07, 11.08), + [3] = vec3(-873.21, 2780.07, 11.08), + [4] = vec3(-877.21, 2780.07, 11.08), + } } - }, - -- You can add or remove zones as you wish - -- Be sure to follow the same format as above - } + } + }, }, ---------------------------------------------- @@ -304,7 +369,7 @@ return { xp = { min = 3, max = 6 }, -- Ores/items that are required to smelt this required = { - { item = 'ls_coal_ore', quantity = 5 }, + { item = 'ls_coal_ore', quantity = 5 }, { item = 'ls_copper_ore', quantity = 5 }, -- You can add or remove additional items as desired }, @@ -337,7 +402,7 @@ return { max = 10, xp = { min = 5, max = 10 }, required = { - { item = 'ls_coal_ore', quantity = 15 }, + { item = 'ls_coal_ore', quantity = 15 }, { item = 'ls_silver_ore', quantity = 5 }, }, add = { @@ -362,13 +427,13 @@ return { }, -- Manage blip settings if desired blip = { - enable = true, -- Enable or disable the blip for this area - sprite = 648, -- Sprite ID (https://docs.fivem.net/docs/game-references/blips/) - color = 17, -- Color (https://docs.fivem.net/docs/game-references/blips/#blip-colors) - scale = 0.9, -- Size/scale + enable = true, -- Enable or disable the blip for this area + sprite = 648, -- Sprite ID (https://docs.fivem.net/docs/game-references/blips/) + color = 17, -- Color (https://docs.fivem.net/docs/game-references/blips/#blip-colors) + scale = 0.9, -- Size/scale label = 'Smelter' -- Label } } -} \ No newline at end of file +} diff --git a/server/mining.lua b/server/mining.lua index b67ad1f..febad4d 100644 --- a/server/mining.lua +++ b/server/mining.lua @@ -11,19 +11,23 @@ local ores = {} -- Ore has been mined --- @param zoneId number --- @param oreId number -RegisterNetEvent('lation_mining:minedore', function(zoneId, oreId) - if not source or not zoneId or not oreId then return end +RegisterNetEvent('lation_mining:minedore', function(mineId, zoneId, oreId) + if not source or not mineId or not zoneId or not oreId then return end + print('mined ore', mineId, zoneId, oreId, source) local source = source - local zone = shared.mining.zones[zoneId] + local zone = shared.mining[mineId].zones[zoneId] if not zone then return end + print('zone', zone) local ore = zone.ores[oreId] if not ore then return end + print('ore', ore) - ores[zoneId] = ores[zoneId] or {} - ores[zoneId][oreId] = ores[zoneId][oreId] or {} - local status = ores[zoneId][oreId][source] + ores[mineId] = ores[mineId] or {} + ores[mineId][zoneId] = ores[mineId][zoneId] or {} + ores[mineId][zoneId][oreId] = ores[mineId][zoneId][oreId] or {} + local status = ores[mineId][zoneId][oreId][source] if status and status.time and status.time > os.time() then return end local coords = GetEntityCoords(GetPlayerPed(source)) @@ -70,7 +74,7 @@ RegisterNetEvent('lation_mining:minedore', function(zoneId, oreId) local addXP = math.random(zone.xp.min, zone.xp.max) mining:AddPlayerData(source, 'exp', addXP) - ores[zoneId][oreId][source] = { time = os.time() + math.floor(zone.respawn / 1000) } + ores[mineId][zoneId][oreId][source] = { time = os.time() + math.floor(zone.respawn / 1000) } if server.logs.events.mined then local rewards = '' @@ -86,10 +90,12 @@ end) CreateThread(function() while true do if next(ores) then - for zoneId, zoneData in pairs(ores) do - for oreId, status in pairs(zoneData) do - if status.time and status.time <= os.time() then - ores[zoneId][oreId][source] = nil + for mineId, mineData in pairs(ores) do + for zoneId, zoneData in pairs(mineData) do + for oreId, status in pairs(zoneData) do + if status.time and status.time <= os.time() then + ores[mineId][zoneId][oreId][source] = nil + end end end end From 12d96b21d62cce8fa2606e366bef329d9611931b Mon Sep 17 00:00:00 2001 From: Madd Date: Tue, 8 Apr 2025 11:43:40 +0930 Subject: [PATCH 2/4] Store overall mine zones in table --- client/mining.lua | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/client/mining.lua b/client/mining.lua index c85cf36..7df80d0 100644 --- a/client/mining.lua +++ b/client/mining.lua @@ -6,6 +6,9 @@ local icons = require 'config.icons' -- Initialize table to store ores local ores = {} +-- Initialize table to store mines +local mines = {} + -- Initialize variable to store inside mine state local inside = false local insideMine = nil @@ -172,7 +175,7 @@ end) -- Setup on player loaded AddEventHandler('lation_mining:onPlayerLoaded', function() for mineId, data in pairs(shared.mining) do - lib.zones.sphere({ + local zone = lib.zones.sphere({ coords = data.center, radius = 400, onEnter = function() @@ -185,6 +188,7 @@ AddEventHandler('lation_mining:onPlayerLoaded', function() end, debug = shared.setup.debug }) + mines[mineId] = zone end end) @@ -203,4 +207,10 @@ AddEventHandler('onResourceStop', function(resourceName) end ores[mineId] = nil end + for mineId, zone in pairs(mines) do + if zone then + zone:remove() + end + mines[mineId] = nil + end end) From 7dbcdb53dc1f76af11cd299a75cc3f05a3b19539 Mon Sep 17 00:00:00 2001 From: Madd Date: Tue, 8 Apr 2025 12:28:57 +0930 Subject: [PATCH 3/4] remove prints that were used during feature development --- server/mining.lua | 3 --- 1 file changed, 3 deletions(-) diff --git a/server/mining.lua b/server/mining.lua index febad4d..b4e21ec 100644 --- a/server/mining.lua +++ b/server/mining.lua @@ -13,16 +13,13 @@ local ores = {} --- @param oreId number RegisterNetEvent('lation_mining:minedore', function(mineId, zoneId, oreId) if not source or not mineId or not zoneId or not oreId then return end - print('mined ore', mineId, zoneId, oreId, source) local source = source local zone = shared.mining[mineId].zones[zoneId] if not zone then return end - print('zone', zone) local ore = zone.ores[oreId] if not ore then return end - print('ore', ore) ores[mineId] = ores[mineId] or {} ores[mineId][zoneId] = ores[mineId][zoneId] or {} From 25a826de215fc88377a10fb17b2c241e9060af74 Mon Sep 17 00:00:00 2001 From: Madd Date: Mon, 12 May 2025 12:01:01 +0930 Subject: [PATCH 4/4] Cleanup - Remove print --- client/mining.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/client/mining.lua b/client/mining.lua index 7df80d0..1ed98eb 100644 --- a/client/mining.lua +++ b/client/mining.lua @@ -92,7 +92,6 @@ local function spawnOre(mineId, zoneId, oreId) local groundFound, groundZ = GetGroundZFor_3dCoord(ore.x, ore.y, ore.z, false) local oreZ = groundFound and groundZ or ore.z local entity = CreateObject(model, ore.x, ore.y, oreZ, false, false, false) - print(ore.x, ore.y, ore.z, oreZ, groundFound) PlaceObjectOnGroundProperly(entity) FreezeEntityPosition(entity, true) AddTargetEntity(entity, {