RX Scripts Logo
Smelters

Configurables

All config & open sourced files included within this script.

Config Files

--[[
BY RX Scripts © rxscripts.xyz
--]]

Config.SaveInterval = 60 -- How often to save the smelters to the database (in seconds)

Config.Smelters = {
    ["Furnace"] = {
        label = "Furnace",
        prop = "furnacesmall", -- Global prop to access the smelter
        slots = 4, -- Material input/output slots
        smeltTimer = 3, -- Seconds to wait before smelting everything once
        fuel = { -- As long as the 'from' item and amount is inside the machine, it can be turned on
            from  = { item = "wood", amount = 1 },
        },
        smeltings = {
            {
                from = { item = "copper_ore", amount = 1 },
                to = { item = "copper_ingot", amount = 3 },
            },
            {
                from = { item = "iron_ore", amount = 1 },
                to = { item = "iron_ingot", amount = 3 },
            },
            {
                from = { item = "silver_ore", amount = 1 },
                to = { item = "silver_ingot", amount = 3 },
            },
            {
                from = { item = "gold_ore", amount = 1 },
                to = { item = "gold_ingot", amount = 3 },
            },
            {
                from = { item = "platinum_ore", amount = 1 },
                to = { item = "platinum_ingot", amount = 3 },
            },
            {
                from = { item = "titanium_ore", amount = 1 },
                to = { item = "titanium_ingot", amount = 3 },
            },
            {
                from = { item = "mithril_ore", amount = 1 },
                to = { item = "mithril_ingot", amount = 3 },
            },
            {
                from = { item = "adamantium_ore", amount = 1 },
                to = { item = "adamantium_ingot", amount = 3 },
            },
        },
        locations = { -- Locations to spawn a smelter on server start
            vector4(1879.4086, 281.6312, 163.2741, 240.4952),
        },
        placeable = {
            enabled = true, -- If you want to allow players to place smelters
            item = "furnace", -- Item to place a smelter
            pickup = {
                enabled = true, -- If you want to allow players to pick up smelters
                placerOnly = true, -- If you want only the placer to be able to pick up the smelter
                returnItem = true, -- If you want to return the item to the player after picking up the smelter
            }
        },
    },
    ["Large Furnace"] = {
        label = "Large Furnace",
        prop = "diamond_furnace_big", -- Global prop to access the smelter
        slots = 6, -- Material input/output slots
        smeltTimer = 3, -- Seconds to wait before smelting everything once
        fuel = { -- As long as the 'from' item and amount is inside the machine, it can be turned on
            from  = { item = "wood", amount = 1 },
        },
        smeltings = {
            {
                from = { item = "copper_ore", amount = 1 },
                to = { item = "copper_ingot", amount = 3 },
            },
            {
                from = { item = "iron_ore", amount = 1 },
                to = { item = "iron_ingot", amount = 3 },
            },
            {
                from = { item = "silver_ore", amount = 1 },
                to = { item = "silver_ingot", amount = 3 },
            },
            {
                from = { item = "gold_ore", amount = 1 },
                to = { item = "gold_ingot", amount = 3 },
            },
            {
                from = { item = "platinum_ore", amount = 1 },
                to = { item = "platinum_ingot", amount = 3 },
            },
            {
                from = { item = "titanium_ore", amount = 1 },
                to = { item = "titanium_ingot", amount = 3 },
            },
            {
                from = { item = "mithril_ore", amount = 1 },
                to = { item = "mithril_ingot", amount = 3 },
            },
            {
                from = { item = "adamantium_ore", amount = 1 },
                to = { item = "adamantium_ingot", amount = 3 },
            },
        },
        locations = { -- Locations to spawn a smelter on server start
            vector4(1880.8346, 284.4971, 163.2741, 238.1256),
        },
        placeable = {
            enabled = true, -- If you want to allow players to place smelters
            item = "large_furnace", -- Item to place a smelter
            pickup = {
                enabled = true, -- If you want to allow players to pick up smelters
                placerOnly = true, -- If you want only the placer to be able to pick up the smelter
                returnItem = true, -- If you want to return the item to the player after picking up the smelter
            }
        },
    },
    ["BBQ"] = {
        label = "BBQ Grill",
        prop = "bbqrustys", -- Global prop to access the smelter
        slots = 3, -- Input/output slots
        smeltTimer = 3, -- Seconds to wait before smelting everything once
        fuel = { -- As long as the 'from' item and amount is inside the machine, it can be turned on
            from  = { item = "wood", amount = 10 },
            to = { item = "charcoal", amount = 5 }, -- Remove this line if u don't want any output item
        },
        smeltings = {
            {
                from = { item = "tosti", amount = 1 },
                to = { item = "sandwich", amount = 1 },
            },
            {
                from = { item = "twerks_candy", amount = 1 },
                to = { item = "snikkel_candy", amount = 1 },
            },
        },
        locations = { -- Locations to spawn a smelter on server start
            vector4(1877.8315, 279.1890, 163.2741, 244.8476),
        },
        placeable = {
            enabled = true, -- If you want to allow players to place smelters
            item = "bbq", -- Item to place a smelter
            pickup = {
                enabled = true, -- If you want to allow players to pick up smelters
                placerOnly = true, -- If you want only the placer to be able to pick up the smelter
                returnItem = true, -- If you want to return the item to the player after picking up the smelter
            }
        },
    },
}

