Page 1 of 2

Question2 music when entering system or undocking

Posted: Mon Sep 08, 2008 4:15 pm
by pagroove
Can you let the engine play certain music when entering a certain system?
I'm aiming to make my Famous Planets OXP a total immersion OXP and plan on to make a song for each of the 10 systems as well as adding custom descriptions in the F7-screen. So when a player undocks or enters a system then Oolite has to play a certain .ogg file. Is that possible via the plist file?

Posted: Mon Sep 08, 2008 8:39 pm
by Thargoid
It'll be do-able via a (world) script. From those shipLaunchedFromStation and shipExitedWitchspace are your fellows, followed by a check as to which system you're in (via the method planet_number, with suitable music play initiation as the result of the check).

Sorry for the very quick summary answer, but I just finished a 6 hour journey and am somewhat K'd.

Posted: Mon Sep 08, 2008 10:34 pm
by pagroove
I understand. You have helped me a great deal with the adding of custom texts to the planet screen. I'il look into this music thing. Although I have a feeling that it will be off course more difficult than it looks. Well then I ask again :lol:

Posted: Tue Sep 09, 2008 11:26 am
by Svengali
The main problem is not to implement music for some events. But I think we need a way to avoid clashes between oxp-music similiar to the way Eric has used for the missionscreens. By using a switch (e.g. in Hyperradio and the next Localhero) a player can choose which oxp should play the music.

Posted: Tue Sep 09, 2008 10:25 pm
by pagroove
What I want is simple. For example when the player enters Tianve then a theme for Tianve is played. I want this to be triggered via the planetinfo.plist? If that's possible. It's a bit like X2/X3 where you have system dependent music. Of course players should be free if they want music or not. I often play with music streaming form internet radio or some mp3's in the background but it's not the same as ingame music.

Posted: Tue Sep 09, 2008 10:56 pm
by Svengali
pagroove wrote:
For example when the player enters Tianve then a theme for Tianve is played. I want this to be triggered via the planetinfo.plist?
I'll test it, but I don't think that this will work. But using JS is easy and fits perfectly. And you can implement a switch. So the player can switch it on or off. Or make it as separate musicpack. Or both. That is possible and not complicated. If you need support/assistance give me a pm.
It's a bit like X2/X3 where you have system dependent music. Of course players should be free if they want music or not. I often play with music streaming form internet radio or some mp3's in the background but it's not the same as ingame music.
I often play with over 20 different musicpacks (Hyperradio), but it is no game music, but the next Localhero version has a musicpack with gamemusic and a switch.

Posted: Wed Sep 10, 2008 5:26 am
by Thargoid
You could maybe do it via script action in the planetinfo.plist (same way that the Lave.oxp one adds its ships etc), although it wouldn't be the most elegant code. The switch should be do-able as you say (via OXPconfig I presume), but the clashing with other music/sound files being played is a little more of an intrinsic issue.

But Svengali has more experience with playing with music playing than me, so I'll let his superior knowledge take over here.

Posted: Wed Sep 10, 2008 11:42 am
by Svengali
@Thargoid: pm'ed you. And for sure I'm not sooo experienced. But if we can avoid 'possible' clashes then we should do it :-)

Posted: Wed Sep 10, 2008 4:16 pm
by Thargoid
No probs. I meant that whilst I've coded various small bits (with immense help from people along the way) I've never experimented with music (I play Oolite with the audio off and the radio on normally).

I can expect that there will be problems with clashes of different sound sources and some turning off others or over-riding them. That's the main experience I'm referring to, from the writing of HyperRadio mainly :)

Your experience in terms of coding to play music is certainly more than mine, cos mine's zero ;)

Posted: Wed Sep 10, 2008 4:33 pm
by pagroove
Well I'm planning to do some music. I made a test themesong. System dependent music via the plist would be my choice for the Famous Planets.OXP.
I want to do a total immersion OXP> Textures, planet descriptions and music.
(cause I'm also a music producer and making music is fun)

But If it isn't an elegant solution to do it via the plist file enlighten me. I'm certainly not a scripter although I'm learning sloooooowwwlly.

So if anybody want to write code that allows me to put an ogg file when you undock or hyper in Tianve just as an experiment I'm very happy.

On a side note: I also made a new breakpattern.ogg
You hear the tunnel and it's quite cool. If anyone wants to have then let me know.
8)

