Integrations
We provide various open source functions into our Advanced Weed Growing resource that enables you to add further customization and/or add third-party resource integrations.
Client
Partial example of code available in client/functions.lua
-- Used to determine if a player can (true) or cannot(false) search a plant for seeds
--- @param id number farmId, can be accessed via Config.Farms[id]
function CanSearchPlant(id)
return true
end
-- Empty function used to allow or reject a user from placing a plant
-- You can add custom requirements here if you have the knowledge to do so
-- To restrict planting return false. To allow return true.
--- @param strain string Unique strain identifier: Config.Strains[strain]
function CanPlant(strain)
local inVehicle = IsPedInAnyVehicle(cache.ped, true)
if inVehicle then
ShowNotification(locale('notify.no-vehicle'), 'error')
return false
end
return true
end
-- Function used to allow or reject a user from entering the lab
-- You can add custom requirements here if you have the knowledge to do so
-- To restrict access return false. To allow access return true.
function CanEnterLab()
local result, isPolice = true, false
if Config.Police.labAccess then
local playerJob = GetPlayerJob()
for _, job in pairs(Config.Police.jobs) do
if playerJob == job then
isPolice = true
end
end
end
local requirements = Config.Lab.requirements
if not requirements then
EventLog('[functions.lua]: CanEnterLab: missing config data')
result = false
end
local playerLevel = exports.lation_weed:GetPlayerData('level')
if playerLevel < requirements.level and not isPolice then
EventLog('[functions.lua]: CanEnterLab: player does not meet level requirement')
result = false
end
if requirements.item.enable then
local hasItem = HasItem(requirements.item.name, 1)
if not hasItem and not isPolice then
EventLog('[functions.lua]: CanEnterLab: player does not have required item')
result = false
end
end
if requirements.police.enable then
local police = lib.callback.await('lation_weed:PoliceCount', false)
if police < requirements.police.count and not isPolice then
EventLog('[functions.lua]: CanEnterLab: not enough police available')
result = false
end
end
if not result then
ShowNotification(locale('notify.not-authorized'), 'error')
end
-- If you want to add custom requirements for entering the lab
-- This is where you would make that happen
return result
end
-- Empty function used to allow or reject a player from starting to roll a joint(s)
-- To reject a roll return false. To allow a roll return true.
function CanRoll(strain)
return true
end
-- Empty function used to allow or reject a player from starting to bag bud(s)
-- To reject a bag return false. To allow a bag return true.
function CanBag(strain)
return true
end
-- Used to determine if a player can (true) or cannot (false) smoke a joint
-- Can be used to make custom edits, requirements, etc
function CanSmoke()
return true
end
-- Function that's triggered when planting process has started
-- This function can be used for anything, but by default
-- It disables the ability to open your inventory during
-- The plant placement process
function StartedPlanting()
DisableInventory()
end
-- Function that's triggered when finished planting process
-- As mentioned above, this function can be used for anything
-- But by default, after a player has finished plant placement
-- It will re-enable access to their inventory
function StoppedPlanting()
EnableInventory()
end
Server
Partial example of code available in server/functions.lua
-- Used to verify all conditions are met before allowing plant placement
-- You can add custom requirements here if you have the knowledge to do so
-- To restrict placement return false. To allow placement return true.
--- @param source number Player ID
--- @param strain string Unique strain identifier | Config.Strains[strain]
--- @return boolean
function CanPlant(source, strain)
if not source or not strain then
EventLog('[functions.lua]: CanPlant: params missing or nil', 'error')
return false
end
local data = Config.Strains[strain]
if not data then
EventLog('[functions.lua]: CanPlant: invalid strain', 'error')
return false
end
local player = GetPlayerPed(source)
if not player then
EventLog('[functions.lua]: CanPlant: unable to get player ped', 'error')
return false
end
local pos = GetEntityCoords(player)
if not pos then
EventLog('[functions.lua]: CanPlant: unable to get player coords', 'error')
return false
end
local identifier = GetIdentifier(source)
if not identifier then
EventLog('[functions.lua]: CanPlant: unable to get player identifier', 'error')
return false
end
local level = exports.lation_weed:GetPlayerData(source, 'level')
if not level then
EventLog('[functions.lua]: CanPlant: unable to get player level', 'error')
return false
end
if level < data.level then
TriggerClientEvent('lation_weed:Notify', source, locale('notify.not-experienced'), 'error')
return false
end
if Config.Police.require then
local police = GetPoliceCount()
if police < Config.Police.count then
TriggerClientEvent('lation_weed:Notify', source, locale('notify.no-police'), 'error')
return false
end
end
local blacklisted = false
for _, zone in pairs(Config.Planting.blacklist) do
local dist = #(pos - zone.coords)
if dist <= zone.radius then
blacklisted = true
break
end
end
if blacklisted then
TriggerClientEvent('lation_weed:Notify', source, locale('notify.cant-place'), 'error')
return false
end
if Config.Planting.restrict.enable then
local whitelisted = false
for _, zone in pairs(Config.Planting.restrict.whitelist) do
local dist = #(pos - zone.coords)
if dist <= zone.radius then
whitelisted = true
break
end
end
if not whitelisted then
TriggerClientEvent('lation_weed:Notify', source, locale('notify.cant-place'), 'error')
return false
end
end
local count = 0
for _, plant in pairs(WeedPlants) do
if plant.owner == identifier then
count += 1
end
end
if count >= Config.Planting.max then
TriggerClientEvent('lation_weed:Notify', source, locale('notify.max-plants'), 'error')
return false
end
if Config.Planting.items.plant_pot.require then
local hasPot = GetItemCount(source, Config.Planting.items.plant_pot.item) >= Config.Planting.items.plant_pot.consume
if not hasPot then
TriggerClientEvent('lation_weed:Notify', source, locale('notify.no-pot'), 'error')
return false
end
end
if Config.Planting.items.shovel.require then
local hasShovel = GetItemCount(source, Config.Planting.items.shovel.item) >= Config.Planting.items.shovel.consume
if not hasShovel then
TriggerClientEvent('lation_weed:Notify', source, locale('notify.no-shovel'), 'error')
return false
end
end
return true
end
-- Used to verify all conditions are met before allowing table placement
-- You can add custom requirements here if you have the knowledge to do so
-- To restrict placement return false. To allow placement return true.
--- @param source number Player ID
--- @return boolean
function CanPlaceTable(source)
if not source then
EventLog('[functions.lua]: CanPlaceTable: source missing or nil')
return false
end
local player = GetPlayerPed(source)
if not player then
EventLog('[functions.lua]: CanPlaceTable: unable to obtain player ped')
return false
end
local pos = GetEntityCoords(player)
if not pos then
EventLog('[functions.lua]: CanPlaceTable: unable to obtain player position')
return false
end
local identifier = GetIdentifier(source)
if not identifier then
EventLog('[functions.lua]: CanPlaceTable: unable to obtain player identifier')
return false
end
local count = 0
for _, table in pairs(Tables) do
if table.owner == identifier then
count += 1
end
end
if count >= Config.Table.limit then
TriggerClientEvent('lation_weed:Notify', source, locale('notify.max-tables'), 'error')
return false
end
if Config.Table.requirements.police.enable then
local police = GetPoliceCount()
if police < Config.Table.requirements.police.count then
TriggerClientEvent('lation_weed:Notify', source, locale('notify.no-police'), 'error')
return false
end
end
for _, location in pairs(Config.Table.restricted) do
local dist = #(pos - location.coords)
if dist < location.radius then
TriggerClientEvent('lation_weed:Notify', source, locale('notify.cant-place'), 'error')
return false
end
end
return true
end
-- Empty function triggered when a player searches a plant & finds a seed
--- @param source number Player Id
--- @param farmId number Config.Farms[farmId]
--- @param reward table reward.item, reward.quantity
function FarmSearched(source, farmId, reward)
end
-- Empty function thats triggered when a player plants a seed
--- @param source number Player ID
--- @param strain string Unique strain identifier | Config.Strains[strain]
--- @param coords vector3 Coordinates planted at
function SeedPlanted(source, strain, coords)
end
-- Empty function thats triggered when a player fertilizes a plant
--- @param source number Player ID
function PlantFed(source)
end
-- Empty function thats triggered when a player waters a plant
--- @param source number PlayerID
function PlantWatered(source)
end
-- Empty function thats triggered when a plant is destroyed
--- @param source number Player ID
--- @param strain string Unique strain identifier | Config.Strains[strain]
function PlantDeleted(source, strain)
end
-- Empty function thats triggered when a player harvests a plant
--- @param source number Player ID
--- @param strain string Unique strain identifier | Config.Strains[strain]
--- @param amount number Quantity of bud received
--- @param quality number Quality level of bud harvested
function PlantHarvested(source, strain, amount, quality)
end
-- Empty function thats triggered when a player finished rolling joints
--- @param source number Player ID
--- @param strain string Unique strain identifier | Config.Strains[strain]
--- @param total number Total number rolled
function JointsRolled(source, strain, total)
end
-- Empty function thats triggered when a player finished bagging weed
--- @param source number Player ID
--- @param strain string Unique strain identifier | Config.Strains[strain]
--- @param total number Total number bagged
function WeedBagged(source, strain, total)
end
-- Empty function thats triggered when a player smokes a joint
--- @param source number Player ID
--- @param item string Item name
function JointSmoked(source, item)
end
-- Empty function thats triggered when a player places a table down
--- @param source number Player ID
--- @param coords vector3|vector4 Coordinates
function TablePlaced(source, coords)
end
-- Empty function thats triggered when a player buys from supply shop
--- @param source number Player ID
--- @param itemId string Config.Shop.items[itemId]
--- @param quantity number Quantity of item purchased
function ShopPurchase(source, itemId, quantity)
end
Warning
It is important to note: any & all edits made in these various functions are your responsibility. We do not provide support for, nor assist with, adding or editing custom functionality into our resources.
Last updated