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.
| Export | Returns | Does |
|---|---|---|
IsAFK() | bool | true from entry commit, before the fade |
StartAFK() | bool | Triggers AFK. Blocks ~1s for the fade |
StopAFK() | — | Exits, or aborts an entry fade |
ToggleAFK() | bool | Acceptance, not direction |
IsAFKEnabled() | bool | Whether it can trigger this session |
SetAFKEnabled(bool) | bool | Session-only, never persisted |
StartAFK returns the outcome, not an acknowledgement. false for:
| Refusal | Toast |
|---|---|
| Session switch off | yes |
| The sequence editor is open | yes |
| Ragdolling, in a cutscene, or mid player-switch | yes |
| Not in a vehicle | yes |
| No sequence applies to the vehicle | yes |
| Input cancelled the fade | no |
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
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.
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
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 event | Per-vehicle event | Token |
|---|---|---|
tafk:admin:upsertSequence | …:upsertVehicleSequence | yes |
tafk:admin:deleteSequence | …:deleteVehicleSequence | yes |
tafk:admin:toggleSequence | …:toggleVehicleSequence | no |
The global three write data.json.sequences, the per-vehicle three vehicleConfigs[<model>].sequences.
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.
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.
local state = exports['tAFK']:audioDiscovery()| Field | Type | Meaning |
|---|---|---|
tracks | array | Every file found, each with a state |
analysed | number | How many have a grid |
unanalysed | array | Never analysed |
stale | array | Analysed, but the sha256 changed |
pending | array | Everything not analysed |
leased | string | nil | The 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.
AFK Cinematics
Still stuck? Support can answer it directly.
Was this page helpful?
TIMMYG Studios