Skip to main content

Voice

Random voice lines by state. Make one per agent and add it as a sense:

:AddSense(VluxyAI.Voice.new({
	Lines = {
		Patrol = { 9113636490, 9113636491 }, -- low groans while it wanders
		Hunt = { 105926319962443 },          -- a growl now and then while it chases
		["*"] = { 9113636681 },              -- anything else
	},
	Interval = { 5, 12 },
}))

A line never repeats twice in a row when the pool has another, never talks over the line before it, and waits Interval between lines.

Functions​

new​

Voice.new(options: VoiceOptions) → Sense

Types

​

interface VoiceOptions {
Lines: {[string]: {number | string}}--

Line pools by state name: asset ids (or rbxasset:// strings). "*" is the pool for any state without its own; a state with neither is silent.

Interval: {number}?--

{ min, max } seconds between lines while in a state. Default { 6, 14 }.

OnEnter: (number | {[string]: number})?--

Chance, 0 to 1, of a line as the agent enters a state that has lines; or chances by state name, "*" for the rest (a state missing from the table gets 0.5). Default 0.5.

Volume: number?--

Default 0.8.

PitchVariation: number?--

Random spread of PlaybackSpeed around 1, so a repeated line does not sound stamped. Default 0.08.

RollOffMin: number?--

Studs heard at full volume. Default 8.

RollOffMax: number?--

Studs until silent. Default 80.

Emit: string?--

Announced with Agent:Emit as each line plays, { Line, State } as the payload, for subtitles. "" announces nothing. Default "Voice".

Play: ((
agent: Agent,
line: number | string
) → number?)?--

Plays a line your way instead (on the client, through your sound system) and returns its length in seconds. Default: a Sound under the rig's root, on the server.

Random: Random?--

Default agent.Data.Random, else a new one.

}

Errors

TypeDescription
"unknown option"
"Lines needs at least one pool"
"Interval must be { min, max } with 0 <= min <= max"

Pick​

Voice.Pick(
pool: {number | string},
last: (number | string)?,
random: Random
) → (number | string)?--

A random line from pool, never last when there is another, nil for an empty pool.

Pure.

NextDelay​

Voice.NextDelay(
interval: {number},--

{ min, max }.

random: Random
) → number--

Seconds until the next line.

Pure.

Tick​

Voice.Tick(
self: Voice,
agent: Agent,
deltaTime: number
) → ()

Checks the agent's state: on entering one with lines it may speak at once (OnEnter), and while in it speaks every Interval, never over its own last line.

Destroy​

Voice.Destroy(self: Voice) → ()

Removes the rig's voice Sound.

Show raw api
{
    "functions": [
        {
            "name": "new",
            "desc": "",
            "params": [
                {
                    "name": "options",
                    "desc": "",
                    "lua_type": "VoiceOptions"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Sense"
                }
            ],
            "function_type": "static",
            "errors": [
                {
                    "lua_type": "\"unknown option\"",
                    "desc": ""
                },
                {
                    "lua_type": "\"Lines needs at least one pool\"",
                    "desc": ""
                },
                {
                    "lua_type": "\"Interval must be { min, max } with 0 <= min <= max\"",
                    "desc": ""
                }
            ],
            "source": {
                "line": 122,
                "path": "lib/Animator/Voice.luau"
            }
        },
        {
            "name": "Pick",
            "desc": "Pure.",
            "params": [
                {
                    "name": "pool",
                    "desc": "",
                    "lua_type": "{ number | string }"
                },
                {
                    "name": "last",
                    "desc": "",
                    "lua_type": "(number | string)?"
                },
                {
                    "name": "random",
                    "desc": "",
                    "lua_type": "Random"
                }
            ],
            "returns": [
                {
                    "desc": "A random line from `pool`, never `last` when there is another, `nil` for an empty pool.",
                    "lua_type": "(number | string)?"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 153,
                "path": "lib/Animator/Voice.luau"
            }
        },
        {
            "name": "NextDelay",
            "desc": "Pure.",
            "params": [
                {
                    "name": "interval",
                    "desc": "`{ min, max }`.",
                    "lua_type": "{ number }"
                },
                {
                    "name": "random",
                    "desc": "",
                    "lua_type": "Random"
                }
            ],
            "returns": [
                {
                    "desc": "Seconds until the next line.",
                    "lua_type": "number"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 177,
                "path": "lib/Animator/Voice.luau"
            }
        },
        {
            "name": "Tick",
            "desc": "Checks the agent's state: on entering one with lines it may speak at once (`OnEnter`), and\nwhile in it speaks every `Interval`, never over its own last line.",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "Voice"
                },
                {
                    "name": "agent",
                    "desc": "",
                    "lua_type": "Agent"
                },
                {
                    "name": "deltaTime",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 274,
                "path": "lib/Animator/Voice.luau"
            }
        },
        {
            "name": "Destroy",
            "desc": "Removes the rig's voice Sound.",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "Voice"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 312,
                "path": "lib/Animator/Voice.luau"
            }
        }
    ],
    "properties": [],
    "types": [
        {
            "name": "VoiceOptions",
            "desc": "",
            "fields": [
                {
                    "name": "Lines",
                    "lua_type": "{ [string]: { number | string } }",
                    "desc": "Line pools by state name: asset ids (or `rbxasset://` strings). `\"*\"` is the pool for any state without its own; a state with neither is silent."
                },
                {
                    "name": "Interval",
                    "lua_type": "{ number }?",
                    "desc": "`{ min, max }` seconds between lines while in a state. Default `{ 6, 14 }`."
                },
                {
                    "name": "OnEnter",
                    "lua_type": "(number | { [string]: number })?",
                    "desc": "Chance, `0` to `1`, of a line as the agent enters a state that has lines; or chances by state name, `\"*\"` for the rest (a state missing from the table gets `0.5`). Default `0.5`."
                },
                {
                    "name": "Volume",
                    "lua_type": "number?",
                    "desc": "Default `0.8`."
                },
                {
                    "name": "PitchVariation",
                    "lua_type": "number?",
                    "desc": "Random spread of `PlaybackSpeed` around `1`, so a repeated line does not sound stamped. Default `0.08`."
                },
                {
                    "name": "RollOffMin",
                    "lua_type": "number?",
                    "desc": "Studs heard at full volume. Default `8`."
                },
                {
                    "name": "RollOffMax",
                    "lua_type": "number?",
                    "desc": "Studs until silent. Default `80`."
                },
                {
                    "name": "Emit",
                    "lua_type": "string?",
                    "desc": "Announced with [Agent:Emit] as each line plays, `{ Line, State }` as the payload, for subtitles. `\"\"` announces nothing. Default `\"Voice\"`."
                },
                {
                    "name": "Play",
                    "lua_type": "((agent: Agent, line: number | string) -> number?)?",
                    "desc": "Plays a line your way instead (on the client, through your sound system) and returns its length in seconds. Default: a Sound under the rig's root, on the server."
                },
                {
                    "name": "Random",
                    "lua_type": "Random?",
                    "desc": "Default `agent.Data.Random`, else a new one."
                }
            ],
            "source": {
                "line": 54,
                "path": "lib/Animator/Voice.luau"
            }
        }
    ],
    "name": "Voice",
    "desc": "Random voice lines by state. Make one per agent and add it as a sense:\n\n```lua\n:AddSense(VluxyAI.Voice.new({\n\tLines = {\n\t\tPatrol = { 9113636490, 9113636491 }, -- low groans while it wanders\n\t\tHunt = { 105926319962443 },          -- a growl now and then while it chases\n\t\t[\"*\"] = { 9113636681 },              -- anything else\n\t},\n\tInterval = { 5, 12 },\n}))\n```\n\nA line never repeats twice in a row when the pool has another, never talks over the line\nbefore it, and waits `Interval` between lines.",
    "source": {
        "line": 113,
        "path": "lib/Animator/Voice.luau"
    }
}