RX Scripts Logo
Plantation

Configurables

All config & open sourced files included within this script.

Config Files

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

Config = {}
-- Create plants in the config/plants/ folder
Config.Plants = {}

Config.DiscordWebhook = ''
Config.Locale = 'en'
Config.SaveInterval = 10    -- Minutes (Set to 'false' to disable saving on interval, only on server shutdown)
Config.PaymentType = 'bank' -- Payment type for buying & upgrading stuff
Config.DistanceBetween = 2.5 -- Minimum distance between plants
Config.PublicAccessFreePlanted = false -- Allow everyone to access & manage a freely planted plant (without plot)
Config.MaxFreePlants = 5 -- Maximum amount of plants a player can plant without a plot
Config.CreatePlantsDistance = 100.0 -- Distance to be nearby for plants to be created
Config.CreatePlantsWait = 1000 -- Wait time in ms for checking distance to create plants

--[[
    Make all kinds of custom actions to (re)use for a plant.
    To bind an action to a plant, go to the actions of your plant in the Config.Plants table and put the unique action name in this list.
--]]
Config.Actions = {                -- Make all kinds of custom actions to (re)use for a plant, you set these
    ['waterWithCan'] = {          -- Unique action
        label = 'Water',
        interval = 60,            --  Minutes before action can be done again
        onPlaceInterval = 0,      -- Minutes before action can be done for the first time (0 to immediately can/need to use action, maximum is interval)
        plantProgress = {
            increase = 10,        -- Increase plant progress when using this action (0-100)
            decrease = 5,         -- Decrease plant progress if action is not done after interval
            decreaseInterval = 30 -- Every x minutes the plant progress decreases if the action is not done when its ready to do
        },
        requiredItems = {
            { item = 'watering_can', label = 'Watering Can', amount = 1, remove = true },
        },
        progressBar = {
            enabled = true,
            label = 'Watering..',
            duration = 5000, -- Duration in milliseconds
            animation = { dict = 'amb@world_human_gardener_plant@male@base', anim = 'base' },
            prop = {
                -- model = 'prop_wateringcan',
                -- position = vector3(0.0, 0.0, 0.0),
                -- rotation = vector3(0.0, 0.0, 0.0),
                -- bone = 60309,
            },
        },
        ui = {
            color = 'sky',   -- 'sky' | 'rose' | 'amber'
            icon = 'bucket', -- 'bucket' | 'seedling' | 'sack' | 'droplet'
        },
        success = "You have watered the plant",
    },
    ['fertilize'] = {
        label = 'Fertilize',
        interval = 60,
        onPlaceInterval = 30,
        plantProgress = {
            increase = 10,
            decrease = 5,
            decreaseInterval = 30
        },
        requiredItems = {
            { item = 'fertilizer', label = 'Fertilizer', amount = 1, remove = true },
        },
        progressBar = {
            enabled = true,
            label = 'Fertilizing..',
            duration = 5000,
            animation = { dict = 'amb@world_human_gardener_plant@male@base', anim = 'base' },
            prop = {
                -- model = 'prop_wateringcan',
                -- position = vector3(0.0, 0.0, 0.0),
                -- rotation = vector3(0.0, 0.0, 0.0),
                -- bone = 60309,
            },
        },
        ui = {
            color = 'amber',
            icon = 'sack',
        },
        success = "You have fertilized the plant",
    },
    ['customAction'] = {
        label = 'Custom Action',
        interval = 60,
        onPlaceInterval = 30,
        plantProgress = {
            increase = 10,
            decrease = 5,
            decreaseInterval = 30
        },
        requiredItems = {
            -- { item = 'bread', label = 'Custom Item', amount = 1, remove = true },
        },
        progressBar = {
            enabled = true,
            label = 'Custom Actioning..',
            duration = 5000,
            animation = { dict = 'amb@world_human_gardener_plant@male@base', anim = 'base' },
            prop = {
                -- model = 'prop_wateringcan',
                -- position = vector3(0.0, 0.0, 0.0),
                -- rotation = vector3(0.0, 0.0, 0.0),
                -- bone = 60309,
            },
        },
        ui = {
            color = 'invalid_color_gets_gray',
            icon = 'droplet',
        },
        success = "You have executed a custom action",
    },
}

