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.
| Section | What it is for |
|---|---|
Config.AutoCreateSQL | Creating the database tables on start. |
Config.Logs | Discord 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
Config.AutoCreateSQL = true- Description: Creates every table the script needs on start. Set it to
falseonly if your database user is not allowed to create tables, and importsql.sqlyourself.
Discord Logs
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
Webhookturns 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
| Switch | Logs |
|---|---|
Planting | Pots placed, seeds planted, pots picked up and plants destroyed by their owner. |
Harvest | Plants harvested and wild bushes picked. |
Theft | Someone harvested or destroyed a plant they do not own, or emptied someone else's drying rack. |
Processing
| Switch | Logs |
|---|---|
Drying | Buds hung on drying racks and dry buds collected. |
Packing | Joints, bags and bricks packed. |
Crossbreed | Every crossbreeding attempt, successful or not. |
Shops
| Switch | Logs |
|---|---|
Shop | Purchases at the Weed Tools shop. |
Dealer | Purchases from the seed dealer. |
Warehouses
| Switch | Logs |
|---|---|
Market | Warehouses bought and sold. |
Wallet | Wallet deposits, withdrawals and expansions bought. |
Stash | Items put in and taken out of the warehouse stash. |
Workers | Workers hired, fired and paid by hand, and changes to their settings. |
Automatic | What the workers harvest, dry and pack on their own, and their wages. Off by default. |
Admin
| Switch | Logs |
|---|---|
Settings | Everything saved in /weedadmin: settings, the shop, zones, wild bushes, joints, warehouse locations and warehouse options. |
Give | Items and warehouses given by staff. |
World | Plants 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(...)orCore.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.
| Function | Fires when |
|---|---|
Log | Any logged action happens, including the ones switched off in Config.Logs. |
Suspicious | A server check fails that a normal client never fails. |
OnPlantTouchedByStranger | Someone harvests or destroys a plant they do not own. |
OnRackRobbed | Someone takes the dry buds from an outdoor rack they do not own. |
OnPlantAction | Any plant action succeeds. |
OnSeedsReceived | A player gets seeds from the dealer, a wild bush or crossbreeding. |
OnTopPicked | A bud is picked off a plant. |
OnPlantHarvested | A plant is picked down to its last bud. |
Log
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
nilfor actions nobody triggered (worker tasks and wages). - operation: what happened, as a short code. The full list:
| Group | Operations |
|---|---|
| Plants | PLANT_PLACE, PLANT_SEED, PLANT_PICKUP, PLANT_DESTROY, HARVEST, WILD_PICK, PLANT_TOUCHED, RACK_ROBBED |
| Processing | RACK_LOAD, RACK_COLLECT, PACK, CROSSBREED |
| Shops | SHOP_BUY, DEALER_BUY |
| Warehouses | WAREHOUSE_BUY, WAREHOUSE_SELL, WAREHOUSE_UPGRADE, WAREHOUSE_DEPOSIT, WAREHOUSE_WITHDRAW, STASH_IN, STASH_OUT |
| Workers | WORKER_HIRE, WORKER_FIRE, WORKER_PAY, WORKER_PREFS, WORKER_HARVEST, WORKER_PACK, WORKER_RACK_LOAD, WORKER_RACK_COLLECT, WORKER_WAGE, WORKER_UNPAID |
| Admin | ADMIN_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 |
| Anticheat | SUSPICIOUS |
- fields: a table with any of
account,amount,item,count,identifier,successanddetails(a table with everything else about the event).
Example: every purchase into your own database table.
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,
})
endSuspicious
function OpenServer.Suspicious(source, reason, level)
end- Description: Your anticheat or staff alert.
reasonis a readable sentence such aspicked 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.
function OpenServer.Suspicious(source, reason, level)
if level < 2 then return end
exports['my_anticheat']:flag(source, 'devhub_weed: ' .. reason)
endOnPlantTouchedByStranger
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
nilwhen the owner is offline. - action:
'harvest'or'destroy'.
OnRackRobbed
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.
-- 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:
truewhen the picker is not the owner.
Example: a guidebook quest step for every harvested plant.
function OpenServer.OnPlantHarvested(source, identifier, variety, amount, info)
TriggerClientEvent('dh_guidebook:client:questProgress', source, 'weed:harvest')
endOnPlantHarvested also fires as the server event devhub_weed:server:plantHarvested, so another resource can listen without touching this file. See exports-and-events.md.