Posted: Wed Sep 10, 2008 5:48 pm
by Svengali
pagroove wrote:
Well I'm planning to do some music. I made a test themesong. System dependent music via the plist would be my choice for the Famous Planets.OXP.
I want to do a total immersion OXP> Textures, planet descriptions and music. (cause I'm also a music producer and making music is fun)
If I get this right it is only for the 10 planets in your Famous Planets.OXP? Maybe someday expanded (you are already using a lot bigger array :-) )?

Posted: Wed Sep 10, 2008 6:10 pm
by Thargoid
OK, after a quick play and a throw-together of code, the following general example script works.

To install it make a text file called script.js in the config folder of the FP OXP, copy the code into it and then modify it to use the sound playing code rather than the console messages (see below). You can also have it do other things as you wish, code for each planet goes between the brace pairs, before the break; .

Code: Select all

this.name = "Famous Planets Music Launch Script"; 
this.author = "PAGroove and Thargoid"; 
this.copyright = "© 2008 the Oolite team."; 
this.description = "Play selected music files when the player witchspaces into or undocks from the main station in a Famous Planet system."; 
this.version = "0.1"; 


this.shipExitedWitchspace = function() 
	{ 
	if(galaxyNumber == 0) 
		{ 
		switch(system.ID)
			{
			case 7:
				{
				player.consoleMessage("Welcome to Lave Commander.",6);
				break; 
				}
			case 147:
				{
				player.consoleMessage("Welcome to Diso Commander.",6);
				break; 
				}
			case 246:
				{
				player.consoleMessage("Welcome to Tianve Commander.",6);
				break;
				}
			} 
		}
	}	 

this.shipLaunchedFromStation = function() 
	{ 
	if(galaxyNumber == 0 && system.mainStation) 
		{ 
		switch(system.ID)
			{
			case 7:
				{
				player.consoleMessage("Launched from Lave station Commander.",6);
				break; 
				}
			case 147:
				{
				player.consoleMessage("Launched from Diso station Commander.",6);
				break; 
				}
			case 246:
				{
				player.consoleMessage("Launched from Tianve station Commander.",6);
				break;
				}
			} 
		}
	}
It's popping up the consoleMessages in lieu of playing music (as I don't have any to hand), but just replace them with Sound.playMusic("yourmusicfilename.ogg") to do your thing. As you can guess the numbers in the cases are the planet numbers from the planet list. So just copy/paste the cases to make the 10, and set the planet numbers accordingly.

Anyway a script.js amended from the above should get you started, for more triggers you can use refer to the wiki JS reference page on Systems.

Editted to add - code rejigged to use switch rather than a load of if's, may as well do it right ;)

Also having looked at the OXPConfig code and discussed with Svengali, this will be a prime candidate for compatibility there too (which I'm happy to try and assist with if you need it).

Share and enjoy...

Posted: Wed Sep 10, 2008 11:07 pm
by pagroove
LOL,

First I want to say that I cannot stress enough to point out that this IS the FRIENDLIEST BOARD ON THIS SIDE OF RIEDQUAT :D :D :D

Had a pm from Svengali with also code. It will be after next weekend till I have enough time to look into the code due to many social obligations. 8)
So don't be disappointed when I cannot work on in immediately.

Wel I was thinking for music for some of the famous planets. Making 10 new tunes is also a long process. When I produce progressive house (check my myspace) then I always take time to make sounds work. So I don't hurry this project.

But THNX all 8) :lol: :D :P

Posted: Wed Sep 10, 2008 11:52 pm
by pagroove
Wow the code is working great. I have a special Tianve tune running now!
Next week gonna make some music.!

Posted: Thu Sep 11, 2008 5:54 am
by Thargoid
In your own good time my friend, no sense to rush a masterpiece ;)

Always happy to help where I can, it's nice to be able to give a little something back for all the assistance I've received (and still receive) in getting my OXP's out there.

I'll look at expanding the skeleton code to make it compatible with OXPConfig and send you a suggestion script when I have time. In the meantime happy composing 8)