--[[
    Configure & customize all plots
--]]
Config.Plots = {
    ['Farmer Plot'] = {
        price = 50000,
        payWithItem = {
            enabled = false, -- If enabled, the price above is the amount of the item below you need to pay, instead of money
            currency = { item = 'gold', label = 'Gold' },
        },
        maxPlants = 10,
        allowedPlants = { 'Tomato' }, -- Allowed plants for this plot from config/plants/ folder
        upgrades = {
            plants = {
                { type = 'Cotton', price = 5000 },
                { type = 'Potato', price = 10000 },
            },
            maxPlants = {
                { amount = 20, price = 5000 },
                { amount = 30, price = 10000 },
            }
        },
        farmers = { -- Members that can be added to the plot to work together
            enabled = true,
            max = 1,
        },
        sellable = {
            enabled = true,
            price = 5000,
        },
        stash = {
            enabled = true,
            slots = 20,
            weight = 1000,
        },
        npc = {
            model = 'a_m_m_hillbilly_01',
            coords = vector3(2199.5732, 5197.5605, 60.0815),
            heading = 121.3640,
        },
        zone = {
            canShow = true, -- Zone can be shown at the npc
            thickness = 10,
            points = {      -- All z values must match
                vector3(2216.5903, 5174.9321, 60.0),
                vector3(2196.9011, 5195.4331, 60.0),
                vector3(2181.9851, 5204.6304, 60.0),
                vector3(2168.9219, 5210.4526, 60.0),
                vector3(2159.4966, 5212.4468, 60.0),
                vector3(2145.6890, 5211.6963, 60.0),
                vector3(2197.6438, 5154.3555, 60.0),
                vector3(2213.6431, 5170.1870, 60.0),
            },
        }
    },
    ['Drugs Plot'] = {
        price = 100000,
        payWithItem = {
            enabled = false, -- If enabled, the price above is the amount of the item below you need to pay, instead of money
            currency = { item = 'gold', label = 'Gold' },
        },
        maxPlants = 10,
        allowedPlants = { 'Weed', 'Poppy' }, -- Allowed plants for this plot from config/plants/ folder
        upgrades = {
            plants = {
                { type = 'Blue Weed', price = 5000 },
                { type = 'Purple Weed', price = 10000 },
                { type = 'Coca', price = 10000 },
            },
            maxPlants = {
                { amount = 20, price = 5000 },
                { amount = 30, price = 10000 },
            }
        },
        farmers = {
            enabled = true,
            max = 2,
        },
        sellable = {
            enabled = true,
            type = 'bank',
            price = 5000,
        },
        stash = {
            enabled = true,
            slots = 20,
            weight = 1000,
        },
        npc = {
            model = 'g_m_m_armboss_01',
            coords = vector3(5404.3218, -5173.9409, 30.4826),
            heading = 89.9120,
        },
        zone = {
            canShow = true, -- Zone can be shown at the npc
            thickness = 10,
            points = {      -- All z values must match
                vector3(5398.9517, -5191.7437, 30.0),
                vector3(5429.2002, -5216.2227, 30.0),
                vector3(5411.8711, -5240.5015, 30.0),
                vector3(5380.2134, -5215.8584, 30.0),
            },
        }
    }
}

--[[
    Configure wild spawning
    Spawns random plants at random locations in their last stage to be harvested
--]]
Config.WildSpawning = {
    {
        plants = { 'Tomato', 'Potato', 'Cotton' }, -- Plants that can spawn at these locations
        limit = 1, -- How many plants can spawn at the same time (we recommend to set this like 1/2 of the total locations)
        locations = {
            vector4(819.2141, 6513.7358, 22.1483, 238.0658),
            vector4(814.9882, 6514.5430, 22.2471, 78.8440),
        },
    },
}

