Tutorial: Adding Music to Your MOD Civilization

After my tests and research, I got a more complete solution, I controlled the playback of music through Lua.
However, the price is that the restart button will not pop up a dialog box and will restart the game directly.
When there is a sound such as a beep, the music will stop.

Other than that, everything is fine, this is the code for the script.
This is one of my already-made mods, and subsequent updates to this script can directly view my mod:


Code:
-----------------------------------------------------------------------------------------
-- Jan 29, 2019 By HaoJun0823
-- This script comes from https://forums.civfanatics.com/threads/tutorial-adding-music-to-your-mod-civilization.621830/
-- Thanks FurionHuang,Gedemon,HerdByFate,raen.
-- Today, there is still no perfect way to add music.
-- If someone can know how to do it, please reply at the address above, thank you!
-----------------------------------------------------------------------------------------

-----------------------------------------------------------------------------------------
-- Gedemon's Script
-- Override the restart button

--2019/01/05
--If you click the Cancel button, the menu will be transparent and cannot be closed.
--So I canceled this menu and if it was triggered incorrectly, the auto save can still be called back.

-----------------------------------------------------------------------------------------
--HaoJun0823 (Randerion)
--2019/01/29
--So i try to fix all bugs which anythings can effect with playing fell.
--I maybe change something UI action like restart button (Just only this currently).
--This script just only change local machine,So you can use random things and don't need to worry other player.
--But you must to be know if you not equal local player is target leader all machine will be play audio or sound!
-----------------------------------------------------------------------------------------


local LEADER_NAME = "LEADER_FATE_QIN" --Set your Leader

function OnReallyRestart() -- Gedemon's Project copy the game lua and add a event.
    -- 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 OnEnterGame()   -- override the default callback once all the files are loaded...
--We need it to replace the restart button.



 
       ContextPtr:LookUpControl("/InGame/TopOptionsMenu/RestartButton"):RegisterCallback( Mouse.eLClick, OnReallyRestart )
       print("replace restart button!")


end

print("Randerion Audio Lua loaded:"..LEADER_NAME.." Pass Lua Check.")

-----------------------------------------------------------------------------------------
-- FurionHuang's Script
-- Stop the music when exit game.
-----------------------------------------------------------------------------------------


function OnUIExitGame() --easily to know.
    stopMusic()
end

function OnPlayerDefeatStopMusic( player, defeat, eventID) -- it's well done.
    --print("Defeat Event Activated.");
    stopMusic()

end

function OnTeamVictoryStopMusic(team, victory, eventID) -- same as the last.
    --print("Victory Event Activated.");
    stopMusic()
 
end

function OnOpenDiplomacyActionView(otherPlayerID) -- The diplomacuy panel open when your access target leader.
    --play some music use anyway for your want.
    local playerConfig:table = PlayerConfigurations[otherPlayerID]
    local leaderName = playerConfig:GetLeaderTypeName()


    if leaderName == LEADER_NAME then
  
        UI.PlaySound("Play_Leader_Music_FATE_QIN"); --YOU NEED A OTHER EVENT NAME TO DO THAT!!!!! If you don't, the game system is still wrong!
        --So please don't let the original leader music play the event.
        --Benefit: You can play any music you want, with any judgment, but you have to make sure your concert stops.
    end


end



function DiplomacyActionView_ShowIngameUI()  
    --Now you need stop your played music.
    stopDiplomacyMusic();
end

----------Events----------

function init() -- I can write this to optimize the event.

   
  print("Initialization event loading.")

  local localPlayerID:number = Game.GetLocalPlayer();
  local playerConfig:table = PlayerConfigurations[localPlayerID]
  local leaderName = playerConfig:GetLeaderTypeName()
 
  if leaderName == LEADER_NAME  then -- Consistent with the above variables
    -- There are local machine things.
    Events.LeaveGameComplete.Add(OnUIExitGame);
    Events.PlayerDefeat.Add(OnPlayerDefeatStopMusic);
    Events.TeamVictory.Add(OnTeamVictoryStopMusic);
    Events.LoadScreenClose.Add(OnEnterGame);
    LuaEvents.RestartGame.Add(OnUIExitGame);
    print(LEADER_NAME.." is local player, add event finished!")
    else
    print(LEADER_NAME.." not local player, don't need add event!")
   

  end

    --There are global game things(Other player need listen diplomacuy music)
    --So you need add a stop Diplomacy Music event for Play_Music event.
    LuaEvents.DiplomacyRibbon_OpenDiplomacyActionView.Add(OnOpenDiplomacyActionView);
    LuaEvents.DiplomacyActionView_ShowIngameUI.Add(DiplomacyActionView_ShowIngameUI);

    print("Event loaded.")
