Music Randomizer (4.6.0; ZScript; S_ChangeMusic)

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Music Randomizer (4.6.0; ZScript; S_ChangeMusic)

Postby Xtor98 » Thu Jun 10, 2021 3:54 am

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.
Joined: 02 Aug 2016
Location: UAC, Hell

Re: Music Randomizer (4.6.0; ZScript; S_ChangeMusic)

Postby Player701 » Thu Jun 10, 2021 6:50 am

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 allExpand view
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)
User avatar
Joined: 13 May 2009
Location: Russia
Discord: Player701#8214
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: Music Randomizer (4.6.0; ZScript; S_ChangeMusic)

Postby Xtor98 » Sun Jun 13, 2021 10:18 am

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!
Joined: 02 Aug 2016
Location: UAC, Hell

Return to Scripting

Who is online

Users browsing this forum: No registered users and 0 guests