音乐模组制作

本页面所适用的版本可能已经过时,最后更新于2.7
(重定向自Music modding


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

Two things are needed in the Crusader Kings II\music folder:

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

Music file

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


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

Definition file

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.


No music on start issue/bug since 2.7x:

  • The songs.txt file inside the music folder requires a different name than the original (simply asongs.txt will do) or there won't be music during load/start, unless you replace the folder.
  • If you do use replace_path for the music folder in your *.mod file, then the opening song crusaderkings2_maintitle needs to be mentioned inside the songs.txt file, which wasn't the case before that patch.

Music scripting

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 }
		}		
	}
}

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
						}
					}
				}
			}
		}
	}
}

External links