Lua Music Triggers

Discuss map ideas, techniques, and give help.
Post Reply
User avatar
PerseusSpartacus
Mjolnir Mark IV
Posts: 334
Joined: Apr 30th '12, 05:03
Location: Somewhere in the 19th Century...

So, from the very beginning, basically all music in any Marathon scenario has been set to loop over an entire level. The only exception to this rule was Rubicon X, which used a trick with ambient sounds to have music emanating from certain parts of its dream levels (generally to indicate the exit teleporter). The original Marathon games were not designed to be capable of anything other than level music and ambient/random sounds.

Aleph One, however, comes with the ability, using Lua, to trigger music to play based on certain conditions. There are several code options here:

Code: Select all

.clear()
clears the level playlist

.fade(duration)
fades out the currently playing track and clears the playlist

.play(track1 [, track2] [, ...])
appends all of the specified tracks to the end of the playlist

.stop()
stops level music and clears the playlist

.valid(track1 [, track2] [, ...])
for every track passed, return true if it exists and is playable and false otherwise
I'm sad that these functions have not been taken advantage of in any Marathon scenarios, and I'm somewhat curious as to how they work. What exactly are their abilities and limitations?

For example, suppose I had a set-piece battle in my map. Suppose I then had a Lua trigger which checked to see whether the player has entered the room where that set-piece battle is supposed to take place - if that condition is met, the game will start playing music using the .play function given above. I assume I could then have another trigger which checks to see if all the enemies in that room are dead, and if they are, it uses the .fade function to stop the music I started when the player entered the room.

Would the music, once started, continually loop? Given that those triggers above mention 'playlists', I assume it's possible to trigger a whole string of songs in order?

Sorry to seem a bit ignorant - it's just that I'm not much of a coder, and I want to try and understand what exactly can be done with these options. Thanks in advance. :D
User avatar
Chocolateer
Born on Board
Posts: 34
Joined: Jul 4th '11, 20:28
Contact:

I played around with it for a couple hours and put together a demo script for Arrival (the first level of the original Marathon scenario). Grab the latest version of the Aleph One package for Marathon and run the attached script as a solo script. I chose the original Marathon scenario because it already comes with music tracks that are played during the levels. Arrival is nice because apart from being the first level, it doesn't take long to play through if you know what you are doing.

What it does is change the music track that is played when certain actions occur:
* Entering certain polygons. The 3 areas are the starting area, the area with the narrow corridors, and the secret room.
* While reading terminals, reverts back when done
* Activating the switch that reveals the exit terminal. Once this event is triggered, the music no longer changes.

I verified that it works even when restoring a saved game. I did not try it in a network game.
PerseusSpartacus wrote: I'm sad that these functions have not been taken advantage of in any Marathon scenarios, and I'm somewhat curious as to how they work. What exactly are their abilities and limitations?
The limitations I found are that you can only play a song starting from the beginning of a track. So if you want to play a track briefly then switch back to the previous track, it isn't possible to pick up where you left off in the middle of the previous track. It also means you can't do cool things like have two versions of the same track at different tempos or have one in a major key and the other in the minor key and switch seemlessly between the two during a big fight or when the player is low in health, for example.

It also isn't possible to read what tracks are currently in the playlist, so in my sample script, for example, I had to hard-code the track that normally plays at the beginning of the level and then manually note of the track currently playing each time I changed tracks. This worked because I only ever had one track in the playlist at a time. If I had used multiple tracks, then it wouldn't have been possible to keep track of the current track and be able to switch back to it.
PerseusSpartacus wrote: For example, suppose I had a set-piece battle in my map. Suppose I then had a Lua trigger which checked to see whether the player has entered the room where that set-piece battle is supposed to take place - if that condition is met, the game will start playing music using the .play function given above. I assume I could then have another trigger which checks to see if all the enemies in that room are dead, and if they are, it uses the .fade function to stop the music I started when the player entered the room.
Yes, this is possible. The .fade() function not only stops the current song but clears the playlist too, resulting in silence after. You would then have to call .play() again to go back to the original track.
PerseusSpartacus wrote: Would the music, once started, continually loop? Given that those triggers above mention 'playlists', I assume it's possible to trigger a whole string of songs in order?
From my experimentation, it seems that once the last song in the playlist is reached, it will play that last song in a continuous loop.

