Modifying Sector Music

The place to discuss scripting and game modifications for X³: Farnham's Legacy

Moderators: Moderators for English X Forum, Scripting / Modding Moderators, Moderators for the X3:FL Forums

Post Reply
Wing2137
Posts: 24
Joined: Thu, 30. Jul 09, 08:39
xr

Modifying Sector Music

Post by Wing2137 » Wed, 17. Apr 24, 06:30

So I've run into a bit of a wall here in regards to the topic title. I was wondering if anyone more familiar with this could give me a hand?

I've been wanting to modify a certain sector to play a specific song. My plan was to do this without changing the MP3 files directly, as this particular sector is one of those sectors that uses multiple tracks (it randomizes the song that plays each time you enter it based on a small pool of tracks). I want only this sector to play the track I had in mind, which is why I didn't want to edit MP3 files since the sector uses multiple tracks. I followed the advice of X2-Illuminatus in this thread: viewtopic.php?t=245384

I was able to get this to work for sectors that have specific themes, (such as Kingdom End, Bluish Snout, Seizewell, etc.) However, the snag I've run into is trying to get this method to work on systems that use the multiple track format. The only other method I found after searching through forum posts from decades past, involved editing the galaxy map to do this. My understanding is that doing anything regarding galaxy edits require a game restart. I was hoping to avoid doing this, as I've got several thousand hours and am still enjoying my current playthrough. :(

Does anybody have any suggestions? I've really run out of ideas... The sector in question that I want to edit is Menelaus' Paradise. I know this method works as I have tested it on systems with static sector themes. It just doesn't seem to work on sectors with multiple randomized themes.

Cycrow
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 22233
Joined: Sun, 14. Nov 04, 23:26
x4

Re: Modifying Sector Music

Post by Cycrow » Wed, 17. Apr 24, 19:47

Changing it via the MD wont work, The MD is what does the random selection

You need to set the fixed music flag, so it doesn't try to change it when entering a sector.
Setting it in the map file will apply this flag automatically, otherwise, you need to do it via a script

Code: Select all

$sector -> set sector music track: <number>
$sector -> set sector music fixed: [TRUE]

Wing2137
Posts: 24
Joined: Thu, 30. Jul 09, 08:39
xr

Re: Modifying Sector Music

Post by Wing2137 » Thu, 18. Apr 24, 11:26

Are you referring to the maps file that's located in the .cat files? I'm not exactly sure how to go about editing that. I see the "x3_universe.pck" in there under the 04.cat file located in addon2 which I believe is related to editing the galaxy, and thus needing a game restart. I haven't been able to figure out how to edit those .pck files through the X3 Editor, and I wanted to avoid a game restart if at all possible. If I have misunderstood your directions however, then I apologize. As for writing it as a script, I have limited knowledge on that aspect. Though I have used XML before to edit other video games (namely C&C 3 Tiberium Wars), my abilities have been limited to editing previously created files after learning new lines of code when observing other XML files.

Basically, I understand the line of code that you posted (thanks by the way!), but I'm unsure of which XML file to add that line of code to, or if I'm supposed to create an XML file that contains that code from scratch. Is there anything else I need to add to the script to get that to function when writing a new XML? Things such as headers or titles using the brackets at the top of the file (these ones < > ). Or do I just need to use the <script> </script> with what you posted and that's it?

My apologies for all of the questions, I'm trying to learn, lol. I'm going to go take a crack at it to see if I can figure it out in the meantime. Much obliged for the assistance, Cycrow!

gav622007
Posts: 57
Joined: Sun, 21. Oct 07, 16:07
x4

Re: Modifying Sector Music

Post by gav622007 » Thu, 18. Apr 24, 12:17

viewtopic.php?f=201&t=436991
create a new script, for example "a.sector.music"

Code: Select all

001   $sector=[THIS] -> get user input: type=Var/Sector, title='select sector'
002   $sector ->set sector music track:<number>
003   $sector ->set sector music fixed: [TRUE]
004   
005   return null
instead of "<number>" the track number
run the script manually
delete the script

Cycrow
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 22233
Joined: Sun, 14. Nov 04, 23:26
x4

Re: Modifying Sector Music

Post by Cycrow » Thu, 18. Apr 24, 13:45

You cant really edit the xml directly, as it won't make alot of sense.

Instead you can use the built in script editor. Just activate it in your game then you can edit it through the interface.

The only extra thing you need to do is get the sector(s) you want to change. This will depend on how you want to change it.

For editing the maps you can use the X3 Editor 2 to extract the x3_universe file, put it in the addon2/maps directory.

Then you can activate the galaxy editor in game and edit the map via the galaxy editor. Changes to the universe file does require a restart. But there are ways to patch in the changes to an existing game, this is more complicated though.

Creating the script is the easiest way.

If however you prefer to just do it via the MD, then you could edit the sector management script and prevent the random selection working in some sectors

Wing2137
Posts: 24
Joined: Thu, 30. Jul 09, 08:39
xr

Re: Modifying Sector Music

Post by Wing2137 » Thu, 18. Apr 24, 23:38

Thanks for the assistance guys. I feel rather stupid, lol. I've had the script editor enabled for quite some time, as I've used it for other scripts people have made. It never occurred to me that I needed to use it for this task instead of editing the XML files directly... Guess I'm too used to doing the latter for other games. :gruebel:

I followed the example code that was given by gav. I'd like some feedback before I try running it. Should I run it in said sector? I couldn't find the 'select sector' option, assuming that was meant to be taken literally. So, I wrote it in manually. Does this look good to you guys?

https://imgur.com/Mi3Der8

Also, can I just edit the same script to be reused for another sector? Or do I have to recreate this script from scratch every time if I've already run it for a previous sector?

Thanks!

Cycrow
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 22233
Joined: Sun, 14. Nov 04, 23:26
x4

Re: Modifying Sector Music

Post by Cycrow » Fri, 19. Apr 24, 00:07

the get user input command will open a selection dialog where you select the sector.

so when you run it, it should then open the galaxy map, where you select the sector

another way would be to add an argument, set to Var/Sector, and do it that way (but it will work pretty much the same)

When you manually run the script, the first selection is the object to run on, just set this to "null"
you can just run the script multiple times selecting a different sector each time.

you only need to do it once in your current game for it to work. If you wanted it to work in any save game automatically, you can get the sector from the x/y coordinates instead, and use a setup script

Wing2137
Posts: 24
Joined: Thu, 30. Jul 09, 08:39
xr

Re: Modifying Sector Music

Post by Wing2137 » Fri, 19. Apr 24, 00:21

Hey it works! Thanks a bunch guys! :)

I just wanted to be absolutely certain before running the script, so I appreciate the confirmation, Cycrow.

Post Reply

Return to “X³: Farnham's Legacy - Scripts and Modding”