RX Scripts Logo
Mining

Configurables

All config & open sourced files included within this script.

Config Files

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

--[[
    MINING ZONES CAN BE FOUND IN config/zones.lua
    ORES CAN BE FOUND IN config/ores.lua
    TOOLS CAN BE FOUND IN config/tools.lua
    LEVELS CAN BE FOUND IN config/levels.lua
    MISSIONS CAN BE FOUND IN config/missions.lua
    TRANSLATIONS CAN BE FOUND IN locales/*.lua

    IN HERE YOU CAN FIND THE MORE GENERIC / NOT VERY LONG LISTS CONFIGURATIONS
--]]

Config = {}

Config.SaveInterval = 10                         -- Minutes (Set to 'false' to disable saving on interval, only on server shutdown, or important reached levels)                       -- Discord webhook to send important logs (Set to '' to disable)
Config.Locale = 'en'
Config.ImgDirectory = 'ox_inventory/web/images/' -- The directory where the images are stored.
Config.Keybinds = {
    pile = 36, -- LEFT CTRL
}

Config.MiningLicense = {
    enabled = true, -- Set to false to disable the whole mining license
    buyable = true, -- Set to false to disable buying the license, use exports to give the license to a player
    price = 1500,
    moneyType = 'bank',
    restricts = {
        mining = true,    -- If true, mining without a license will notify the police and will give no benefits
        shopNPC = true,   -- If true, you need a mining license to open the shop NPC
        sellNPC = true,   -- If true, you need a mining license to open the sell NPC
        miningNPC = true, -- If true, you need a mining license to open the mining NPC
        vehicleRenting = true, -- If true, you need a mining license to rent a vehicle
    },
}

Config.MiningNPC = { -- NPC to buy mining license (if enabled) & see routes, level etc..
    enabled = true,  -- Set to false to disable the mining NPC
    coords = vector3(1078.8353, -1980.5603, 30.4708),
    heading = 190.3568,
    model = 's_m_y_construct_01',
    blip = {
        enabled = true,
        sprite = 124,
        color = 31,
        label = 'Bob The Miner',
        display = 2,
        scale = 0.7,
        shortrange = true,
    },
}

Config.ShopNPC = {  -- NPC that opens a shop
    enabled = true, -- Set to false to disable the shop npc
    route = true,   -- If true, the shop NPC will have a route in the mining npc
    label = 'Mining Shop',
    moneyType = 'bank',
    model = 's_m_y_dockwork_01',
    coords = vector3(1078.0854, -1972.3464, 30.4707),
    heading = 196.7609,
    blip = {
        enabled = true,
        sprite = 124,
        color = 31,
        display = 2,
        scale = 0.7,
        shortrange = true,
    },
    categories = {
        ['Pickaxes'] = {
            { item = 'stone_pickaxe',    amount = 1, price = 2500,  label = 'Stone Pickaxe',    requiredLevel = 0, mystery = false },
            { item = 'iron_pickaxe',     amount = 1, price = 5000,  label = 'Iron Pickaxe',     requiredLevel = 1, mystery = false },
            { item = 'steel_pickaxe',    amount = 1, price = 7500,  label = 'Steel Pickaxe',    requiredLevel = 3, mystery = false },
            { item = 'titanium_pickaxe', amount = 1, price = 10000, label = 'Titanium Pickaxe', requiredLevel = 4, mystery = false },
            { item = 'diamond_pickaxe',  amount = 1, price = 15000, label = 'Diamond Pickaxe',  requiredLevel = 5, mystery = true },
            { item = 'quantum_pickaxe',  amount = 1, price = 20000, label = 'Quantum Pickaxe',  requiredLevel = 6, mystery = true },
        },
        ['Drills'] = {
            { item = 'mining_drill', amount = 1, price = 50000,  label = 'Mining Drill', requiredLevel = 8,  mystery = false },
            { item = 'laser_drill',  amount = 1, price = 100000, label = 'Laser Drill',  requiredLevel = 10, mystery = true },
        },
    },
}

Config.SellNPCS = {  -- NPC that opens a shop to sell mining stuff
    {
        enabled = true, -- Set to false to disable the selling shop npc
        route = true,   -- If true, the sell NPC will have a route in the mining npc
        label = 'Ingots Selling',
        moneyType = 'bank',
        model = 'a_m_m_hillbilly_01',
        coords = vector3(1076.8552, -1987.3607, 29.9554),
        heading = 234.2191,
        blip = {
            enabled = true,
            sprite = 124,
            color = 31,
            display = 2,
            scale = 0.7,
            shortrange = true,
        },
        categories = { -- Price is per 1
            ['Ingots'] = {
                { item = 'copper_ingot',     price = 100,  label = 'Copper Ingot',     requiredLevel = 0, mystery = false },
                { item = 'iron_ingot',       price = 200,  label = 'Iron Ingot',       requiredLevel = 1, mystery = false },
                { item = 'silver_ingot',     price = 300,  label = 'Silver Ingot',     requiredLevel = 2, mystery = false },
                { item = 'gold_ingot',       price = 400,  label = 'Gold Ingot',       requiredLevel = 3, mystery = false },
                { item = 'platinum_ingot',   price = 500,  label = 'Platinum Ingot',   requiredLevel = 4, mystery = false },
                { item = 'titanium_ingot',   price = 750,  label = 'Titanium Ingot',   requiredLevel = 5, mystery = false },
                { item = 'mithril_ingot',    price = 1000, label = 'Mitril Ingot',     requiredLevel = 6, mystery = true },
                { item = 'adamantium_ingot', price = 1500, label = 'Adamantium Ingot', requiredLevel = 8, mystery = true },
            },
        },
    },
    {
        enabled = true, -- Set to false to disable the selling shop npc
        route = true,   -- If true, the sell NPC will have a route in the mining npc
        label = 'Ore Selling',
        moneyType = 'bank',
        model = 'a_m_m_hillbilly_01',
        coords = vector3(2664.0840, 2893.8633, 35.7282),
        heading = 350.2184,
        blip = {
            enabled = true,
            sprite = 124,
            color = 31,
            display = 2,
            scale = 0.7,
            shortrange = true,
        },
        categories = { -- Price is per 1
            ['Ores'] = {
                { item = 'coal_ore',       price = 10,  label = 'Coal Ore',       requiredLevel = 0, mystery = false },
                { item = 'copper_ore',     price = 10,  label = 'Copper Ore',     requiredLevel = 0, mystery = false },
                { item = 'iron_ore',       price = 20,  label = 'Iron Ore',       requiredLevel = 1, mystery = false },
                { item = 'silver_ore',     price = 30,  label = 'Silver Ore',     requiredLevel = 2, mystery = false },
                { item = 'gold_ore',       price = 40,  label = 'Gold Ore',       requiredLevel = 3, mystery = false },
                { item = 'platinum_ore',   price = 50,  label = 'Platinum Ore',   requiredLevel = 4, mystery = false },
                { item = 'titanium_ore',   price = 75,  label = 'Titanium Ore',   requiredLevel = 5, mystery = false },
                { item = 'mithril_ore',    price = 100, label = 'Mitril Ore',     requiredLevel = 6, mystery = true },
                { item = 'adamantium_ore', price = 150, label = 'Adamantium Ore', requiredLevel = 8, mystery = true },
            },
        },
    }
}

Config.VehicleRentals = { -- Vehicle rentals (clear table to disable)
    ['Dumpers Rental'] = {
        model = 'a_m_m_hillbilly_01',
        locations = {
            {
                coords = vector3(2706.0933, 2777.3484, 36.8780),
                heading = 63.5346,
                spawnCoords = vector4(2687.5459, 2767.3572, 36.8780, 203.7949),
                returnCoords = vector3(2697.3955, 2776.9321, 37.8780)
            },
        },
        moneyType = 'bank',
        vehicles = {
            { model = 'bulldozer', label = 'Bulldozer', rentInterval = 30, intervalPrice = 1500, deposit = 10000, requiredLevel = 1, mystery = false },
            { model = 'dump',      label = 'Dump',      rentInterval = 30, intervalPrice = 2500, deposit = 15000, requiredLevel = 3, mystery = false },
            { model = 'tiptruck2', label = 'Tiptruck',  rentInterval = 30, intervalPrice = 3000, deposit = 15000, requiredLevel = 3, mystery = false },
            { model = 'rubble',    label = 'Rubble',    rentInterval = 30, intervalPrice = 3500, deposit = 20000, requiredLevel = 5, mystery = true },
        },
        blip = {
            enabled = true,
            sprite = 124,
            color = 31,
            display = 2,
            scale = 0.7,
            shortrange = true,
        },
    },
}

--[[
    ONLY CHANGE THIS PART IF YOU HAVE RENAMED SCRIPTS SUCH AS FRAMEWORK, TARGET, INVENTORY ETC
    RENAME THE SCRIPT NAME TO THE NEW NAME
--]]
---@type table Only change these if you have changed the name of a resource
Resources = {
    FM = { name = 'fmLib', export = 'new' },
    OXTarget = { name = 'ox_target', export = 'all' },
    QBTarget = { name = 'qb-target', export = 'all' },
}
IgnoreScriptFoundLogs = false

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 ShowTextUI(text, opts)
    if not TextUIShown then
        TextUIShown = true
        lib.showTextUI(text, opts)
    end
end

function HideTextUI()
    if TextUIShown then
        TextUIShown = false
        lib.hideTextUI()
    end
end

function AddMiningNPCTarget(ped)
    if OXTarget then
        OXTarget:addLocalEntity(ped, {
            {
                label = 'Open Bob The Miner',
                name = 'openMiningNPC',
                icon = 'fas fa-trowel',
                distance = 2.5,
                onSelect = function(data)
                    OpenMiningUI()
                end,
            }
        })
    elseif QBTarget then
        QBTarget:AddTargetEntity(ped, {
            options = {
                {
                    label = 'Open Bob The Miner',
                    icon = 'fas fa-trowel',
                    targeticon = 'fas fa-trowel',
                    action = function(entity)
                        OpenMiningUI()
                    end,
                }
            },
            distance = 2.5,
        })
    end
end

function AddOreTarget(zoneName, oreId)
    local ore = SpawnedOres[zoneName][oreId]

    if OXTarget then
        OXTarget:addLocalEntity(ore.obj, {
            {
                label = 'Mine '..ore.name,
                name = 'mineOre',
                icon = 'fas fa-trowel',
                distance = 2.5,
                canInteract = function()
                    return not IsMining
                end,
                onSelect = function(data)
                    MineOre(zoneName, oreId)
                end,
            }
        })
    elseif QBTarget then
        QBTarget:AddTargetEntity(ore.obj, {
            options = {
                {
                    label = 'Mine '..ore.name,
                    icon = 'fas fa-trowel',
                    targeticon = 'fas fa-trowel',
                    canInteract = function()
                        return not IsMining
                    end,
                    action = function(entity)
                        MineOre(zoneName, oreId)
                    end,
                }
            },
            distance = 2.5,
        })
    end
end

function AddShopNPCTarget(npc)
    if OXTarget then
        OXTarget:addLocalEntity(npc, {
            {
                label = 'Open Mining Shop',
                name = 'openMiningShop',
                icon = 'fas fa-shopping-cart',
                distance = 2.5,
                onSelect = function(data)
                    OpenShopNPC()
                end,
            }
        })
    elseif QBTarget then
        QBTarget:AddTargetEntity(npc, {
            options = {
                {
                    label = 'Open Mining Shop',
                    icon = 'fas fa-shopping-cart',
                    targeticon = 'fas fa-shopping-cart',
                    action = function(entity)
                        OpenShopNPC()
                    end,
                }
            },
            distance = 2.5,
        })
    end
end

function AddSellNPCTarget(npc, sellId)
    if OXTarget then
        OXTarget:addLocalEntity(npc, {
            {
                label = 'Open Mining Selling',
                name = 'openMiningSelling',
                icon = 'fas fa-shopping-cart',
                distance = 2.5,
                onSelect = function(data)
                    OpenSellNPC(sellId)
                end,
            }
        })
    elseif QBTarget then
        QBTarget:AddTargetEntity(npc, {
            options = {
                {
                    label = 'Open Mining Selling',
                    icon = 'fas fa-shopping-cart',
                    targeticon = 'fas fa-shopping-cart',
                    action = function(entity)
                        OpenSellNPC(sellId)
                    end,
                }
            },
            distance = 2.5,
        })
    end
end

function AddVehicleRentalNPCTarget(npc, rentalName, locIndex)
    if OXTarget then
        OXTarget:addLocalEntity(npc, {
            {
                label = 'Open '..rentalName,
                name = 'openVehicleRental',
                icon = 'fas fa-truck',
                distance = 2.5,
                onSelect = function(data)
                    OpenVehicleRental(rentalName, locIndex)
                end,
            }
        })
    elseif QBTarget then
        QBTarget:AddTargetEntity(npc, {
            options = {
                {
                    label = 'Open '..rentalName,
                    icon = 'fas fa-ship',
                    targeticon = 'fas fa-truck',
                    action = function(entity)
                        OpenVehicleRental(rentalName, locIndex)
                    end,
                }
            },
            distance = 2.5,
        })
    end
end

function RemoveShopNPCTarget(ped)
    if OXTarget then
        OXTarget:removeLocalEntity(ped, 'openMiningShop')
    elseif QBTarget then
        QBTarget:RemoveTargetEntity(ped, 'Open Mining Shop')
    end
end

function RemoveSellNPCTarget(ped)
    if OXTarget then
        OXTarget:removeLocalEntity(ped, 'openMiningSelling')
    elseif QBTarget then
        QBTarget:RemoveTargetEntity(ped, 'Open Mining Selling')
    end
end

function RemoveTarget(ent, name)
    if OXTarget then
        OXTarget:removeLocalEntity(ent, name)
    elseif QBTarget then
        QBTarget:RemoveTargetEntity(ent, name)
    end
end

function GetItemsAmounts()
    return FM.callback.sync('mining:getItemsAmounts')
end

function MineProgressBar(toolFound, duration)
    local cfgTool = Config.Tools[toolFound]

    return FM.progress.start({
        label = 'Mining',
        time = duration,
        anim = cfgTool.anim,
        disable = {
            move = true,
            car = true,
            combat = true,
        },
        prop = cfgTool.prop,
        type = 'circle',
    })
end

---@param type 'returnVehicle'
function ShowMarker(type, coords)
    if type == 'returnVehicle' then
        DrawMarker(39, coords, 0, 0, 0, 0, 0, 0, 3.0, 3.0, 3.0, 255, 100, 100, 100, false, true, 2, false, false, false, false)
    end
end

function ShowHelpNotification(msg, thisFrame, beep, duration)
    AddTextEntry('helpNotification', msg)

    if thisFrame then
        DisplayHelpTextThisFrame('helpNotification', false)
    else
        if beep == nil then
            beep = true
        end
        BeginTextCommandDisplayHelp('helpNotification')
        EndTextCommandDisplayHelp(0, false, beep, duration or -1)
    end
end

local function notifyPolice(coords, msg)
    local blip = AddBlipForCoord(coords.x, coords.y, coords.z)
    SetBlipSprite(blip, 161)
    SetBlipScale(blip, 1.0)
    SetBlipColour(blip, 1)
    SetBlipAsShortRange(blip, false)
    BeginTextCommandSetBlipName("STRING")
    AddTextComponentString(_L('blip_suspicious_mining_activity'))
    EndTextCommandSetBlipName(blip)

    FM.utils.notify(msg, 'error')

    Wait(20000)
    RemoveBlip(blip)
end

RegisterNetEvent('mining:notifyPolice', function(coords, msg)
    notifyPolice(coords, msg)
end)