DRL > Requests For Features

More music?

<< < (2/6) > >>

Malek Deneith:
Not at the current moment as far as I'm aware. There was a plan for an sound API rework, and one of ideas pitched for that rework was something like what you're asking about, but currently it's uncertain will said rework be done or not.

Game Hunter:

--- Quote from: Pabbicus on October 09, 2011, 01:55 ---Is there any way to add something to a sort of playlist? Say, instead of it just playing the 2-3 different tracks it plays for the random floors, it plays them at random? I'm not well-versed in DoomRL's coding, but I have played around with a bit more "advanced" games like, well, most games made by Paradox.
--- End quote ---

Before, when I didn't have modding experience, I didn't think randomizing music was possible. However, now that I know how to write this sort of thing in lua, I tried constructing a function of it and, upon testing, found it to work just fine. Here's what you need to do:

Create a table for all your songs, using the same pathname that you'd use in the music configuration file. Here's an example using all the default music from randomly-generated levels:

--- Code: ---
local playlist = {
"music/11 - hangar.mid",
"music/12 - nuclear plant.mid",
"music/13 - toxin refinery.mid",
"music/14 - command control.mid",
"music/15 - phobos lab.mid",
"music/16 - central processing.mid",
"music/17 - computer station.mid",
"music/19 - military base.mid",
"music/22 - containment area.mid",
"music/24 - deimos lab.mid",
"music/26 - halls of the damned.mid",
"music/27 - spawning vats.mid",
"music/32 - slough of despair.mid",
"music/33 - pandemonium.mid",
}

--- End code ---

The function (given below), called rand_music(music_array,song_num), takes in a playlist (replace music_array with the variable name of the playlist) and returns a randomized table of that playlist. song_num indicates how large we want the randomized playlist to be, so you can have a random playlist smaller or bigger than the input playlist itself.


--- Code: ---local function rand_music(music_array,song_num)
local song_tot = table.maxn(music_array)
local song_count = 0
local music_list = {}
for i=1,math.ceil(song_num/song_tot) do
local loop_itr = math.min(song_tot,song_num)
song_num = song_num - song_tot
local song_list = music_array
for j=1,loop_itr do
idx = math.random(song_tot-j+1)
song = song_list[idx]
music_list[song_count] = song
table.remove(song_list,j)
song_count = song_count + 1
end
end
return(music_list)
end

--- End code ---

Finally, we call the function using the playlist we created:


--- Code: ---local mus = rand_music(playlist,22)

--- End code ---

The output, in this case mus, should be called for each level that you want to include randomized music for. Ideally, you want to create a randomized playlist of the same size as the number of levels you want randomized music for. Additionally, you can create several playlists in this manner (for instance, one playlist for random levels and one for the special levels).

Attached to this post is an example music.lua file, fully commented, that includes everything mentioned above, as well as an example of the Music{} table that makes use of the randomized playlist.

thelaptop:
Unlocked due to some demand on wanting to ask questions on how this can be done.

Brewtal Legend:
Thanks Laptop

Anyone actually use this?

I'm having trouble understanding exactly how to implement the random music.

Do I add these into my main music config?

Do I put "local mus = rand_music(playlist,22)" where the music track would ordinarily be placed? What's the "22" for?

Game Hunter:
There's a music.lua file attached to the post: for people who work best with examples, it's probably your best bet to figure it out. Otherwise:


* Copy the rand_music function at the beginning of your music.lua file (or whichever one you use).
* Create a array that contains all of the songs you want in the playlist. (See the first code, "local playlist = ...", as an example.)
* In order to create the randomized playlist, call the function rand_music and output it to a local variable. The first argument is the playlist array you created, and the second argument is the length of the randomized playlist you're making (if this value is more than the actual playlist, then songs will be repeated after everything plays once).
* For each level in the game that you wanted a song to be random, add one of the randomized playlist elements in place of what's usually there. For instance, if your call to rand_music looks like "local mus = rand_music(playlist,22)", then mus is a 22-element array, from mus[1] to mus[22], and each to-be-randomized level should have a different element from that array.
I hope this clears anything up. There are comments in the example file, as well.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version