server.lua

This file holds three things: the database switch, the Discord logs, and the hooks where the script hands control over to your own resources.

SectionWhat it is for
Config.AutoCreateSQLCreating the database tables on start.
Config.LogsDiscord logs, one switch per kind of event.
OpenServer.*Empty functions for your own logs, alerts, quests and checks.

Money, items and notifications are handled by devhub_lib for your framework, so there is nothing to wire up for them here.

Database

Lua
Config.AutoCreateSQL = true
  • Description: Creates every table the script needs on start. Set it to false only if your database user is not allowed to create tables, and import sql.sql yourself.

Discord Logs

Lua
Config.Logs = {
    Webhook = '', -- Discord webhook URL (empty = logs off)
 
    Plants = {
        Planting = true,
        Harvest = true,
        Theft = true,
    },
    ...
    Suspicious = true,
}
  • Description: Sends an embed to a Discord webhook whenever something worth recording happens. An empty Webhook turns logging off completely, no matter what the category switches say.
  • Setup: Create a webhook in your Discord channel settings, paste the URL into Webhook, and switch off the categories you do not care about.
  • Why it is in server.lua: this file never reaches the players' computers, so nobody can read your webhook URL out of the client files.

Every embed shows the player's name, server id and identifier, what happened, and the details that matter for that event (item and amount, price and account, plant or warehouse id, coordinates).

Plants

SwitchLogs
PlantingPots placed, seeds planted, pots picked up and plants destroyed by their owner.
HarvestPlants harvested and wild bushes picked.
TheftSomeone harvested or destroyed a plant they do not own, or emptied someone else's drying rack.

Processing

SwitchLogs
DryingBuds hung on drying racks and dry buds collected.
PackingJoints, bags and bricks packed.
CrossbreedEvery crossbreeding attempt, successful or not.

Shops

SwitchLogs
ShopPurchases at the Weed Tools shop.
DealerPurchases from the seed dealer.

Warehouses

SwitchLogs
MarketWarehouses bought and sold.
WalletWallet deposits, withdrawals and expansions bought.
StashItems put in and taken out of the warehouse stash.
WorkersWorkers hired, fired and paid by hand, and changes to their settings.
AutomaticWhat the workers harvest, dry and pack on their own, and their wages. Off by default.

Admin

SwitchLogs
SettingsEverything saved in /weedadmin: settings, the shop, zones, wild bushes, joints, warehouse locations and warehouse options.
GiveItems and warehouses given by staff.
WorldPlants and stations edited by staff.

Suspicious

Suspicious = true logs every server check a normal client never fails: an action that came too fast, from too far away, in the wrong state or without the needed items. The same line is printed in red in the server console.

Automatic is the loudest switch by a wide margin: every worker task and every wage payment is one message, around the clock, even while nobody is online. Leave it off unless you are investigating a specific warehouse.


Server hooks

Every OpenServer function ships empty on purpose. Fill in the ones you need; leave the others alone.

  • Every devhub_lib function works inside them, for example Core.GetIdentifier(source), Core.AddItem(...) or Core.Notify(...).
  • They run inside pcall: a mistake in your code prints an error in the server console instead of breaking the action that called it.
  • They run after the action succeeded. To stop an action, use the admin panel settings instead; these hooks are for reacting.
FunctionFires when
LogAny logged action happens, including the ones switched off in Config.Logs.
SuspiciousA server check fails that a normal client never fails.
OnPlantTouchedByStrangerSomeone harvests or destroys a plant they do not own.
OnRackRobbedSomeone takes the dry buds from an outdoor rack they do not own.
OnPlantActionAny plant action succeeds.
OnSeedsReceivedA player gets seeds from the dealer, a wild bush or crossbreeding.
OnTopPickedA bud is picked off a plant.
OnPlantHarvestedA plant is picked down to its last bud.

Log

Lua
function OpenServer.Log(source, operation, fields)
end
  • Description: Called for every action the script logs, before the Discord switches are checked. Use it to send logs to your own system (fivemanage, a database table, a different webhook per category).
  • source: the player, or nil for actions nobody triggered (worker tasks and wages).
  • operation: what happened, as a short code. The full list:
