Audio
constAudio:object
Defined in: client/api.d.ts:1377
The game’s own sound triggers, played at this machine. A trigger is a name the game’s audio data declares – a_o_bell_kkut_kostelni, c_torch_whoosh1, f_ge_cough_woman – standing for an FMOD event. The full vocabulary is Libs/GameAudio/*.xml in IPL_GameData.pak, with the gameplay-facing subset listed in Libs/Tables/GameAudio/SkaldAtlTrigger.xml. Nothing here is replicated: a sound everyone should hear is one the server tells every client to play. Every call returns false while the audio system is not up, which is the case before a world is loaded, and for a trigger name the audio data does not declare.
Type Declaration
Section titled “Type Declaration”hasTrigger()
Section titled “hasTrigger()”hasTrigger(
trigger):boolean
Asks the audio system whether it knows a trigger by this name, without playing it. A patch or another mod can change what is declared, so a resource that ships names can fail early rather than silently.
Parameters
Section titled “Parameters”trigger
Section titled “trigger”string
Name to look for.
Returns
Section titled “Returns”boolean
True when the name resolves. False also while the audio system is not up.
play()
Section titled “play()”play(
trigger):boolean
Plays a trigger with no position: heard at full volume wherever the player is, like a UI cue. It goes on the one global audio object every 2D sound in the game shares, which is why it cannot be stopped again.
Parameters
Section titled “Parameters”trigger
Section titled “trigger”string
Name of the trigger, spelled as the game’s audio data spells it. Not text and not translated.
Returns
Section titled “Returns”boolean
True when the audio system took it.
playAt()
Section titled “playAt()”playAt(
trigger,position):boolean
Plays a trigger once at a point in the world, positioned and attenuated against the player’s ears. The sound is handed to the engine and forgotten: it stays where it was put, plays to its end, and cannot be stopped or moved. Occlusion is ignored rather than ray-traced, so a wall between the point and the player does not silence it.
Parameters
Section titled “Parameters”trigger
Section titled “trigger”string
Name of the trigger, spelled as the game’s audio data spells it.
position
Section titled “position”Where to play it, in world-space metres.
Returns
Section titled “Returns”boolean
True when the audio system took it.
playFile()
Section titled “playFile()”playFile(
file,entityId,purpose?):boolean
Plays a sound file on an entity, positioned and attenuated like the game’s own spoken lines and under the same volume settings. A file streamed by the server plays exactly like one the game ships. An entity takes one file per 0.1 seconds.
Parameters
Section titled “Parameters”string
Game-root path of an .ogg, with or without the extension – sounds/kcdc/<resource>/line for one a server streams.
entityId
Section titled “entityId”number
Engine entity to play it on – what Player.entityId reports.
purpose?
Section titled “purpose?”string
Which of the game’s voice host events carries it: inner, 10, 20, 35, 50, 100, 200 (a bark heard up to that many metres), sfp_dialog, sfp_cutscene or sfp_music. Defaults to 50.
Returns
Section titled “Returns”boolean
True when the entity was there and took it.
playOnEntity()
Section titled “playOnEntity()”playOnEntity(
trigger,entityId):boolean
Plays a trigger on an entity, giving it an audio component if it has none. The sound follows the entity for as long as it lasts and can be stopped again by name, which is what anything attached to a body, a horse or a prop wants.
Parameters
Section titled “Parameters”trigger
Section titled “trigger”string
Name of the trigger, spelled as the game’s audio data spells it.
entityId
Section titled “entityId”number
Engine entity to hang it on – what Player.entityId reports. Entity ids are reused, so one is only meaningful while the entity is alive.
Returns
Section titled “Returns”boolean
True when the entity was there and took it.
setEntityParameter()
Section titled “setEntityParameter()”setEntityParameter(
entityId,parameter,value):boolean
Sets one of the continuous parameters the game’s FMOD events read, on this entity’s sounds alone. It affects what is already playing as well as what starts later.
Parameters
Section titled “Parameters”entityId
Section titled “entityId”number
Engine entity whose sounds the parameter applies to.
parameter
Section titled “parameter”string
Name of the continuous parameter, as Libs/Tables/GameAudio/SkaldAtlRtpc.xml lists it – horse_speed, player_stamina, wind_velocity.
number
What to set it to. The range is whatever the FMOD event expects.
Returns
Section titled “Returns”boolean
True when both the parameter and the entity were there.
setEntitySwitch()
Section titled “setEntitySwitch()”setEntitySwitch(
entityId,switchName,state):boolean
Selects one of the discrete switch states the game’s sounds branch on, for this entity alone.
Parameters
Section titled “Parameters”entityId
Section titled “entityId”number
Engine entity whose sounds the switch applies to.
switchName
Section titled “switchName”string
Name of the switch, as Libs/GameAudio/g_switches.xml declares it – sword_mat, bow_type.
string
Which of that switch’s states to select. States belong to their switch, so the same name under a different switch is a different state.
Returns
Section titled “Returns”boolean
True when the switch, the state and the entity were all there.
stopAllOnEntity()
Section titled “stopAllOnEntity()”stopAllOnEntity(
entityId):boolean
Stops everything the entity is playing, the game’s own sounds included. Use stopOnEntity when the trigger is known.
Parameters
Section titled “Parameters”entityId
Section titled “entityId”number
Engine entity to silence.
Returns
Section titled “Returns”boolean
True when the entity was there to take it.
stopOnEntity()
Section titled “stopOnEntity()”stopOnEntity(
trigger,entityId):boolean
Stops every instance of one trigger on the entity. Triggers that have already finished are not an error.
Parameters
Section titled “Parameters”trigger
Section titled “trigger”string
Name of the trigger to stop.
entityId
Section titled “entityId”number
Engine entity it was played on.
Returns
Section titled “Returns”boolean
True when the entity was there to take it.