Skip to content

API reference

Exports, events, state bags, and server-side admin events for integrating with tAFK.

Client exports

All on exports['tAFK'], acting on the local player.

ExportReturnsDoes
IsAFK()booltrue from entry commit, before the fade
StartAFK()boolTriggers AFK. Blocks ~1s for the fade
StopAFK()—Exits, or aborts an entry fade
ToggleAFK()boolAcceptance, not direction
IsAFKEnabled()boolWhether it can trigger this session
SetAFKEnabled(bool)boolSession-only, never persisted

StartAFK returns the outcome, not an acknowledgement. false for:

RefusalToast
Session switch offyes
The sequence editor is openyes
Ragdolling, in a cutscene, or mid player-switchyes
Not in a vehicleyes
No sequence applies to the vehicleyes
Input cancelled the fadeno

A manual start arms a 3-second input grace window — input cannot cancel the fade inside it. StopAFK is not a no-op when the player is not AFK: it aborts an entry fade, so calling it just after StartAFK cancels that start.

Client events

tafk:stateChanged

lua
AddEventHandler('tafk:stateChanged', function(isAfk) end)

Local to one client, and fired before the state bag is written.

State bags

LocalPlayer.state.afk

Replicated, set on AFK enter, exit and resource start. tAFK writes it; other scripts read it.

lua
local ok = Player(playerServerId).state.afk   -- client, about anyone
local ok = Player(source).state.afk           -- server

AddStateBagChangeHandler('afk', nil, function(bagName, key, value)
    local playerId = GetPlayerFromStateBagName(bagName)  -- server id
end)

nil means they have not loaded tAFK. Treat it as "not AFK".

Server-side admin events

All gated on tlib.admin. A non-admin can fire them and nothing happens.

tafk:admin:updateSetting

lua
TriggerServerEvent('tafk:admin:updateSetting', key, value)

An unknown key or a value outside its clamp is logged to the server console and nothing is written.

Sequence events

Global eventPer-vehicle eventToken
tafk:admin:upsertSequence…:upsertVehicleSequenceyes
tafk:admin:deleteSequence…:deleteVehicleSequenceyes
tafk:admin:toggleSequence…:toggleVehicleSequenceno

The global three write data.json.sequences, the per-vehicle three vehicleConfigs[<model>].sequences.

lua
TriggerServerEvent('tafk:admin:upsertSequence', seqObject, token)
TriggerServerEvent('tafk:admin:upsertVehicleSequence', 'bati801', seqObject, token)
TriggerServerEvent('tafk:admin:toggleVehicleSequence', 'bati801', 'bati_low_pass', false)

seqObject is shaped like sequences[]; a matching id is replaced, otherwise appended, and anything invalid is rejected with the text on tafk:admin:saveResult. A script firing only the global pair silently misses every per-vehicle sequence.

The token argument

Any value you choose, echoed back verbatim. Use a fresh one per write and ignore replies that do not match. Pass nil and the write still happens, but no reply is sent.

tafk:admin:saveResult

Server → client. The only channel carrying a write's outcome.

lua
RegisterNetEvent('tafk:admin:saveResult', function(token, ok, message)
    -- message: a full sentence, nil on success
end)

Show message verbatim; do not parse it.

audioDiscovery (server export)

The state of beat analysis across every discovered track.

lua
local state = exports['tAFK']:audioDiscovery()
FieldTypeMeaning
tracksarrayEvery file found, each with a state
analysednumberHow many have a grid
unanalysedarrayNever analysed
stalearrayAnalysed, but the sha256 changed
pendingarrayEverything not analysed
leasedstring | nilThe file being analysed now

analysed is a count while the three beside it are lists; #state.analysed is not what you want.

Client config events

tafk:request_config asks for the current data.json and is answered by tafk:config_receive. It is rate-limited to one call per second per player, and a second is dropped silently — wait, do not retry.

Still stuck? Support can answer it directly.

Was this page helpful?