GroupOperations
PlantsPLANT_PLACE, PLANT_SEED, PLANT_PICKUP, PLANT_DESTROY, HARVEST, WILD_PICK, PLANT_TOUCHED, RACK_ROBBED
ProcessingRACK_LOAD, RACK_COLLECT, PACK, CROSSBREED
ShopsSHOP_BUY, DEALER_BUY
WarehousesWAREHOUSE_BUY, WAREHOUSE_SELL, WAREHOUSE_UPGRADE, WAREHOUSE_DEPOSIT, WAREHOUSE_WITHDRAW, STASH_IN, STASH_OUT
WorkersWORKER_HIRE, WORKER_FIRE, WORKER_PAY, WORKER_PREFS, WORKER_HARVEST, WORKER_PACK, WORKER_RACK_LOAD, WORKER_RACK_COLLECT, WORKER_WAGE, WORKER_UNPAID
AdminADMIN_SETTINGS, ADMIN_SHOP_SETTINGS, ADMIN_ZONES, ADMIN_WILD, ADMIN_JOINTS, ADMIN_WAREHOUSE_LOCATION, ADMIN_WAREHOUSE_OPTION, ADMIN_GIVE, ADMIN_WAREHOUSE_GIVE, ADMIN_PLANT, ADMIN_STATION
AnticheatSUSPICIOUS
  • fields: a table with any of account, amount, item, count, identifier, success and details (a table with everything else about the event).

Example: every purchase into your own database table.

Lua
function OpenServer.Log(source, operation, fields)
    if operation ~= 'SHOP_BUY' and operation ~= 'DEALER_BUY' then return end
    exports.oxmysql:insert('INSERT INTO my_purchases (identifier, shop, amount) VALUES (?, ?, ?)', {
        fields.identifier, operation, fields.amount,
    })
end

Suspicious

Lua
function OpenServer.Suspicious(source, reason, level)
end
  • Description: Your anticheat or staff alert. reason is a readable sentence such as picked a top from too far (plant 12).
  • level: 1 = minor, lag or a slow connection can cause it. 2 = almost certainly cheating.

Example: only the serious ones go to your anticheat.

Lua
function OpenServer.Suspicious(source, reason, level)
    if level < 2 then return end
    exports['my_anticheat']:flag(source, 'devhub_weed: ' .. reason)
end

OnPlantTouchedByStranger

Lua
function OpenServer.OnPlantTouchedByStranger(source, ownerSource, plantId, action)
end
  • Description: Someone harvested or destroyed a plant they do not own. The owner already gets a notification from the script; this hook is for anything extra, such as a police alert.
  • ownerSource: the owner's server id, or nil when the owner is offline.
  • action: 'harvest' or 'destroy'.

OnRackRobbed

Lua
function OpenServer.OnRackRobbed(source, ownerSource, stationId, amount)
end
  • Description: Someone collected the dry buds from an outdoor drying rack they do not own. The owner is notified by the script.
  • amount: how many dry buds were taken.

Progress hooks

Four hooks for quests, achievements and battle passes.

Lua
-- action = 'place' | 'soil' | 'seed' | 'water' | 'fertilize' | 'revive' | 'pickup' | 'destroy'
function OpenServer.OnPlantAction(source, identifier, action, plant)
end
 
-- how = 'dealer' | 'wild' | 'crossbreed'
function OpenServer.OnSeedsReceived(source, variety, amount, how)
end
 
-- info = { plantId, owner, stranger }
function OpenServer.OnTopPicked(source, identifier, variety, amount, info)
end
 
-- info = { plantId, owner, stranger, warehouseId, bucket, coords }
function OpenServer.OnPlantHarvested(source, identifier, variety, amount, info)
end
  • variety: the strain id, for example 'kush'. See strains-and-items.md.
  • amount in OnTopPicked: the wet buds given for that one bud, perks included.
  • amount in OnPlantHarvested: the wet buds the whole plant gave, from every player who picked it.
  • stranger: true when the picker is not the owner.

Example: a guidebook quest step for every harvested plant.

Lua
function OpenServer.OnPlantHarvested(source, identifier, variety, amount, info)
    TriggerClientEvent('dh_guidebook:client:questProgress', source, 'weed:harvest')
end

OnPlantHarvested also fires as the server event devhub_weed:server:plantHarvested, so another resource can listen without touching this file. See exports-and-events.md.