Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 59 additions & 36 deletions client/smelting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ local mining = exports.lation_mining
-- Initialize table to store smelting menu
local menu = {}

-- Initialize table to store smelter zones
local smelters = {}

-- Initialize variable to track if player is inside smelting zone
local inside = nil

-- Initialize boolean to track smelting state
local smelting = false

Expand Down Expand Up @@ -106,7 +112,7 @@ local function startSmelting(ingotId, count)
end

smelted += 1
TriggerServerEvent('lation_mining:completesmelt', ingotId)
TriggerServerEvent('lation_mining:completesmelt', ingotId, inside)
end

ClearPedTasks(cache.ped)
Expand Down Expand Up @@ -139,41 +145,58 @@ end)

-- Setup on player loaded
AddEventHandler('lation_mining:onPlayerLoaded', function()
lib.zones.sphere({
coords = shared.smelting.coords,
radius = 200,
onEnter = function()
AddCircleZone({
coords = shared.smelting.coords,
name = 'smelt-zone',
radius = 3,
debug = shared.setup.debug,
options = {
{
name = 'smelt-zone',
label = locale('target.smelt-ore'),
icon = icons.smelt,
iconColor = icons.smelt_color,
distance = 2,
canInteract = function()
if smelting then return false end
return true
end,
onSelect = function()
ShowMenu('smelt-menu')
end,
action = function()
ShowMenu('smelt-menu')
end
for smelterId, coords in pairs(shared.smelting.coords) do
local zone = lib.zones.sphere({
coords = coords,
radius = 15,
onEnter = function()
inside = smelterId
AddCircleZone({
coords = coords,
name = 'smelt-zone'..smelterId,
radius = 3,
debug = shared.setup.debug,
options = {
{
name = 'smelt-zone'..smelterId,
label = locale('target.smelt-ore'),
icon = icons.smelt,
iconColor = icons.smelt_color,
distance = 2,
canInteract = function()
if smelting then return false end
return true
end,
onSelect = function()
ShowMenu('smelt-menu')
end,
action = function()
ShowMenu('smelt-menu')
end
}
}
}
})
end,
onExit = function()
RemoveCircleZone('smelt-zone')
end,
debug = shared.setup.debug
})
})
end,
onExit = function()
inside = nil
RemoveCircleZone('smelt-zone'..smelterId)
end,
debug = shared.setup.debug
})
smelters[smelterId] = zone
createBlip(coords, shared.smelting.blip)
end
buildMenu()
createBlip(shared.smelting.coords, shared.smelting.blip)
end)

-- Cleanup on resource stop
--- @param resourceName string
AddEventHandler('onResourceStop', function(resourceName)
if GetCurrentResourceName() ~= resourceName then return end
for smelterId, zone in pairs(smelters) do
if zone then
zone:remove()
end
smelters[smelterId] = nil
end
end)
4 changes: 3 additions & 1 deletion config/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,9 @@ return {

smelting = {
-- Where do you want the smelter to be?
coords = vec3(1087.6827, -2002.1394, 31.4841),
coords = {
vec3(1087.6827, -2002.1394, 31.4841),
},
-- The types of ingots that can be smelted from ores
ingots = {
[1] = {
Expand Down
8 changes: 5 additions & 3 deletions server/smelting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ local players = {}

-- Complete smelting action
--- @param ingotId number
RegisterNetEvent('lation_mining:completesmelt', function(ingotId)
if not source or not ingotId then return end
RegisterNetEvent('lation_mining:completesmelt', function(ingotId, inside)
if not source or not ingotId or not inside then return end
local source = source

local ingot = shared.smelting.ingots[ingotId]
if not ingot then return end

if not shared.smelting.coords[inside] then return end

local hasItems = true
for _, req in pairs(ingot.required) do
if GetItemCount(source, req.item) < req.quantity then
Expand All @@ -29,7 +31,7 @@ RegisterNetEvent('lation_mining:completesmelt', function(ingotId)
return
end

local dist = #(shared.smelting.coords - GetEntityCoords(GetPlayerPed(source))) <= 15
local dist = #(shared.smelting.coords[inside] - GetEntityCoords(GetPlayerPed(source))) <= 15
if not dist then return end

local canCarry = true
Expand Down