--[[
    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 InitPlotTarget(plotName)
    local staticPlot = Plots[plotName]
    local pedEntity = staticPlot.ped

    if OXTarget then
        OXTarget:addLocalEntity(pedEntity, {
            {
                label = 'Buy Plot',
                name = 'buyPlotNPC',
                icon = 'fas fa-leaf',
                distance = 2.5,
                canInteract = function()
                    return not Plots[plotName].owner
                end,
                onSelect = function()
                    OpenBuyPlot(plotName)
                end,
            },
            {
                label = 'Manage Plot',
                name = 'managePlotNPC',
                icon = 'fas fa-leaf',
                distance = 2.5,
                canInteract = function()
                    return Plots[plotName] and Plots[plotName].owner == PlayerIdentifier
                end,
                onSelect = function()
                    OpenManagePlot(plotName)
                end,
            },
            {
                label = 'Sell Plot',
                name = 'sellPlotNPC',
                icon = 'fas fa-leaf',
                distance = 2.5,
                canInteract = function()
                    return Plots[plotName] and Plots[plotName].owner == PlayerIdentifier and Plots[plotName].sellable.enabled
                end,
                onSelect = function()
                    SellPlot(plotName)
                end,
            },
            {
                label = 'Toggle Zone',
                name = 'toggleZoneNPC',
                icon = 'fas fa-draw-polygon',
                distance = 2.5,
                canInteract = function()
                    return staticPlot.zone.canShow
                end,
                onSelect = function()
                    InitPlotZone(plotName)
                end,
            },
        })
    elseif QBTarget then
        QBTarget:AddTargetEntity(pedEntity, {
            options = {
                {
                    label = 'Buy Plot',
                    icon = 'fas fa-leaf',
                    canInteract = function()
                        return not Plots[plotName].owner
                    end,
                    action = function(data)
                        OpenBuyPlot(plotName)
                    end,
                },
                {
                    label = 'Manage Plot',
                    icon = 'fas fa-leaf',
                    canInteract = function()
                        return Plots[plotName] and Plots[plotName].owner == PlayerIdentifier
                    end,
                    action = function(data)
                        OpenManagePlot(plotName)
                    end,
                },
                {
                    label = 'Sell Plot',
                    icon = 'fas fa-leaf',
                    canInteract = function()
                        return Plots[plotName] and Plots[plotName].owner == PlayerIdentifier and Plots[plotName].sellable.enabled
                    end,
                    action = function(data)
                        SellPlot(plotName)
                    end,
                },
                {
                    label = 'Toggle Zone',
                    icon = 'fas fa-draw-polygon',
                    canInteract = function()
                        return staticPlot.zone.canShow
                    end,
                    action = function(data)
                        InitPlotZone(plotName)
                    end,
                },
            },
            distance = 2.5
        })
    end
end

function InitPlantTarget(plantId, isWild)
    local plant = not isWild and Plants[plantId] or WildPlants[plantId]

    if OXTarget then
        OXTarget:addLocalEntity(plant.object, {
            {
                label = 'Manage ' .. plant.type,
                name = 'managePlant',
                icon = 'fas fa-leaf',
                distance = 2.5,
                canInteract = function()
                    if isWild then return false end
                    if not plant.plot and Config.PublicAccessFreePlanted then return true end

                    local plot = Plots[plant.plot]

                    if plant.plot and plot then
                        local cfgPlot = Config.Plots[plant.plot]

                        if cfgPlot and cfgPlot.farmers and cfgPlot.farmers.enabled then
                            if plot.members[PlayerIdentifier] then return true end
                            if plot.owner == PlayerIdentifier then return true end
                        end
                    end

                    if plant.owner == PlayerIdentifier then return true end

                    return false
                end,
                onSelect = function()
                    OpenManagePlant(plantId)
                end,
            },
            {
                label = 'Harvest ' .. plant.type,
                name = 'harvestPlant',
                icon = 'fas fa-leaf',
                distance = 2.5,
                canInteract = function()
                    return isWild
                end,
                onSelect = function()
                    HarvestPlant(plantId, true)
                end,
            }
        })
    elseif QBTarget then
        QBTarget:AddTargetEntity(plant.object, {
            options = {
                {
                    label = 'Manage Plant',
                    icon = 'fas fa-leaf',
                    canInteract = function()
                        if isWild then return false end
                        if not plant.plot and Config.PublicAccessFreePlanted then return true end
                        if plant.plot and Plots[plant.plot] then
                            local cfgPlot = Config.Plots[plant.plot]
                            if cfgPlot and cfgPlot.farmers and cfgPlot.farmers.enabled then
                                if Plots[plant.plot].members[PlayerIdentifier] then return true end
                            end
                        end

                        if plant.owner == PlayerIdentifier then return true end

                        return false
                    end,
                    action = function(data)
                        OpenManagePlant(plantId)
                    end,
                },
                {
                    label = 'Harvest Plant',
                    icon = 'fas fa-leaf',
                    canInteract = function()
                        return isWild
                    end,
                    action = function(data)
                        HarvestPlant(plantId, true)
                    end,
                }
            },
            distance = 2.5
        })
    end
end