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

NPC SYSTEM#

The NPC API provides read access to the NPC configuration synced from the server. Use it to look up voice settings, personality data, and traits for any ped entity or model — whether configured explicitly or using generated defaults.

Trait caching: Optional traits use probability rolls. Results are cached in entity state (Entity(entity).state.traitRolls) and are network-synced. Call clearTraitCache to force a re-roll.

getNPCInfo#

Get complete NPC information for a ped entity or model name. Returns the configured data if a matching NPC entry exists, or generated defaults based on detected gender if not.

Syntax
exports['onex-voiceInteraction']:getNPCInfo(target)
NameTypeDescription
targetnumber | stringPed entity handle, or model name string (e.g. "mp_m_freemode_01")

Returns: { success = true, data = NPCInfo }

NPCInfo fields#

FieldTypeDescription
configtableFull NPC config entry (or generated default)
voicetable{ voice, rate, pitch, volume } — TTS voice settings
animationtable{ lipSync, gesture, returnToIdle } — animation defaults
audiotable{ maxDistance, falloffCurve, spatialAudio, volumeMultiplier }
personalitytable{ mood, speechPattern, responseStyle, traits }
traitstableArray of trait objects from personality.traits
genderstring"male" or "female"
isDefaultbooleantrue if no explicit config matched — defaults were generated
entitynumberEntity handle (when queried by handle)
modelKeystringModel hash string used as config key
Your Script
-- Query by entity handle local r = exports['onex-voiceInteraction']:getNPCInfo(pedHandle) if r.success then print("Voice:", r.data.voice.voice) print("Gender:", r.data.gender) print("Is default:", r.data.isDefault) print("Mood:", r.data.personality.mood) end -- Query by model name local r = exports['onex-voiceInteraction']:getNPCInfo("mp_m_freemode_01") if r.success then print("Default voice for freemode male:", r.data.voice.voice) end

Default config shape#

When no NPC config matches, defaults are generated:

{ voice = { voice = "en-US-GuyNeural", rate = 1.0, pitch = 1.0, volume = 1.0 }, animation = { lipSync = true, gesture = true, returnToIdle = true }, audio = { maxDistance = 30, falloffCurve = "linear", spatialAudio = true, volumeMultiplier = 1.0 }, personality = { mood = "neutral", speechPattern = "casual", responseStyle = "brief", traits = {} }, gender = "male", -- or "female", detected from ped model category = "default", isDefault = true }

Voice selection from defaults uses a pool per gender, with the entity ID modulating which pool entry is chosen — so different peds of the same model get different voices.

checkNPCTraits#

Check whether an NPC has specific traits. Required traits always return hasTrait = true. Optional traits are probability-rolled on first check and cached.

Syntax
exports['onex-voiceInteraction']:checkNPCTraits(entity, traitIds)
NameTypeDescription
entitynumberPed entity handle
traitIdsstring | string[]Single trait ID string, or array of trait ID strings

Returns: { success = true, data = { [traitId] = TraitCheckResult } }

TraitCheckResult fields#

FieldTypeDescription
hasTraitbooleanWhether the NPC has this trait
isRequiredbooleantrue if the trait is always active (probability = 100)
probabilitynumberConfigured probability (1–100)
rolledProbabilitynumberThe actual roll value used — present only on freshly rolled results
cachedbooleantrue if the result came from cache — present only on cached results
Your Script
-- Check a single trait local r = exports['onex-voiceInteraction']:checkNPCTraits(pedHandle, "drug_addict") if r.success and r.data.drug_addict.hasTrait then print("This NPC is a drug addict") end -- Check multiple traits at once local r = exports['onex-voiceInteraction']:checkNPCTraits(pedHandle, { "aggressive", "friendly", "drug_addict" }) if r.success then for traitId, result in pairs(r.data) do print(traitId, result.hasTrait, result.probability) end end

queryNPCTraits#

Query trait data by entity, tag, or definition. More flexible than checkNPCTraits — use when you need to search or inspect definitions rather than check a specific NPC.

Syntax
exports['onex-voiceInteraction']:queryNPCTraits(query)

The query table must contain exactly one of these fields (or combine entity + tag):

NameTypeDescription
query.entitynumberGet all traits configured for a specific ped
query.tagstringFilter by trait tag — combinable with entity
query.definitionstring | trueGet a specific trait definition by name, or true for all definitions
Your Script
-- Get all traits on a specific NPC local r = exports['onex-voiceInteraction']:queryNPCTraits({ entity = pedHandle }) if r.success then for _, trait in ipairs(r.data.traits) do print(trait.traitId, trait.isRequired, trait.probability) end end

Return shapes by query type#

QueryReturns
{ entity }{ traits = { ... } }
{ entity, tag }{ hasTrait = bool, matchingTraits = { ... } }
{ tag }{ npcs = { { modelHash, config, matchingTraits } } }
{ definition = "name" }{ definition = { ... } }
{ definition = true }{ definitions = { [id] = { ... } } }

clearTraitCache#

Clear the cached probability roll results for an entity. Forces fresh rolls on the next checkNPCTraits or queryNPCTraits call.

Syntax
exports['onex-voiceInteraction']:clearTraitCache(entity)
NameTypeDescription
entitynumberPed entity handle — required

Returns: { success = true, data = { cleared = 1 } }

Trait rolls are stored in entity state (Entity(entity).state.traitRolls) and are network-synced. Clearing the cache on one client affects all clients that read that entity's state.

Your Script
-- Force re-roll for a specific ped exports['onex-voiceInteraction']:clearTraitCache(pedHandle)

Last updated 4 months ago

Quick Links

All DocumentationOur Products