Opensource Files

All script-related open source code is contained within these files. Third-party components, including frameworks, inventory systems, and other external code, are separately maintained & open sourced in our fmLib repository.
--[[
BY RX Scripts © rxscripts.xyz
--]]

function GetPlacingSmelterCoords(cfgSmelterKey)
    local smelter = Config.Smelters[cfgSmelterKey]
    local prop = smelter.prop
    local coords = GetEntityCoords(PlayerPedId())
    local forward = GetEntityForwardVector(PlayerPedId())

    coords = coords + forward

    if prop == 'furnacesmall' then
        coords = coords - vector3(0, 0, 1.5)
    elseif prop == 'hornoelectrico' then
        coords = coords - vector3(0, 0, 1.5)
    elseif prop == 'bbqbig' then
        coords = coords - vector3(0, 0, 1.75)
    elseif prop == 'bbqrustys' then
        coords = coords - vector3(0, 0, 1.75)
    else
        coords = coords - vector3(0, 0, 1.0)
    end

    local heading = GetEntityHeading(PlayerPedId())

    return coords, heading
end

function Notify(msg, type)
    if Core == 'ESX' then
        CoreObj.ShowNotification(msg, type)
    elseif Core == 'QB' then
        CoreObj.Functions.Notify(msg, type)
    end
end

function InitSmelter(smelter)
    local smelterSettings = Config.Smelters[smelter]

    if Target == 'OX' then
        exports.ox_target:addModel(smelterSettings.prop, {
            {
                name = "Open "..smelterSettings.label,
                label = string.format(Locales['open_label'], smelterSettings.label),
                icon =  "fas fa-fire-flame-curved",
                iconColor = "orange",
                distance = 2.5,
                onSelect = function(data)
                    local obj = GetClosestObjectOfType(data.coords, data.distance + 1.0, GetHashKey(smelterSettings.prop), false, false, false)
                    if obj == 0 then
                        obj = GetClosestObjectOfType(data.coords, data.distance + 1.0, GetHashKey(smelterSettings.prop), true, false, false)
                    end

                    if obj then
                        OpenSmelter(smelter, GetEntityCoords(obj))
                    end
                end,
            },
        })
    elseif Target == 'QB' then
        exports['qb-target']:AddTargetModel(smelterSettings.prop, {
            options = {
                {
                    num = 1,
                    icon = "fas fa-fire-flame-curved",
                    label = string.format(Locales['open_label'], smelterSettings.label),
                    action = function(entity)
                        OpenSmelter(smelter, GetEntityCoords(entity))
                    end,
                },
            },
            distance = 2.5
        })
    end
end

function InitPickupSmelterTarget(key, smelter, entity)

    local smelterKey = PlacedSmelters[key].cfgSmelterKey

    if Target == 'OX' then
        exports.ox_target:addLocalEntity(entity, {
            {
                name = "Pick up "..smelter.label,
                label = "Pick up "..smelter.label,
                icon =  "fas fa-fire-flame-curved",
                iconColor = "orange",
                distance = 2.5,
                onSelect = function()
                    PickupSmelter(key, smelter.label)
                end,
            },
        })
    elseif Target == 'QB' then
        exports['qb-target']:AddTargetEntity(entity, {
            options = {
                {
                    num = 1,
                    icon = "fas fa-fire-flame-curved",
                    label = string.format(Locales['open_label'], smelter.label),
                    canInteract = function()
                        return true
                    end,
                    action = function()
                        OpenSmelter(smelterKey, GetEntityCoords(entity))
                    end,
                },
                {
                    icon = "fas fa-fire-flame-curved",
                    label = "Pick up "..smelter.label,
                    action = function()
                        PickupSmelter(key, smelter.label)
                    end
                },
            },
            distance = 2.5
        })
    end
end