Page 1 of 1

Music Randomizer (4.6.0; ZScript; S_ChangeMusic)

Posted: Thu Jun 10, 2021 3:54 am
by Xtor98
Hello, dear community.
I want to ask a question about music and Zscript.
Somewhere in depths of ZDoom forum found "Music Changer" (from YouTube link), which has two music - one that replaces theme of level, another - if you attract the attention of monsters (battle music).
In parameters, you can set how many monsters (5-10, it doesn't matter) will change music.
I tried did it like in Doom 2016 - when music changes to combat, so that there are several tracks and each time one of available files ones is selected.
I couldn't do this with S_ChangeMusic function - the music is constantly being loop and game starts hard lag every second.
But I got point where level was assigned to its source track (S_ChangeMusic"*").
Can I ask knowledgeable persons to help me understand this question, how starting from the 44th line in the ZSCRIPT file to gramatically make a random selection of music without lags? To change - and nicely play. And at next battle - another one.
On the 7 line I declaring list of tracks.
File is located here.
Thanks for your attention.

Re: Music Randomizer (4.6.0; ZScript; S_ChangeMusic)

Posted: Thu Jun 10, 2021 6:50 am
by Player701
This doesn't have to do anything with random selection, the actual problem here is that you change the music every time the battle condition is triggered. You need to do it only once instead, for that you already have the variable play_music_until_array_of_actor_have_at_least_one_entry in your script. Here is the correct code for that (replace the if statement on line 45):

Code: Select all

if ((monsters_which_have_player_as_target.size() >= cvar.findcvar('amount_of_monsters_in_chase').getint() || (is_boss_joined_to_party && cvar.findcvar('take_in_account_boss_flag').getint() == 0)) && !play_music_until_array_of_actor_have_at_least_one_entry)

Re: Music Randomizer (4.6.0; ZScript; S_ChangeMusic)

Posted: Sun Jun 13, 2021 10:18 am
by Xtor98
It really works the way I expected it to. I don't understand why I was struggling for a long time with a problem whose solution was right under nose.
Thank you so much!