Jump to content

How to make a mod choose from a pool of files randomly?


Recommended Posts

Hello fellow modders!

 

I am trying to create a simple mod that picks a sound file from a pool of sound files to play upon leveling up in Fallout 4. This is kind of a stepping stone project for me for bigger projects that rely on random number generation. I have some experience with XEdit, but I am kind of new to making my own mods. I couldn't find any good modder's resource/library of scripts for Fallout 4, so if someone can point me in the right direction I would appreciate it. Here is my main question:

 

How do I use XEdit for random number generation (in this project's case, use random number generation to pick a sound file from a pool of files and set it as the level up sound file)?

 

Thank you!

Edited by talamoana
Link to comment
Share on other sites

This is more of a scripting problem, not xEdit per se. I haven’t done enough Papyrus scripting to be of much help in this case, but you might want to look at the current scripts handling leveling. I think it has “tutorial” in its name, but it has been a while since I last looked at the vanilla scripts.
Link to comment
Share on other sites

This is more of a scripting problem, not xEdit per se. I haven’t done enough Papyrus scripting to be of much help in this case, but you might want to look at the current scripts handling leveling. I think it has “tutorial” in its name, but it has been a while since I last looked at the vanilla scripts.

Thanks for pointing me in the right direction. I managed to find some good example scripts to learn from. I am pretty excited for this small random number generation project. I shall keep you guys posted :)

Link to comment
Share on other sites

Zorkaz is right about SoundDescriptors, you can add as many Music Tracks as you want to a custom one, and sounds will be picked up randomly. And you can attach conditions to both if you want them to match the player's level. This can very probably be done directly in XEdit, I can't tell you exactly how though, as I only use XEdit to polish and clean up my mods but generally mod in the CK.

 

If you're looking for a script to attach to some object in the world, you could use something like this:

Sound Property MySound01 Auto
Sound Property MySound02 Auto
Sound Property MySound03 Auto
Sound Property MySound04 Auto
Sound Property MySound05 Auto
Sound Property MySound06 Auto
Actor Property PlayerRef Auto

Int iCount
Int iSoundInstance
Int iPlayerLevel

Event OnLoad()
	iCount = Utility.RandomInt(0, 2)
	ActorBase PlayerBase = PlayerRef.GetBaseObject() as ActorBase
	iPlayerLevel = PlayerBase.GetLevel()
	If iPlayerLevel <= 9
		If iCount == 0
			iSoundInstance = MySound01.Play(Self)
		ElseIf iCount == 1
			iSoundInstance = MySound02.Play(Self)
		ElseIf iCount == 2
			iSoundInstance = MySound03.Play(Self)
		EndIf
	ElseIf (iPlayerLevel >= 10)&& (iPlayerLevel <= 19)
		If iCount == 0
			iSoundInstance = MySound04.Play(Self)
		ElseIf iCount == 1
			iSoundInstance = MySound05.Play(Self)
		ElseIf iCount == 2
			iSoundInstance = MySound06.Play(Self)
		EndIf
	EndIf
EndEvent

Event OnCellDetach()
	Sound.StopInstance(iSoundInstance)
EndEvent

This covers player level up to 19 but you could go as high as you want by simply adding more "ElseIf" to match levels above 20.

 

And if you're looking for libraries of scripts for F04, I really don't know any. But there are plenty around for Skyrim, they're just as good for learning because Papyrus really hasn't changed much between Skyrim and F04, and the few differences are easy to pinpoint by searching the CK's wiki.

 

Take a look at Darkfox127's scripting tutorials here on Nexus, they're really good at making you understand the basics to get started.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...