end

init()
-----------------------------------------------------------------------------------------
-- Done.
-----------------------------------------------------------------------------------------

function stopMusic() -- Use this method to stop music to fix something or you can write to other methods.

 UI.PlaySound("Stop_Music_FATE_QIN");
  --UI.PlaySound("Stop_Leader_Music_FATE_QIN_War");
   UI.PlaySound("Stop_Music_War_FATE_QIN");
    --UI.PlaySound("Stop_Leader_Music_FATE_QIN_Other");
     --UI.PlaySound("Stop_Leader_Music_FATE_QIN_Self");
      UI.PlaySound("Stop_Music_Peace_FATE_QIN");
     
      stopDiplomacyMusic()

end

function stopDiplomacyMusic()
  UI.PlaySound("Stop_Leader_Music_FATE_QIN");
end




-----------------------------------------------------------------------------------------
-- Really Done.
-----------------------------------------------------------------------------------------

That's all, you need all the workflows of FurionHuang (remove the Leader event), and then make sure your leader name and civilization correspond. At the same time, the event is completed, it is completed, you do not need to change too much content, because I have already written.

This LUA requires an XML and is loaded via the userinterface. If you don't know, you can take a look at DLC1.

Thank you very much for all Modder support! Now that we have a way to play properly (although we have lost the dialog to restart), I expect others to provide a better way to achieve the original effect!

If you have any questions, please contact me in time.
 
Last edited:
Uhh, I can't install Wwise. It requires that I have paid account on their website...
 
Uhh, I can't install Wwise. It requires that I have paid account on their website...

At the time I filled up a form to get it, don´t know if still the same, but already expired. This also worked as a team account, try to see if someone has it at the present moment.
 
I almost gave up. I did it on a civ mod and replaced the music. Even though, the last step did not work.

It was impossible to drag switches to the Game Synchs, so I left it empty.
 
Last edited:
I almost gave up. I did it on a civ mod and replaced the music. Even though, the last step did not work.

It was impossible to drag switches to the Game Synchs, so I left it empty.

Hi, don't quit, you almost there, the question is that you have to change the view, or be at the right place. Try changing views, I don't have the program anymore so I can't direct you to the right choice, but I remember to take a long time to drag that too.
 
Hi, don't quit, you almost there, the question is that you have to change the view, or be at the right place. Try changing views, I don't have the program anymore so I can't direct you to the right choice, but I remember to take a long time to drag that too.

I am stuck at the moment. In the game, the track only plays once. And that's it. No music later at all.

Just to let everyone know. The online launcher to this version does not work anymore. But you can still download the program manually from the official site in case you need it.
 
Last edited:
Did you put your era music(s) to infinite too? Since if is set to 1 will only play one time.

That's it!

Tried changing the views and still nothing...
 
I only remember to click all options for hours until find and then i did a remake and I had to find it again for hours! Maybe someone with the program can help you.

If @FurionHuang cannot explain it, then I will go to Wwise forums. Maybe that'll help.

Maybe things get better when Firaxis releases some modding tools soon. Maybe more tutorials and mods will appear etc.
 
Nice, I still can open the application, you have to change the layout (sorry not view...) to Interactive Music. But probably you got there but you cannot drag, right?

Spoiler :


upload_2019-4-30_10-28-37.png


 
upload_2017-8-29_19-30-8.png

Well, I was talking about this image. Can you drag it? It's in the SoundBank layout.
 
I think so. I could drag the events to the "Add" tab.
 
I added new to the game location and automatically adds one more. I think the drag part is on the screen I showed you before.

Spoiler :

upload_2019-4-30_11-18-44.png




EDITED: Are you sure you added all paths (or completed all steps) in Switch Container part
 
Last edited:
Zrzut ekranu (155).png

Yes, the paths are added here. But the soundbank tab is empty.
 
Are those only 4 eras to add? Can we add a Classical_Era, for instance?
 
Are those only 4 eras to add? Can we add a Classical_Era, for instance?

Yes, the default eras are that, but I actually don´t use that! One of the main reasons is that in that way I have music for all 8 eras. So you actually can ignore that part (of trying to drag/appear or the default eras), you can see my Portugal mod, I run my music by Lua: I stop the default and run at my will.

I even add war music

Spoiler :

upload_2019-4-30_13-35-20.png

 
Last edited:
Back
Top Bottom