Can anyone provide a code that randomly chooses one of the tracks for a map, instead of the player doing it manually? (shift+f5)
Page 1 of 1
A code for music randomizer?
#1 Posted 28 November 2016 - 01:37 AM
This post has been edited by Anvil: 28 November 2016 - 02:12 AM
#2 Posted 28 November 2016 - 03:45 AM
shift F5 sounds pretty damned easy, actually. I do have some code for a music randomizer that I wrote for Duke Forces. I need to sleep now but maybe I'll dig it out for you in the next few days.
#3 Posted 28 November 2016 - 12:30 PM
This is special cased for the original game.
(Gross old obsolete code you don't need anymore:)
gamevar temp 0 0 gamevar temp2 0 0 // Advances the random number generator seed a bit since EDuke32 currently never calls srand(). defstate advance_rand getticks temp andvar temp 255 whilevarn temp 0 { displayrand temp2 subvar temp 1 } ends // Randomizes the music choice on level start. gamevar music_level 0 0 gamevar music_volume 0 0 defstate apply_music setvarvar temp VOLUME setuserdef[].volume_number music_volume starttrackvar music_level setuserdef[].volume_number temp ends appendevent EVENT_ENTERLEVEL state advance_rand displayrandvar music_volume 3 ifvare music_volume 0 // episode 1 setvarvar temp 6 else setvarvar temp 10 displayrandvarvar music_level temp state apply_music endevent
(Gross old obsolete code you don't need anymore:)
Spoiler
#4 Posted 28 November 2016 - 08:13 PM
That's very good, but it has one shortcoming imo. The main reason people want a music randomizer is when starting a user map. A user map sets VOLUME to 0, so that code would limit the random music selections for user maps to the episode 1 tracks. I don't know if that can be solved without adding all of the missing tracks to the episode 1 music definition (which is what I do in my version).
#5 Posted 28 November 2016 - 11:32 PM
My code randomizes the episode as well as the level. Note the displayrandvar music_volume 3, followed by a check for episode 1 (7 levels instead of 11), then the displayrandvarvar for the level.
#6 Posted 29 November 2016 - 03:33 AM
Hendricks266, on 28 November 2016 - 12:30 PM, said:
Loading savegames will cause a slight music stutter
I tested it with OGG files: loading savegames doesn't cause a slight music stutter, it causes the track to continue from the point it was when saving instead of continuing regularly.
#7 Posted 29 November 2016 - 03:08 PM
Good point. Total Meltdown should really have a new music system, which will require some work on the savegame format. Then this should work for real.
#8 Posted 30 November 2016 - 02:11 AM
I also tested Duke Forces randomizer: the track continues almost regularly when loading a game. (there is a slight stutter.)
#9 Posted 03 December 2016 - 11:27 AM
The code works well for user maps without the 2 hacks!
This post has been edited by Anvil: 03 December 2016 - 11:46 AM
#11 Posted 22 June 2017 - 04:18 AM
Is it possible to randomize the tracks also during the level, after each track ends?
#12 Posted 22 June 2017 - 01:11 PM
There is no good way to know when tracks are finished, but thank you for asking so I can think about this when I get around to a better music system.
Share this topic:
Page 1 of 1