Duke4.net Forums: A code for music randomizer? - Duke4.net Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

A code for music randomizer?

User is offline   Anvil 

#1

Can anyone provide a code that randomly chooses one of the tracks for a map, instead of the player doing it manually? (shift+f5)

This post has been edited by Anvil: 28 November 2016 - 02:12 AM

1

User is online   Danukem 

  • Duke Plus Developer

#2

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.
0

User is offline   Hendricks266 

  • Weaponized Autism

  #3

This is special cased for the original game.

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

2

User is online   Danukem 

  • Duke Plus Developer

#4

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).
0

User is offline   Hendricks266 

  • Weaponized Autism

  #5

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.
0

User is offline   Anvil 

#6

View PostHendricks266, 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.
1

User is offline   Hendricks266 

  • Weaponized Autism

  #7

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.
0

User is offline   Anvil 

#8

I also tested Duke Forces randomizer: the track continues almost regularly when loading a game. (there is a slight stutter.)
0

User is offline   Anvil 

#9

The code works well for user maps without the 2 hacks!

This post has been edited by Anvil: 03 December 2016 - 11:46 AM

1

User is offline   Sanek 

#10

Is it possible to go backwards when choosing the tracks?
0

User is offline   Anvil 

#11

Is it possible to randomize the tracks also during the level, after each track ends?
0

User is offline   Hendricks266 

  • Weaponized Autism

  #12

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.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic


All copyrights and trademarks not owned by Voidpoint, LLC are the sole property of their respective owners. Play Ion Fury! ;) © Voidpoint, LLC

Enter your sign in name and password


Sign in options