Onex
Onex
Home
Products
Documentation
Changelog
Login with FiveM
  • 👋 Welcome
  • Claim Purchase
  • Translations
    • Weaponmeta
    • Voice Interaction
      Integrations
      Installation
      Configuration
      Features
      Api
      Action
      Layers
      Npc
      Speech
Artifacts Tracker
  1. Onex Scripts
  2. Scripts_guides / Events
Ctrl K

EVENTS#

Events provide passive listening and alternative registration paths for the voice system. Use exports for active control (register, enable, query). Use events for observing what is happening — lifecycle notifications, transcript monitoring, and cross-resource coordination.

When to use events vs exports#

Use caseRecommended
Register an action with a callbackRegisterAction global or registerAction export
Register an action from a UI resource that has no client scriptTriggerEvent('onex-voiceInteraction:action:register', ...)
React to any command execution (logging, analytics)AddEventHandler('onex-voiceInteraction:command:executed', ...)
Monitor raw speech before matchingAddEventHandler('voicesdk:onTranscript', ...)
Detect when no command matchedAddEventHandler('onex-voiceInteraction:noMatch', ...)

Action lifecycle events#

onex-voiceInteraction:action:registered#

Fires when any action is successfully registered.

Your Script
AddEventHandler('onex-voiceInteraction:action:registered', function(name, sourceResource) print("Action registered:", name, "by", sourceResource) end)
ArgumentTypeDescription
namestringAction name
sourceResourcestringResource that registered it

onex-voiceInteraction:action:unregistered#

Fires when an action is unregistered.

Your Script
AddEventHandler('onex-voiceInteraction:action:unregistered', function(target) print("Action unregistered:", target) end)
ArgumentTypeDescription
targetstringAction name or @resource_name pattern that was unregistered

onex-voiceInteraction:action:enabled-changed#

Fires when a single action's enabled state changes.

Your Script
AddEventHandler('onex-voiceInteraction:action:enabled-changed', function(actionName, enabled) print("Action", actionName, enabled and "enabled" or "disabled") end)
ArgumentTypeDescription
actionNamestringAction name
enabledbooleanNew enabled state

onex-voiceInteraction:action:group-changed#

Fires when a group is enabled or disabled via setActionEnabled("#group_name", ...).

Your Script
AddEventHandler('onex-voiceInteraction:action:group-changed', function(groupName, enabled) print("Group", groupName, enabled and "enabled" or "disabled") end)
ArgumentTypeDescription
groupNamestringGroup name
enabledbooleanNew enabled state

onex-voiceInteraction:action:all-enabled#

Fires when setActionEnabled("*", true) clears all disabled states, restoring all actions.

Your Script
AddEventHandler('onex-voiceInteraction:action:all-enabled', function() print("All actions restored") end)

No arguments.

onex-voiceInteraction:command:executed#

Fires every time a voice command matches and executes. Useful for logging, analytics, or triggering secondary side-effects.

Your Script
AddEventHandler('onex-voiceInteraction:command:executed', function(name, def, score, tier, transcript, confidence, extractedVars) print(string.format( "Executed: %s | Score: %.2f | Tier: %d | Transcript: %s", name, score, tier, transcript )) end)
ArgumentTypeDescription
namestringAction name
deftableFull action definition
scorenumberMatch score (0.0–1.0)
tiernumberMatching tier used (1–4)
transcriptstringRecognized speech text
confidencenumberSTT confidence (0.0–1.0)
extractedVarstableVariables extracted from {placeholder} phrases

onex-voiceInteraction:noMatch#

Fires when speech was recognized but no action matched.

Your Script
AddEventHandler('onex-voiceInteraction:noMatch', function(data) print("No match for:", data.transcript, "confidence:", data.confidence) end)
FieldTypeDescription
data.transcriptstringThe unmatched speech text
data.confidencenumberSTT confidence of the transcript
data.enabledGroupstableList of currently enabled group names at time of no-match

onex-voiceInteraction:recordingStarted#

Fires when the microphone begins recording. Useful for UI feedback such as showing a recording indicator.

Your Script
AddEventHandler('onex-voiceInteraction:recordingStarted', function() -- show recording indicator end)

No arguments.

onex-voiceInteraction:error#

Fires when an internal system error occurs.

Your Script
AddEventHandler('onex-voiceInteraction:error', function(errorType, errorMessage) print("Voice system error:", errorType, errorMessage) end)
ArgumentTypeDescription
errorTypestringError category identifier
errorMessagestringHuman-readable error description

Raw transcript event#

voicesdk:onTranscript#

Fires before command matching — every time the STT engine produces a transcript. Useful for debugging, building custom matching logic, or displaying live captions.

