Tutorial: Adding Music to Your MOD Civilization

I haven't toyed with adding Music/Sounds to the Game yet, but before doing so I wanted ask whether the process of adding new audio sounds that are for specific Civilizations/Leaders is the same/similar one as for Units or any regular sound effect. I want to add new Sounds/Music tracks that I can play/stop manually using lua, so nothing that replaces existing audio files or is specific to something. Ex: adding multiple Sounds from which I can randomly pick one to play when Event X happens.

I started to follow the script for Civilization/Leader music, but meanwhile, I changed that and started to play what I wanted. You can make all sounds (you make all sound events of stop, play, resume, and so on) and organize them in all folders you want (in Wwise) and they play in-game when you want, but in UI scripts. Im not too much into Lua events, but I play/stop music when my units move.
 
I started to follow the script for Civilization/Leader music, but meanwhile, I changed that and started to play what I wanted. You can make all sounds (you make all sound events of stop, play, resume, and so on) and organize them in all folders you want (in Wwise) and they play in-game when you want, but in UI scripts. Im not too much into Lua events, but I play/stop music when my units move.
Thanks for the Answer, raen! That sounds nice ;) !!
If I understand you correctly, you can also stop a specific sound and then resume it later whenever you want, right? I've seen the lua function that allows that for when you go to the Diplomacy Screen and select another Leader, but didn't know it can also be used for other music sounds. pretty nice!

Since you Guys have some knowledge and experience with Civ 6 audio and Wwise, I wanted to ask you if this could be possible to mod:
- I want to add a music playlist (either new sounds or existing ones in the game) that I can add/remove Music tracks from InGame using lua and organize the tracks based on anything I want, like alphabetically or based on the Civ/Era.
If that's not possible, then is it possible to:
- Play a Music Sound, and as soon as it's finished, decide which sound to Play next.
From the lua audio methods/Objects I have seen, none of that is possible, so the only way I can think of to make that possible, is to save data of all the songs (Name, and time length), and when playing a sound add a waiting function with the time length of the music sound playing right now, and when it's over, switch to next song. This is tedious work and I don't know if it would work or cause Issues like when the Game lags or something.
 
start and stop are asyncronous calls, I dont know about knowning when ends. In other words If you start 3 musics all run. In my case I use eras to get my diffrent music, and additionally, I have made a folder in wwise for my war music, and play when at war.

In wwise you can define a sequence.
 
start and stop are asyncronous calls, I dont know about knowning when ends. In other words If you start 3 musics all run. In my case I use eras to get my diffrent music, and additionally, I have made a folder in wwise for my war music, and play when at war.

In wwise you can define a sequence.
Thanks for the Infos!
 
Well I was fully prepared for disappointment, but Audiokinetic came through! I'll be adding the provided files to an upcoming tutorial I'm writing, but I want to add them here now for anyone else that stumbles upon this thread. It's too large to attach, so I've provided a Dropbox link.

Dropbox Link: Wwise v2015.9.1 (64 bit)
Download the zip, extract the 3 files to your desktop, and double click each one to run it.

I don't believe it matters in what order. A text file has also been included for explanation.

Apparently, this a temporary solution, as Audiokinetic explained their plans for the near future. Here's the quote:

Mike Drummelsmith
Head of Developer Relations - Audiokinetic Inc.
Twitter/X: @AKMikeD

