Documentation

Can-Check Hooks

Hook functions that run before a dyno run starts. Return false to deny with an optional reason.

Can-check hooks allow you to control who may start a run in zyke_dyno. Return false with an optional reason to deny the run and tell the player why.

Client and server hooks return true by default.

#File Locations

SideFile
Serverserver/can_checks.lua
Clientclient/can_checks.lua

Both files are unencrypted and safe to edit directly. Edit the existing functions inside Dyno.

Types / Classes

All types / classes can be found in types/types.lua. plyId is the requesting player's server ID. dynoId is the dyno's id, and vehicle the car on it.


#How Reason Strings Work

#Server-side reasons

The server sends the reason to the client, which shows it as a notification. Use a locale key, such as reason:wrongJob, or your own text with a space in it, which is shown as it is. Missing reasons fall back to "reason:actionUnavailable".

#Client-side reasons

Client reasons work the same way, and show in the panel on the dyno while the car stands on it, and as a notification when E is pressed. They provide immediate feedback; enforce trusted restrictions in the corresponding server hook. Add custom reason keys to every resource locale.

This server-side example only lets mechanics run the dynos.

Example:

lua
---@param plyId PlayerId
---@param dynoId integer
---@param vehicle integer
---@return boolean allowed
---@return string? reason
function CanRunDyno(plyId, dynoId, vehicle)
    if (not Z.isJob(plyId, "mechanic")) then return false, "reason:wrongJob" end

    return true
end

#Execution & Validation

Keep hooks synchronous and free of side effects. Returning true continues the normal flow; the built-in job, class, engine, line-up, and busy checks still apply. The server hook runs before the checks other resources register through RegisterRunCheck.

The placing tool, CreateDyno, RemoveDyno, and AbortRun are not subject to the run hooks.


#Server-Sided Hooks

All server-sided hooks are in server/can_checks.lua.

#Can Run Dyno

Called before a run starts, after the built-in checks.

Example:

lua
---@param plyId PlayerId
---@param dynoId integer
---@param vehicle integer
---@return boolean allowed
---@return string? reason
function CanRunDyno(plyId, dynoId, vehicle)
    return true
end

#Client-Sided Hooks

All client-sided hooks are in client/can_checks.lua.

#Can Run Dyno

Called every frame while the player's car stands on a dyno, so keep it cheap, and before the client asks the server to start a run. The server re-validates every run.

Example:

lua
---@param dynoId integer
---@param vehicle integer
---@return boolean allowed
---@return string? reason
function CanRunDyno(dynoId, vehicle)
    return true
end

#Server Hooks

server/hooks.lua holds OnDynoRunFinished, which runs once a run is finished and its result saved. It receives the full sheet, with sheet.driver as the player who drove it, unlike the zyke_dyno:OnRunFinished event. Add logs, job pay, or custom logic there.

Example:

lua
---@param sheet DynoSheet
function OnDynoRunFinished(sheet)
    -- Add logs, job pay or custom logic here
end