Your Script
AddEventHandler('voicesdk:onTranscript', function(transcript, confidence) -- Fires before matching — no action has been selected yet print("Heard:", transcript, string.format("(%.0f%%)", confidence * 100)) end)
ArgumentTypeDescription
transcriptstringRaw recognized speech text
confidencenumberSTT confidence (0.0–1.0)

TTS events#

onex-voiceInteraction:tts:start#

Fires when TTS playback begins.

Your Script
AddEventHandler('onex-voiceInteraction:tts:start', function(text) print("TTS started:", text) end)
ArgumentTypeDescription
textstringText being spoken

onex-voiceInteraction:tts:end#

Fires when TTS playback finishes naturally.

Your Script
AddEventHandler('onex-voiceInteraction:tts:end', function(text) print("TTS finished:", text) end)
ArgumentTypeDescription
textstringText that was spoken

onex-voiceInteraction:tts:stop#

Fires when TTS playback is stopped early via stopSpeech().

Your Script
AddEventHandler('onex-voiceInteraction:tts:stop', function() print("TTS stopped") end)

No arguments.

onex-voiceInteraction:tts:error#

Fires when TTS synthesis or playback fails.

Your Script
AddEventHandler('onex-voiceInteraction:tts:error', function(errorType, text) print("TTS error:", errorType, "for text:", text) end)
ArgumentTypeDescription
errorTypestringError category
textstringText that failed to play

onex-voiceInteraction:tts:voices#

Fires when the voice list is available from the browser engine. Used internally by getVoices() when called without a callback.

Your Script
AddEventHandler('onex-voiceInteraction:tts:voices', function(voices) for _, voice in ipairs(voices) do print(voice.name) end end)
ArgumentTypeDescription
voicestable[]Array of available voice objects from the browser TTS engine

Audio 3D events#

onex-voiceInteraction:audio3d:start#

Fires when a 3D positional audio sound begins playing.

Your Script
AddEventHandler('onex-voiceInteraction:audio3d:start', function(soundId) print("3D audio started:", soundId) end)
ArgumentTypeDescription
soundIdstringSound identifier

onex-voiceInteraction:audio3d:end#

Fires when a 3D positional audio sound finishes.

Your Script
AddEventHandler('onex-voiceInteraction:audio3d:end', function(soundId, entity) print("3D audio ended:", soundId) end)
ArgumentTypeDescription
soundIdstringSound identifier
entitynumber | nilPed entity the sound was attached to, or nil for global sounds

onex-voiceInteraction:audio3d:error#

Fires when a 3D positional audio sound fails.

Your Script
AddEventHandler('onex-voiceInteraction:audio3d:error', function(soundId, error, entity) print("3D audio error:", soundId, error) end)
ArgumentTypeDescription
soundIdstringSound identifier
errorstringError description
entitynumber | nilPed entity the sound was attached to, or nil for global sounds

Registration via TriggerEvent#

All three action management exports have event equivalents. Use these when calling from a resource that does not have a persistent client script context (e.g. a UI frame resource).

Register an action#

Your Script
TriggerEvent('onex-voiceInteraction:action:register', { name = "buy_water", phrases = { "buy water", "give me water" }, trigger = { event = { name = "myres:buyItem", type = "server", params = { item = "water" } } }, group = "voice_shop_1" })

If registration fails, onex-voiceInteraction:action:register-failed fires with the action name and error message.

Your Script
AddEventHandler('onex-voiceInteraction:action:register-failed', function(name, errorMessage) print("Failed to register action:", name, errorMessage) end)

Unregister an action#

Your Script
TriggerEvent('onex-voiceInteraction:action:unregister', "buy_water")

Set action enabled state#

Your Script
TriggerEvent('onex-voiceInteraction:action:setEnabled', "#voice_shop_1", false) TriggerEvent('onex-voiceInteraction:action:setEnabled', "buy_water", true)

Global RegisterAction#

RegisterAction is a global function available within the same resource as the voice system scripts. It is functionally identical to the registerAction export but is required when the action's callback must reference Lua closures in the current scope.

Lua callbacks do not survive export boundaries. If your trigger uses callback = function(data) ... end, and that function references upvalues in the same file, use RegisterAction — not the export.

Your Script
-- This works: callback references a local variable local shopId = "liquor_1" RegisterAction({ name = "buy_item", phrases = { "buy {item}" }, trigger = { callback = function(data) -- shopId is accessible here because RegisterAction stays in-scope TriggerServerEvent('shop:buy', shopId, data.extractedVariables.item) end }, group = "voice_shop_liquor_1", layer = "shop" })
Your Script
-- This would break the closure: export crosses resource boundary -- exports['onex-voiceInteraction']:registerAction({ -- trigger = { callback = function(data) -- print(shopId) -- shopId is NOT accessible across export boundary -- end } -- })

RegisterAction is only available in the same resource. Use the export or event form from other resources.

Last updated 3 months ago

Quick Links

All DocumentationOur Products