The play_sound_event command can be used to play any of the supported audio formats. The ones I've personally tested it with are mp3 and wav, but I imagine there are more.
CA documentation tell us this much:
Code:
---------------------------------------------------
Identifier: play_sound_event
Parameters: <event id> [<index>] [tag = <something>]
Description: Plays sound event
Sample use: play_sound_event PREBATTLE_TEST
Class: PLAY_SOUND_EVENT
Implemented: Yes
Author: Artem
---------------------------------------------------
Identifier: stop_sound_event
Parameters: <tag>
Description: Stops tagged sound events
Sample use: stop_sound_event PREBATTLE_TEST
Class: STOP_SOUND_EVENT
Implemented: Yes
Author: Artem
Parameters:
- event_id - Can be any event identifier from the DEFAULT sound bank in the descr_sounds_narration.txt file. In vanilla, these events are only used for historical battle advisor speeches. If you don't plan on including historical battles in your mod, you can remove the existing ones. Or, just add your own.
- index - ??? Oh, well, it's optional, so who cares
- tag - Optional. Can be anything you want, as long as it doesn't contain any white space characters. The only thing the tag is used for is to stop the audio before it plays to the end with the stop_sound_event command.
Simple example of how it can be used:
Announcing settlement names when player clicks on a settlement:
1. In your script, add this code:
Code:
monitor_event SettlementSelected SettlementName Asturga
play_sound_event Asturga
end_monitor
2. In descr_sounds_narration.txt, append:
Code:
event Asturga
folder data/sounds/city_names
Asturga.mp3
end
3. Add Asturga.mp3 to your mod's data/sounds/city_names folder
Slightly more complicated example which lets the user turn city names on/off on the fly (by clicking on the '?' button in the help scroll):
1. In your script, add this code:
Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; City names script
;;;;;;;;;;;;;;;;;;;;;;;;;;;
declare_counter AnnounceCityNames
declare_counter FlagAlreadyToggled
set_counter AnnounceCityNames 1
monitor_event ScrollAdviceRequested ScrollAdviceRequested help_scroll
set_counter FlagAlreadyToggled 0
if I_CompareCounter AnnounceCityNames = 0
set_counter AnnounceCityNames 1
set_counter FlagAlreadyToggled 1
end_if
if I_CompareCounter AnnounceCityNames = 1
and I_CompareCounter FlagAlreadyToggled = 0
set_counter AnnounceCityNames 0
stop_sound_event Asturga_tag
end_if
end_monitor
monitor_event SettlementSelected SettlementName Asturga
and I_CompareCounter AnnounceCityNames = 1
play_sound_event Asturga tag = Asturga_tag
end_monitor
2-3: same as before
If you want it to work for every settlement, you'll need to add a monitor and a sound event for each one, individually.
Using a script, you can add custom sounds to any combination of event/conditions.
Disclaimer: There are a few side-effects, however minor, I feel I should mention them:
1. If you quit the game back to the main menu while a sound event is playing, it'll keep playing to the end
2. If you close the game while it's playing, either with Alt-F4 or from the main menu, you'll get a CTD.
3. In the 2nd example, if you turn the feature off, you'll get an error message when closing the game, saying it could not find a sound event. If you leave it always on, everything works fine. No idea why this happens. If you can figure it out, let me know.