We will be putting up a new method for modding games on our site soon, and CivVI will be one of those games. So when a user goes to download Wwise, they'll create their account on our site, and then they'll be able to go to a 'school' link (I'm co-opting our course system for this) and find various modding projects (courses) there. Each will come with a license key for non-commercial use to let them build larger soundbanks, with the same capabilities the core developers had.

So keep an eye out for that (follow Audiokinetic on Twitter/X for example), and then incorporate that new info when it's up for your tutorial. Having users actually have a license key will let you have projects with more than 200 assets in them.
 
Surely not the simplest solution, but seems to work:
Spoiler :

.modinfo
Code:
        <AddUserInterfaces>
            <Properties>
                <Context>InGame</Context>
            </Properties>
                <File>InGame/GCO_ModInGame.xml</File>
        </AddUserInterfaces>

GCO_ModInGame.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<Context Name="GCO_ModInGame">
    <Include File="PopupDialog"/>
    <MakeInstance Name="PopupDialog" />
</Context>

GCO_ModInGame.lua
Code:
-----------------------------------------------------------------------------------------
-- Override the restart button
-----------------------------------------------------------------------------------------
include( "PopupDialog" )

local m_kPopupDialog

function OnReallyRestart()
    -- Start a fresh game using the existing game configuration.
    LuaEvents.RestartGame() -- add the function(s) you want to call before restarting a game to this lua event : LuaEvents.RestartGame.Add(myFunction)
    Network.RestartGame()
end

function OnRestartGame()
    ContextPtr:LookUpControl("/InGame/TopOptionsMenu/"):SetHide(true)
    if (not m_kPopupDialog:IsOpen()) then
        m_kPopupDialog:AddText(      Locale.Lookup("LOC_GAME_MENU_RESTART_WARNING"))
        m_kPopupDialog:AddButton( Locale.Lookup("LOC_COMMON_DIALOG_NO_BUTTON_CAPTION"), OnNo )
        m_kPopupDialog:AddButton( Locale.Lookup("LOC_COMMON_DIALOG_YES_BUTTON_CAPTION"), OnReallyRestart, nil, nil, "PopupButtonInstanceRed" )
        m_kPopupDialog:Open()
    end
end

function OnNo()
    ContextPtr:LookUpControl("/InGame/TopOptionsMenu/"):SetHide(false)
end

function Initialize()
    m_kPopupDialog = PopupDialog:new( "ModInGame" )
end

function OnEnterGame()   -- override the default callback once all the files are loaded...
    ContextPtr:LookUpControl("/InGame/TopOptionsMenu/RestartButton"):RegisterCallback( Mouse.eLClick, OnRestartGame ) 
end
Events.LoadScreenClose.Add(OnEnterGame)

Initialize()

Many thanks to Gedemon for this essential solution. However, it's missing an all important 'ContextPtr:SetHide(false)', thus the popup remains hidden when you click the restart. Additionally, Gedemon's solution relies on hidding the main menu so the popup doesn't appear underneath it. I found a better solution that mimics the regular restart button menu behavior and puts the popup on top of the main menu. I also implemented the escape key for closing the popup. To clarify for others, yes the file name must be 'GCO_ModInGame'. This demo adds a custom function to the restart button, which prints "=== Thanks Gedemon! ===" to the console when you click restart.

GCO_ModInGame.lua:
Code:
-----------------------------------------------------------------------------------------
-- Override the restart button
-----------------------------------------------------------------------------------------
include("PopupDialog");

local m_kPopupDialog;

-- yes button.
function OnReallyRestart()

  -- add your functions here.
  LuaEvents.RestartGame.Add(function() print("=== Thanks Gedemon! ==="); end);

  LuaEvents.RestartGame();
  Network.RestartGame();
end

-- no button.
function OnNo()
  m_kPopupDialog:Close();
end

-- restart button.
function OnRestartGame()
  if (not m_kPopupDialog:IsOpen()) then
    m_kPopupDialog:AddText(  Locale.Lookup("LOC_GAME_MENU_RESTART_WARNING"));
    m_kPopupDialog:AddButton(Locale.Lookup("LOC_COMMON_DIALOG_NO_BUTTON_CAPTION"), OnNo);
    m_kPopupDialog:AddButton(Locale.Lookup("LOC_COMMON_DIALOG_YES_BUTTON_CAPTION"), OnReallyRestart, nil, nil, "PopupButtonInstanceRed");
    m_kPopupDialog:Open();
  end
  ContextPtr:ChangeParent(ContextPtr:LookUpControl("/InGame/TopOptionsMenu"));
  ContextPtr:SetHide(false);
end

-- input.
function OnInput(hInput)
  if not ContextPtr:IsHidden() and hInput:GetMessageType() == KeyEvents.KeyUp
      and hInput:GetKey() == Keys.VK_ESCAPE then
    OnNo();
  end
end

-- on LoadScreenClose.
function OnEnterGame()
  ContextPtr:SetInputHandler(OnInput, true);
  ContextPtr:LookUpControl("/InGame/TopOptionsMenu/RestartButton"):RegisterCallback(Mouse.eLClick, OnRestartGame);
end
Events.LoadScreenClose.Add(OnEnterGame);

function Initialize()
  m_kPopupDialog = PopupDialog:new("ModInGame");
end

Initialize();
 
Top Bottom