Hooks
Learn how to use the hooks system.
Hooks
This resource exposes a lightweight hooks system that lets other resources influence or react to the crafting flow.
Why hooks?
- Pre-crafting control: deny or allow crafting based on your own rules (whitelists, jobs, cooldowns, zones, etc.)
- Post-crafting reactions: logging, analytics, trigger other systems.
Available hook points
-
crafting:preCraft (runnable, can veto)
- Runs right before a craft is accepted. If any handler returns a denial, the craft is stopped.
-
crafting:postCraft (emit, fire-and-forget)
- Runs after the craft has been queued/saved. Return values are ignored.
Context object
All hooks receive the same context table:
src
(number): player's source IDplayerId
(string): persistent player identifierrecipe
(table): recipe object (contains e.g.uuid
,title
,ingredients
,results
,craftingTime
)quantity
(number): amount to craftbenchType
(table): bench type (e.g.uuid
,name
,fullAccess
)benchLocation
(string): location UUIDinventory
(table, preCraft only): player's item summary (itemName => count)
Register hooks
You can register either with an inline function or by pointing to an export in your resource.
1) Register with a function (recommended)
2) Register via export (if you want to reuse the same callback)
In your resource (fxmanifest): export a function, e.g. myPreCraftCheck
.
Unregister
Return values (preCraft only)
A handler may return any of the following to influence the flow:
true
ornil
→ allow and continue to the next handlerfalse
→ stop crafting, use default messagecrafting.not_authorized
{ success = false, message = 'errors.key' }
→ stop crafting with the given translation keyfalse, 'errors.key'
→ stop crafting with the given translation key
Note: Messages are expected to be translation keys already used by the resource.
Examples
Max quantity per craft
Job whitelist
Per-recipe cooldown
Log after crafting
Advanced
Manual run/emit from other resources
If you need to trigger the hook chain yourself:
Notes
- Handlers are automatically removed when the resource that registered them stops.
- Priority: lower numbers run earlier. Default
0
. - Keep handlers fast; avoid long synchronous operations in preCraft.
- If a handler errors, it is logged and preCraft may fail with a generic error.