Gotcha. I was successful in creating/duplicating an animation and make it play custom sounds via xml editing.Ah, I read your comment, I think you were only trying to replace native sound? That's not what I'm doing. I'm trying to add a new sound and play it from the code side. It's not playing or finding the sound even though XML is correct - according to documentation.
In other words, you still need that bulky Modding Tools even for such a simple operation?edit project.mbproj
Yes, I mentioned this in my previous post but the problem was that the game didn't seem to use the XMLs. Debugging showed that it was detecting the documents, yet changes didn't actually show in-game. skins.xml is loaded the same way, and someone whom had successfully loaded a custom skins.xml before suddenly couldn't get it to work anymore, so we figured something was broken. Let me know if you are successfully able to add and play custom sounds like that right now. I just double-checked my files and it's not working for me.It is possible to play sound in game. It was hard to find how to do that though. People need to edit project.mbproj file according to the way native project.mbproj file did.
to set up a module, yes you need.In other words, you still need that bulky Modding Tools even for such a simple operation?
Firstly i added this to the module_sounds.xmlYes, I mentioned this in my previous post but the problem was that the game didn't seem to use the XMLs. Debugging showed that it was detecting the documents, yet changes didn't actually show in-game. skins.xml is loaded the same way, and someone whom had successfully loaded a custom skins.xml before suddenly couldn't get it to work anymore, so we figured something was broken. Let me know if you are successfully able to add and play custom sounds like that right now. I just double-checked my files and it's not working for me.
I'll add a section on loading the files through project.mbproj when I do get it working though.
<module_sound name="sam_musket_firing_01" sound_category="mission_foley" path="musket_firing_01.wav"/>
Well, that's bad and sad. Because there is no packaging happening anyway for audios and they are all read from disk/folder directly - and for module_strings.xml for example, you don't require to have modding tools.to set up a module, yes you need.
I guess something is not right with sound modding at the moment as Reus and you already mentioned and struggled with. Let's see if they can fix this soon. Playing a sound shouldn't be rocket science and shouldn't require hella different weird changes.- Sounds that dont have valid categories wont be played!
example:
int soundIndex = SoundEvent.GetEventIdFromString("example/voice/charge");//to avoid string operations in runtime soundIndex can be cached.
if (playOneshot)
{
MakeSound(soundIndex, MainAgent.Position, false, true, -1, -1);//plays oneshot sound at position with given parameters.
}
else
{
SoundEvent eventRef = SoundEvent.CreateEvent(soundIndex, Scene);//get a reference to sound and update parameters later.
eventRef.SetPosition(MainAgent.Position);
eventRef.Play();
}
Well, that's bad and sad
100% Agreed! This overly convoluted method should be fixed.I guess something is not right with sound modding at the moment as Reus and you already mentioned and struggled with. Let's see if they can fix this soon. Playing a sound shouldn't be rocket science and shouldn't require hella different weird changes.
namespace Shokuho
{
// Music Patching
[HarmonyPatch(typeof(MBMusicManager), MethodType.Constructor)]
public class MBMusicManagerPatch
{
private static void Postfix(MBMusicManager __instance)
{
if (!NativeConfig.DisableSound)
{
int num = (int)PsaiCore.Instance.LoadSoundtrackFromProjectFile(BasePath.Name + "Modules/Shokuho/ModuleSounds/Music/soundtrack.xml");
}
System.Diagnostics.Debug.WriteLine("Postfix loaded! (Music)");
}
}
}
I'm not sure but based on that code piece, it appears that this Instance can be called from anywhere - hence you don't need Harmony for that - you can simply call it in your OnSubmoduleLoad or somewhere else, right?Speaking of rocket science, we figured out how to use harmony to force load custom soundtrack.xml (so you can play music from your own mod folder without the need to overwrite any vanilla files.
It can be done by postfixing the path to the xml like this:
It's related to https://assetstore.unity.com/packages/tools/audio/psai-music-engine-pro-24788(Note: Not sure if related but https://csharp.hotexamples.com/examples/psai.Editor/Segment/-/php-segment-class-examples.html)
Technically yes, however, it needs to write to "_battleMode" and "_campaignMode", both of which are readonly (and then probably call Initialize), in order for it to take effect.I'm not sure but based on that code piece, it appears that this Instance can be called from anywhere - hence you don't need Harmony for that - you can simply call it in your OnSubmoduleLoad or somewhere else, right?
private readonly MBMusicManager.BattleMusicMode _battleMode;
private readonly MBMusicManager.CampaignMusicMode _campaignMode;
private MBMusicManager()
{
if (!NativeConfig.DisableSound)
{
int num = (int) PsaiCore.Instance.LoadSoundtrackFromProjectFile(BasePath.Name + "music/soundtrack.xml");
}
this._battleMode = new MBMusicManager.BattleMusicMode();
this._campaignMode = new MBMusicManager.CampaignMusicMode();
}
Yes but it's not related to that line anyway. Because return value isn't used.Technically yes, however, it needs to write to "_battleMode" and "_campaignMode", both of which are readonly (and then probably call Initialize), in order for it to take effect.
int num = (int) PsaiCore.Instance.LoadSoundtrackFromProjectFile(BasePath.Name + "music/soundtrack.xml");
this._battleMode = new MBMusicManager.BattleMusicMode(num);
this._campaignMode = new MBMusicManager.CampaignMusicMode(num);
I think you need to specify if your sounds are 3d inside your module_sounds.xml, you have to write "false" on is_2d="true"I'm having issues with fire arms. I've added the custom sound to the animations, but I am now running into a few issues.
1. Knowledge based - How do I get the sounds to sound muted with distance or add reverb?
2. Limitations - After a certain number of firearms go off in large battles, eventually all of the firearms sounds muted. Any ideas?
If anyone is interested in taking a look, you can see the mod here: https://www.nexusmods.com/mountandblade2bannerlord/mods/2742?tab=description
Actually - there was originally a bug that seems to have been resolved some time ago. This has been fixed by TW!I think you need to specify if your sounds are 3d inside your module_sounds.xml, you have to write "false" on is_2d="true"
<module_sound name="example/combat/hit" is_2d="true" sound_category="mission_combat" path="example_sound_modders.ogg" />
<base type="solution">
<file id="soln_module_sound" name="ModuleData/module_sounds.xml" type="module_sound" />
</base>
<module_sound name="serdar" is_2d="false" sound_category="alert" path="serdar.wav" />
using TaleWorlds.MountAndBlade;
using TaleWorlds.Core;
using TaleWorlds.Localization;
using TaleWorlds.Engine;
using TaleWorlds.InputSystem;
namespace serdar
{
public class SubModule : MBSubModuleBase
{
public override void OnMissionBehaviorInitialize(Mission mission)
{
if (mission.CombatType == Mission.MissionCombatType.Combat && mission.IsFriendlyMission)
{
mission.AddMissionBehavior(new SerdarBehaviour());
}
}
}
public class SerdarBehaviour : MissionBehavior
{
public override MissionBehaviorType BehaviorType => MissionBehaviorType.Other;
private SoundEvent eventRef;
public override void OnMissionTick(float dt)
{
if (InputKey.Space.IsPressed())
{
int soundIndex = SoundEvent.GetEventIdFromString("hurdaci");
Mission.Current.MakeSound(soundIndex, Mission.Current.MainAgent.Position, false, true, -1, -1);
InformationManager.DisplayMessage(new InformationMessage("hurdaci gelieah"));
}
if (InputKey.M.IsPressed())
{
if (eventRef == null || !eventRef.IsPlaying())
{
int soundIndex = SoundEvent.GetEventIdFromString("serdar");
eventRef = SoundEvent.CreateEvent(soundIndex, Mission.Current.Scene);//get a reference to sound and update parameters later.
eventRef.SetPosition(Mission.Current.MainAgent.Position);
eventRef.Play();
}
InformationManager.DisplayMessage(new InformationMessage("YAPMA NOLURSUN YABANCI DEGILIM"));
}
if (InputKey.N.IsPressed())
{
if (eventRef != null)
{
eventRef.Stop();
eventRef.Release();
}
int soundIndex = SoundEvent.GetEventIdFromString("reload_full");
eventRef = SoundEvent.CreateEvent(soundIndex, Mission.Current.Scene);//get a reference to sound and update parameters later.
eventRef.SetPosition(Mission.Current.MainAgent.Position);
eventRef.Play();
InformationManager.DisplayMessage(new InformationMessage("reloading"));
}
if (eventRef != null && eventRef.IsPlaying())
{
eventRef.SetPosition(Mission.Current.MainAgent.Position);
}
}
}
}