1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

Making a custom Leader use Custom Music!

Discussion in 'Civ5 - Modding Tutorials & Reference' started by Leugi, Apr 13, 2013.

  1. Leugi

    Leugi Supreme Libertador

    Joined:
    Jan 25, 2013
    Messages:
    1,675
    Location:
    Bolivia
    So, this tutorial assumes you know how to add a new civilization with a new leader to the game and thus know how to use Modbuddy properly.

    Now that the Fall Patch is here, we can finally add music to a mod!. The process is quite simple, as it only requires some xml'ing.

    Tools you'll need
    • Modbuddy
    • Music for your new Leader

    Step 1: Import the Music with VFS=True

    So, first thing to do is import the new music you want to your mod through Modbuddy. Place both files (you'll need a Peace music and a War music) wherever you feel more comfortable. Don't forget to set VFS=True in their properties.

    MP3 or OGG should work... However, for some strange reason, my OGGs never work, so I use MP3.

    Step 2: AudioDefine!

    You'll need to add a new SoundID for your new music. The new database tables made for the Fall Patch DO NOT FOLLOW THOSE OF THE INSTALLATION FOLDERS. They have a different (and nice) structure:

    Code:
    <GameData>
    	<Audio_Sounds>
    
    		<!--Lautaro Music-->
    		<Row>
    			[B][COLOR="Green"]<SoundID>SND_LEADER_MUSIC_LAUTARO_PEACE</SoundID>[/COLOR][/B]
    			[B][COLOR="Blue"]<Filename>LautaroPeace</Filename>[/COLOR][/B]
    			<LoadType>DynamicResident</LoadType>
    		</Row>
    		<Row>
    			[B][COLOR="Green"]<SoundID>SND_LEADER_MUSIC_LAUTARO_WAR</SoundID>[/COLOR][/B]
    			[B][COLOR="Blue"]<Filename>LautaroWar</Filename>[/COLOR][/B]
    			<LoadType>DynamicResident</LoadType>
    		</Row>
    		<!--Lautaro Music-->
    	</Audio_Sounds>
    	<Audio_2DSounds>
    		<!--Lautaro Music For Audio Scripts-->
    		<Row>
    			<ScriptID>AS2D_[B]LEADER_[/B]MUSIC_[B]LAUTARO_[/B]PEACE</ScriptID>
    			[B][COLOR="Green"]<SoundID>SND_LEADER_MUSIC_LAUTARO_PEACE</SoundID>[/COLOR][/B]
    			<SoundType>GAME_MUSIC</SoundType>
    			<MinVolume>120</MinVolume>
    			<MaxVolume>120</MaxVolume>
    			<IsMusic>true</IsMusic>
    		</Row>
    		<Row>
    			<ScriptID>AS2D_[B]LEADER_[/B]MUSIC_[B]LAUTARO[/B]_WAR</ScriptID>
    			[B][COLOR="Green"]<SoundID>SND_LEADER_MUSIC_LAUTARO_WAR</SoundID>[/COLOR][/B]
    			<SoundType>GAME_MUSIC</SoundType>
    			<MinVolume>80</MinVolume>
    			<MaxVolume>80</MaxVolume>
    			<IsMusic>true</IsMusic>
    		</Row>
    		<Row>
    			<ScriptID>AS2D_AMBIENCE_[B]LEADER_LAUTARO[/B]_AMBIENCE</ScriptID>
    			[COLOR="Green"]<SoundID>SND_AMBIENCE_COAST_BED</SoundID>[/COLOR]
    			<SoundType>GAME_SFX</SoundType>
    			<Looping>true</Looping>
    			<MinVolume>60</MinVolume>
    			<MaxVolume>60</MaxVolume>
    		</Row>
    		<!--Lautaro Music-->
    	</Audio_2DSounds>
    	
    
    </GameData>
    
    This is an example code from my Mapuche mod, we're adding leader music to Lautaro, the Mapuche leader.

    In the code we're doing 2 things. First, we define what files to use. Then we're also defining where to use them (and also using a sound existant in the core game files for the ambience)

    Audio_Sound!


    First, we define which Audio sound File to use (bold blue part). The loadtype is important, as we're telling the Mod that the new sound will be loaded not at launch of the game, but at launch of the mod.

    As you may see, the way it references the file "LautaroWar" is without its extension or path.

    Check the SoundID (bold green part) There's not (yet) any specificality of the name, so name it what you want. I usually use that name structure as is the one Civ 5 uses and so its easier to remember.

    Audio_2DSounds

    Then we have the Audio_2DSounds (note, if you're making an ambience sound like a sound for a unit you'll have to use Audio_3DSounds instead).

    Now, the most important step here is the Bolded part. The way Firaxis links a ScriptID with a leader is by hard checking the Leader Type and comparing it with the ScriptID.

    So... If we have <Type>LEADER_LAUTARO</Type> on our Leaders database, our ScriptIDs have to be <ScriptID>AS2D_LEADER_MUSIC_LAUTARO_PEACE</ScriptID> and so forth for War and Ambience sounds. That's what makes all of this work

    Important Tags of the Audio Scripts.

    So, I'll not cover all of the tags here, but I'll cover the most important and basic ones:
    • ScriptID: Defines the name of the Audio Script. As said before, this is hardcoded for both leaders and civ soundtracks, so be careful with the name.
    • SoundID: Links the Script with an Audio define. Simply use the same SoundID. For using SoundIDs that already exist ingame, check "Assets/Sounds/XML/" or "Assets/DLC/Expansion2/Sounds/XML" files, so you can find the SoundIDs you need. (like with my ambience sound)
    • SoundType: This one is not always used, but I use it just in case. Check the core files for more sound types (as far as I know, if you're doing a Great Work sound it doesn't need any Soundtype)
    • MinVolume and MaxVolume: These ones are useful since our music will not necessarily be in the right volume. The default volume is 100, so if in your first test the volume is right, then you don't even need to add these ones. (lower than 100, means lower volume, higher than 100, means louder)
    • IsMusic: This one's necessary so the game recognizes your file as part of the sound track, and so it will taper it down when, for example, you meet a city-state.
    • TaperSoundtrackVolume: We're not using this one here, but if you are making Great Works this one is necessary. Its the volume of the music when this sound is playing, so you'll usually not use it or set it to 0.0 so the music cuts while playing the Great Work sound.

    Step 3: UpdateDatabase

    Just like when doing civs, leaders and units, you must set your new XML to Update the Database with ModBuddy.

    To do this, go to your Mod properties, and in the "Actions" tab you'll see an "Add" button. Click it and set the Event to "OnModActivated", the action to "UpdateDatabase", and the File to your xml file.

    Step 4: Test

    Test, and Enjoy! (or, if it didn't work, repair, test and Enjoy!)

    And there; now you only have to suffer because your mod's filesize is far too big for our happy site, but you got custom leader music!

    Important questions

    Is there a way of doing this through SQL

    I think there is, its as simple as using sql everywhere, however I have not tested this yet, so yeah.

    Well, that's it, hope you enjoy this!
     
    dylansan likes this.
  2. Putmalk

    Putmalk Deity

    Joined:
    Sep 26, 2010
    Messages:
    2,623
    Location:
    New York
    This is crazy, I remember that music was unmoddable...they finally fixed that?
     
  3. Pouakai

    Pouakai It belongs in a museum. Moderator

    Joined:
    Jun 16, 2010
    Messages:
    7,158
    Location:
    Aotearoa
    I think the difference is like with 3D wonder models - it's possible if the ID is added to the base files, but it won't work if it's done through a mod.

    If that's correct, it is modular, all you'd need to do is copy and paste the new sound ID into their respective files
     
  4. Leugi

    Leugi Supreme Libertador

    Joined:
    Jan 25, 2013
    Messages:
    1,675
    Location:
    Bolivia
    Its not that much that they fixed rather than we sort of managed how it works... Sort of...

    Yes, that's pretty much it... Though I don't consider editing base files "modular" per se, even if all you do is adding rather than modifying...

    Anyway, what didn't allow this whole music thing, is that we didn't know how on earth was the ScriptID assigned to a Leader. What I discovered is that it is automatically by adding the last part of the Leader's Type (LEADER_BELZU), it seems the game is hardcoded to search that last part within the script ID... And that's how it works.
     
  5. Apolodog

    Apolodog Chieftain

    Joined:
    Apr 18, 2013
    Messages:
    59
    My leader's custom music doesn't loop during the game. I never play civ 5 with music on so is that normal or did I make a mistake somewhere?
     
  6. Leugi

    Leugi Supreme Libertador

    Joined:
    Jan 25, 2013
    Messages:
    1,675
    Location:
    Bolivia
    Oh, that's definitively normal. The way music plays is like this:

    1. While loading, it uses the title screen (which to many becomes really boring, mind you)
    2. When you start playing, it plays the Leader Music (Peace in peace and War in War)
    3. Once the Leader Music ends, it plays generic style-related music (Asian music for all Asian civs, European music for all European civs, etc)

    So, you also must change the Civilizations music to fit that of another. So, in the XML of the civilization, you must add a <SoundtrackTag>Sweden</SoundtrackTag> if you want, say European music (you could also use England, Spain, Greece, etc; using the name of a civ with the set of music you want to copy...)
     
  7. Pouakai

    Pouakai It belongs in a museum. Moderator

    Joined:
    Jun 16, 2010
    Messages:
    7,158
    Location:
    Aotearoa
    Bit of a bump, but just thought it would be worth mentioning that the file should be backed up, since each time the files are verified or there's a patch / DLC downloaded it'll revert to the base version of the file.
     
  8. JFD

    JFD Kathigitarkh

    Joined:
    Oct 19, 2010
    Messages:
    9,130
    Location:
    The Kingdom of New Zealand
  9. Leugi

    Leugi Supreme Libertador

    Joined:
    Jan 25, 2013
    Messages:
    1,675
    Location:
    Bolivia
    Ok, with the Fall (beta) patch now available, this Tutorial has been updated! Now we can have custom music without harming the core files! :D
     
  10. ls612

    ls612 Deity Moderator

    Joined:
    Mar 10, 2008
    Messages:
    8,073
    Location:
    America
    Question: how would I tell the game to play music as the soundtrack while playing (as opposed to having it associated with just one leader)?
     
  11. Leugi

    Leugi Supreme Libertador

    Joined:
    Jan 25, 2013
    Messages:
    1,675
    Location:
    Bolivia
    I will update my "Create a Soundtrack!" tutorial, but the principle is the same, soundtracks are also named and hardcoded in a way. So, if a Civ has "Soundtracktag>America" it'll play all of the SONG_AMERICA_PEACE_xx

    forums.civfanatics.com/showthread.php?p=12438258

    http://forums.civfanatics.com/showthread.php?p=12437437

    Of course, you'd have to use Update tags instead of Row, unless you're making a whole new soundtrack
     
  12. ls612

    ls612 Deity Moderator

    Joined:
    Mar 10, 2008
    Messages:
    8,073
    Location:
    America
    But is there a way to make it so the music you add will play regardless of what civ you are playing? Or would I need to go through and add audio definitions for my new music to all of the civs soundtrack definitions? (for background, I'm trying to add some civ 3/4 music to civ 5 and would like it to play regardless of which civ you are playing)
     
  13. Leugi

    Leugi Supreme Libertador

    Joined:
    Jan 25, 2013
    Messages:
    1,675
    Location:
    Bolivia
    Well, yeah, either add the new music to all soundtracks or make all civs use the same SoundtrackTag. That shouldn't be too hard with SQL though, it could be something like this:

    Code:
    UPDATE Civilizations
    SET SoundtrackTag = 'America';
    That will make all civs have the same soundtrack... But to add a soundtrack to all others, well, its harder I think. I suppose you could simply change 4 soundtracks (as there are actually only 4) and make all European civs use the same soundtrack, all the Native American the same, and so forth...
     
  14. Gedemon

    Gedemon Modder Super Moderator

    Joined:
    Oct 4, 2004
    Messages:
    9,717
    Location:
    France
    Changing soundtrack for existing civs is a bit tricky because if you look at the audio tables before loading any mod you'll find that they are empty.

    From what I understand, the game engine pick the civilizations tracks from the cache in which are stored the data from the game XML files, not from the DB. But if a new track is defined in the database for an existing civ or leader, it will use this one.

    Now if you want to replace all tracks for a civ, you need to find out how many peace/war tracks are defined by the base game, then replace all with your tracks (if you don't have enough tracks, you'll have to define multiple entries with the same track until you reach the same number of peace/war tracks for that civ. edit: another possibility is to use the percent chance of playing tag)

    Also, I'm not sure that the SoundtrackTag is used, but I've not tried it, can someone confirm ?
     
  15. Leugi

    Leugi Supreme Libertador

    Joined:
    Jan 25, 2013
    Messages:
    1,675
    Location:
    Bolivia
    So, I suppose one could see the last Peace, Either and War numbers for each track, and add the tracks after that one.

    I think that soundtracktags are not used by official civs (so its a nice thing they added the tag itself). Official Civs use a similar model than leaders, so if its CIVILIZATION_AMERICA, it knows it has to play all SONG_AMERICA. I could test and see what happens if I change directly the CIVILIZATION_AMERICA to something else (it should not have music), and if I change SONG_AMERICA to what I changed the civ tag (it should play again).

    However, if via mod you add the Soundtracktag, it priorizes the Soundtracktag.
     
  16. ls612

    ls612 Deity Moderator

    Joined:
    Mar 10, 2008
    Messages:
    8,073
    Location:
    America
    So if I create new SoundtrackTag entries called AmericaNew, EuropeNew, etc, I could then use SQL to do replacements intelligently?

    Also, do SoundtrackTag entries use core XML syntax or something else?
     
  17. Leugi

    Leugi Supreme Libertador

    Joined:
    Jan 25, 2013
    Messages:
    1,675
    Location:
    Bolivia
    Yeah, that could work. The fancy thing about SoundtrackTags is that they work with the name (ignoring caps) in xml.

    So, if you use <SoundtrackTag>AmeRICa</SoundtrackTag>, it'll automatically relate it to all SONG_AMERICA_PEACE_xx, automatically.
     
  18. ls612

    ls612 Deity Moderator

    Joined:
    Mar 10, 2008
    Messages:
    8,073
    Location:
    America
    Cool. The 4 regions are America, Europe, Asia, and MiddleEast, correct?

    Also, do I need to have the same amount of music as the base soundtracks anymore? (ie, 26 tracks for Europe Peace, etc)
     
  19. Murphy613

    Murphy613 Prince

    Joined:
    Nov 18, 2012
    Messages:
    483
    Is ther any way to add a soundtrack?
     
  20. Leugi

    Leugi Supreme Libertador

    Joined:
    Jan 25, 2013
    Messages:
    1,675
    Location:
    Bolivia
    Ok, as promised I updated my other tutorial for the Fall Patch here:

    Creating your own Soundtrack!
     

Share This Page