Skip to content
KCKingdoms Connected Scripting APIScripting guides and API
Global objectClient APIGenerated

Audio

const Audio: 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.

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.

string

Name to look for.

boolean

True when the name resolves. False also while the audio system is not up.

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.

string

Name of the trigger, spelled as the game’s audio data spells it. Not text and not translated.

boolean

True when the audio system took it.

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.

string

Name of the trigger, spelled as the game’s audio data spells it.

Vector3

Where to play it, in world-space metres.

boolean

True when the audio system took it.

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.

string

Game-root path of an .ogg, with or without the extension – sounds/kcdc/<resource>/line for one a server streams.

number

Engine entity to play it on – what Player.entityId reports.

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.

boolean

True when the entity was there and took it.

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.

string

Name of the trigger, spelled as the game’s audio data spells it.

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.

boolean

True when the entity was there and took it.

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.

number

Engine entity whose sounds the parameter applies to.

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.

boolean

True when both the parameter and the entity were there.

setEntitySwitch(entityId, switchName, state): boolean

Selects one of the discrete switch states the game’s sounds branch on, for this entity alone.

number

Engine entity whose sounds the switch applies to.

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.

boolean

True when the switch, the state and the entity were all there.

stopAllOnEntity(entityId): boolean

Stops everything the entity is playing, the game’s own sounds included. Use stopOnEntity when the trigger is known.

number

Engine entity to silence.

boolean

True when the entity was there to take it.

stopOnEntity(trigger, entityId): boolean

Stops every instance of one trigger on the entity. Triggers that have already finished are not an error.

string

Name of the trigger to stop.

number

Engine entity it was played on.

boolean

True when the entity was there to take it.