Need help with playing stock .mp3 as background!

Post your scripting questions / solutions here

Moderator: Moderators

Post Reply
vkdawg
Private
Posts: 9
Joined: Mon Jan 26, 2004 8:51 pm

Need help with playing stock .mp3 as background!

Post by vkdawg »

Hello all....

I'm really hoping someone can help me with this, because I'M GOING NUTS and pulling my hair out over this one!!

I've searched the forums and read tutorials til I'm blue in the face. I've been working on this to NO AVAIL all day!!

Here's what I want to do:

I want to play a stock .mp3 as the background sound/music for everyone. If possible I'd also like to set the volume of it a little past 100% (like 1.3 or something). This file is located at: C:\Program Files\EA GAMES\MOHAA\main\sound\amb_stereo\Amb_M2_SubpenInt 02.mp3

Okay.... I'd like to do this in a script, so this is what I have in my mapname.scr file:
main:

level waittill prespawn

setcvar "g_obj_alliedtext1" "xxxxxx"
setcvar "g_obj_alliedtext2" ""
setcvar "g_obj_alliedtext3" ""
setcvar "g_obj_axistext1" ""
setcvar "g_obj_axistext2" ""
setcvar "g_obj_axistext3" ""

setcvar "g_scoreboardpic" "textures/mohmenu/dmloading/xxxxxx.tga"

exec global/DMprecache.scr

exec global/ambient.scr mapname

/*
level.farplane = 3500
$world farplane 3500
$world farplane_color (.3 .3 .3)
*/

level waittill spawn
Okay, THEN, I created a folder "music" and in that folder I put the mapname.mus file. Here's the mapname.mus file:
path sound/amb_stereo

normal Amb_M2_SubpenInt02.mp3 // Default

!normal volume 1.3
!normal loop
Now, according to all the tutorials and messages I've read THAT IS SUPPOSED to do it! I have the "exec global/ambient.scr mapname" BETWEEN "level waittill prespawn" and "level waittill spawn" AND I have the mapname.mus file IN the "music" folder!!

Here's what I see in the log file:
------ Server Initialization Complete ------ 4.61 seconds
soundtrack switched to music/mapname.mus.
playing music/mapname.mus
music set to normal with fallback normal
Loading Ambient.scr
Well, I CANNOT here the .mp3 playing in the background when I play the map! I simply can't get this to work!! I've also tried putting the line: "level.script = maps/dm/mapname.scr" just above the "exec global/ambient.scr mapname" line - doesn't help.

I'm looking for help here in a few possible ways:

If someone can see what I'm doing wrong using this method (does it even work for Spearhead or is this an AA method), and can help me get it working that would be great...

OR

If someone simply knows of a way to start up one of the stock .mp3's as the background for EVERYONE for the ENTIRE map that would be great!!

Thanks
User avatar
Axion
Major General
Posts: 683
Joined: Mon Sep 29, 2003 5:14 am
Location: Northern California
Contact:

Post by Axion »

As taken from the music tutorial-

Music works a little different in MOHAA. As you can have only one .mus file playing at a time, you'll need a different system for the background music. You can use the 'tm' commands for this. The following music commands are available:

tmstart
tmstartloop
tmstop
playsong
playmp3
stopmp3

I have no idea why the commands in italic are included in the game. None of them are used in the original MOHAA scripts. The only commands you need are the ones that start with 'tm', and in most cases you'll want to use 'tmstartloop' to start a looping music. To start or change the music playing in the background by script, you need for example, the following lines:

wait 2
$player stufftext "tmstartloop sound/music/mus_04b_suspense.mp3"

below 'level waittill spawn' in your map script. I found that if I didn't add the 'wait' before the $player line, that the music would not work on the first spawn. The stufftext command means 'put this text in the player's console'. Background music is not implemented by default in multiplayer maps, but you can add it if you want to. You need to process the stufftext command to all players, for example use the following script.

level waittill spawn
wait 2

for(local.playernum = 1; local.playernum <= $player.size; local.playernum++)
{
$player[local.playernum] stufftext "tmstartloop sound/music/mus_04b_suspense.mp3"
}

Note that this is not a completely bug free method, as players don't join at the same time. You could for instance run this code in a while loop the whole time to start the music for everyone on the server.

To stop the music in single player mode use:

$player stufftext "tmstop"

and for multiplayer mode use:

for(local.playernum = 1; local.playernum <= $player.size; local.playernum++)
{
$player[local.playernum] stufftext "tmstop"
}

to stop the music in multiplayer mode.

-------------------------------------------------------------------------------
Final Notes
-------------------------------------------------------------------------------

I think this is all you need to know to get ambient sounds and music in both single player and multiplayer maps. If you don't need location depended ambient sounds you can also use

soundtrack mymapname

This will only play the 'normal' music, no 'aux' musics. You then don't have to create any triggers and don't need the global/ambient.scr in your script, but you will need a .mus file. If you have any problems with the things mentioned above, feel free to either contact me or post at the forums


It looks to me that you forgot to include some of the things from this tutorial in your script...
"The work of a thousand years is nothing but rubble."
- Dr. Carl Goerdeler (1943)
Visit my mapping site: http://www.freewebs.com/axion9
Image
vkdawg
Private
Posts: 9
Joined: Mon Jan 26, 2004 8:51 pm

Post by vkdawg »

I HAVE already studied that tutorial inside and out.

And YES, the only way I was able to get the sound to work at all was by using:
level waittill spawn
wait 2

for(local.playernum = 1; local.playernum <= $player.size; local.playernum++)
{
$player[local.playernum] stufftext "tmstartloop sound/music/mus_04b_suspense.mp3"
}
However, if you continue to read the tutorial it says:
Note that this is not a completely bug free method, as players don't join at the same time. You could for instance run this code in a while loop the whole time to start the music for everyone on the server.


When I use this method I can hear the background ONLY when I go into RCON and do a RESTART. So.... the only time I can hear the sounds is doing a RESTART - that's the ONLY way...

I don't even hear it after the first spawn - maybe the "wait 2" is not long enough?? The problem is though, even if I increase the "wait" I might hear it on the first spawn, but anyone JOINING the game would NEVER hear the background sound.

Now the tutorial says to run this code in a "while loop" to catch players as they join at different times, but I have NO IDEA how to do this.

Maybe if I could just figure out how to get that code into a "while loop" I can get it to work?? My only question is, if I put it in a "while loop", won't it just keep restarting the sound?

PLEASE HELP!

I even tried the "soundtrack mymapname" in my .scr file - that didn't do anything either!!
omniscient
Major General
Posts: 694
Joined: Tue Sep 16, 2003 12:02 am

Post by omniscient »

while(expression){
play music stuff
}
Image
Post Reply