Results 1 to 4 of 4

Thread: How-to: Use the play_sound_event command

  1. #1
    HouseOfHam's Avatar Primicerius
    Join Date
    Apr 2007
    Location
    Minnesota, USA
    Posts
    3,030

    Default How-to: Use the play_sound_event command

    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.
    Last edited by HouseOfHam; January 04, 2011 at 05:17 PM.
    RTR website/SVN admin

    - Settlement coordinate locator -for RTW/M2TW
    - EDB Validator v1.2.8 (Oct 16, 2012) - for RTW/M2TW
    - RTW scripting tutorials
    - n-turns per year script generator

  2. #2

    Default Re: How-to: Use the play_sound_event command

    House of Ham,

    I followed steps 1-3 as you show above, but it does not play the sound for me when I click on the city. Then when I exit the game I get the following error message "Sound event The_Die_Has_Been_Cast not found!" What am I doing wrong?

    1. background_script.txt

    monitor_event SettlementSelected SettlementName Cannae
    play_sound_event The_Die_Has_Been_Cast
    end_monitor

    2. descr_sounds_narration.txt

    event The_Die_Has_Been_Cast
    folder data/sounds
    The_Die_Has_Been_Cast.mp3
    end

    3. Added The_Die_Has_Been_Cast.mp3 to my mod's data/sounds/
    Last edited by CPT Worsham; March 13, 2011 at 05:57 PM.

  3. #3

    Default Re: How-to: Use the play_sound_event command

    Now I have the sound working, but I still get the following message when I exit the game: "Sound event The_Die_Has_Been_Cast not found!"

  4. #4
    HouseOfHam's Avatar Primicerius
    Join Date
    Apr 2007
    Location
    Minnesota, USA
    Posts
    3,030

    Default Re: How-to: Use the play_sound_event command

    I've never figured that out myself. Perhaps there is another file it needs to be added to.
    RTR website/SVN admin

    - Settlement coordinate locator -for RTW/M2TW
    - EDB Validator v1.2.8 (Oct 16, 2012) - for RTW/M2TW
    - RTW scripting tutorials
    - n-turns per year script generator

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •