Music modding

From Crusader Kings II Wiki
Jump to navigation Jump to search

It is fairly simple to add or change music in Crusader Kings II.

Two things are needed in the music folder:

  • a music file, saved in the Vorbis (.ogg) format (.mp3 is not supported)
  • a definition (text) file, saved in .txt format, referencing the music file.


Music file[edit | edit source]

Since patch 2.7x the sample rate of the music file has to be 44100 Hz, as otherwise songs have a scratchy sound or don't seem to play in game anymore.

To convert to ogg format, VLC media player can be used:

  • In Media menu, select Convert / Save...
  • Click Add to select the music file (note: only supports one song at a time)
  • Click Convert / Save
  • Select profile Audio - Vorbis (OGG)
  • Click Browse to select a destination file
  • Click Start and wait for encoding to finish


Alternatively, the open-source downloadable tool Audacity can be used.

Definition file[edit | edit source]

In the base game the music files are defined in songs.txt, which is located in the Crusader Kings II\music folder. Music which is added by DLCs such as Hymns of Abraham or Songs of the Caliph is defined in a .txt file within the music folder of DLC's zip file. Songs are defined using a similar system to events. The simplest are those found in the base game, and look something like this:

song = {
	name = "crusaderkings2_maintitle.ogg"
	song_name = "Crusader Kings 2 Maintitle"
	
	chance = {
		modifier = {
			factor = 1
		}		
	}
	volume = 0.48
}

Each song has:

  • a name, which corresponds to the .ogg file being used.
  • a song_name, which can be displayed to the player
  • a factor within a chance clause which defines how likely it is to be played. Songs in the base game all carry a factor of 1, while those added in DLCs tend to have a larger factor (thus making them play more often).
  • a volume to adjust the audio level.


Music scripting[edit | edit source]

It is possible to change the probability that a song will play based on certain conditions. Most of the music-based DLCs add music which is exclusive to a particular culture/culture group or religion/religion group. This is achieved by adding conditions to the modifier clause. For example, the song England Anno 1066 from the Songs of Albion DLC uses the following code:

song = {
	name = "englandanno1066.ogg"
	
	chance = {
		factor = 2
		modifier = {
			factor = 0
			NOT = {	culture = english }
			NOT = {	culture = saxon }
		}		
	}
        volume = 0.45
}

This gives it a probability factor of 2 (i.e. makes it twice as likely to play as a track in the base game), but restricts it to only play when the player's character is either English or Anglo-Saxon by multiplying the factor by 0 when that is not the case (2 × 0 = 0).

The conditions used are the same as those used in events, so can be incredibly elaborate or be based on very specific triggers.

The free Songs of Yuletide DLC uses the clause NOT = { real_month_of_year = 11 } to reduce the chance to 0 in any month other than December.

The songs in Songs of the Holy Land each carry two modifier clauses: one multiplies the base factor (in this case 5) by 0.1 (5 × 0.1 = 0.5) if there is not currently a crusade; the other multiplies it by 2 (5 × 2 = 10) if there is a crusade and the player is currently in the target kingdom (e.g. leading troops in the crusade or is in their capital, which is within the target kingdom).

song = {
	name = "ascalon.ogg"
	
	chance = {
		factor = 5
		modifier = {
			factor = 0.1
			has_called_crusade = no
		}
		modifier = {
			factor = 2
			crusade_target = {
				ROOT = {
					location = {
						kingdom = {
							title = PREVPREVPREV
						}
					}
				}
			}
		}
	}
        volume = 0.45
}


No music on start/launch (since patch 2.7x) and how to prevent that issue[edit | edit source]

  • When only adding songs to the existing music (and hence not using replace_path inside the *.mod file):
In such case the defintion file inside the music folder requires a different name to the original songs.txt file.
That text file can have its own single name or simply a single letter added to it. For example "asongs.txt" will do.  
In such case a song file requires to be named after the opening song "crusaderkings2_maintitle" and for that to be mentioned inside the definition (songs.txt) file of the mod.

External links[edit | edit source]