I suggest you load the original Marathon scenario in Aleph One then play around with the commands yourself in the console. The tricky part for me was figuring out the names of the tracks, which are "Music/00.ogg" thru "Music/15.ogg"
Attachments
Arrival.zip
(1.58 KiB) Downloaded 310 times
User avatar
PerseusSpartacus
Mjolnir Mark IV
Posts: 334
Joined: Apr 30th '12, 05:03
Location: Somewhere in the 19th Century...

Thanks, that was very helpful. I thought the overall effect was very interesting, and there's a lot of room for having fun with this sort of thing. I'm sure it would work better if you had larger level sections for each music track, so as to ensure the song would be allowed to play itself out a bit before terminating.

Again, thanks a lot. :D
User avatar
philtron
Mjolnir Mark IV
Posts: 356
Joined: Apr 20th '12, 05:27
Contact:

I'm assuming this could be applied to multiplayer? So if someone is in the lead it plays victorious music, or when someone gets a kill it can play and audio that says "killtacular" or some such.
User avatar
Crater Creator
Vidmaster
Posts: 943
Joined: Feb 29th '08, 03:54
Contact:

I don't see a way to specify which player hears the music, so it probably plays for all players. That would rule out your first idea, since someone is always in the lead. Death messages a la "killtacular" would be better suited to sound effects, methinks.

If anyone's interested in trying new things with sound, check out the footsteps script I wrote in a different thread. I think it could make a neat addition, at least with actual new sound assets.
User avatar
Chocolateer
Born on Board
Posts: 34
Joined: Jul 4th '11, 20:28
Contact:

I tested my Arrival script out in a co-op game, and all players heard the same music. So when one person read a terminal, the music changed for everyone.

I've been thinking about it some more, and even though it isn't possible to start playback of a song from somewhere in the middle, you could still pull off some nifty tricks with some careful music composition. Anyone remember Tetris Attack for the SNES? That game changed the music whenever the player was in danger of losing, and it always played the songs from the beginning after a track change.

Here's a sample video from youtube if you don't know what I'm talking about. You can hear the track changes at 1:44, 3:17, 4:35, 5:38, 6:52, 9:09, & 10:03.
User avatar
AlumiuN
Born on Board
Posts: 11
Joined: Dec 23rd '15, 00:48
Location: New Zealand

Seeing as AlephOne has its own mixer, it probably wouldn't be too hard to allow playback of tracks from part way through (although that would mean messing with the source code, so you'd either have to get someone to merge it into the main project or distribute your own version). Alternately, you can do something like Payday 2 has, where you have a selection of loops and some tracks to bridge between them; without a dedicated format like Payday 2 has that could be a little messy as far as number of necessary files goes, but it's a solution that wouldn't require a source code change.
User avatar
Hopper
Mjolnir Mark IV
Posts: 585
Joined: May 10th '09, 17:02
Contact:

Crater Creator wrote:I don't see a way to specify which player hears the music, so it probably plays for all players.
You'd do that by changing the playlist only on the appropriate player's machine:

Code: Select all

if Players[player_who_took_the_lead].local_ then
  Music.fade(1)
  Music.play(victory_track)
end
AFAIK, just changing the music shouldn't cause OOS.
User avatar
Crater Creator
Vidmaster
Posts: 943
Joined: Feb 29th '08, 03:54
Contact:

Aha. I suppose I've trained myself to always iterate over the whole list of players. The local player hasn't seemed like a useful construct for netgames before. This gives me a new perspective; thanks! [MUp]
Post Reply