Random Elevator Music (like in ROTT :D)

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.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
User avatar
Lexus Alyus
Posts: 4220
Joined: Tue Jul 15, 2003 5:07 pm
Location: Nottingham, UK
Contact:

Random Elevator Music (like in ROTT :D)

Post by Lexus Alyus »

Greetings,

I'm wondering how to change the music, but not all the time, just randomly every so often, like sometimes it changes, but sometimes it doesn't. Does that make sense? Probably not... as an example, look to the elevators in ROTT (the old Dos version as I've never played the remade modern version). I've created my elevator script that always changes the music, but how do I make it random so it sometimes changes the music (with a longer delay) and sometimes doesn't change the music (with a shorter delay)? Preferably not changing the music happening more often than changing the music.

Here's my always-changing-music-ROTT-elevator script:

Code: Select all

script 5 (void)
{
Thing_Stop(0);
SetPlayerProperty(0, 1, PROP_FROZEN);
SetLineSpecial(1, 0);
LocalSetMusic("GOINGUP"); 
delay(575);
Teleport_NoFog(35,0);
Radius_Quake(1,10,0,1,0);
SetPlayerProperty(0, 0, PROP_FROZEN);
SetLineSpecial(1, Door_Animated, 0, 1, 4);
LocalSetMusic( "OWW");
}
Ty in advance.

:twisted:
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: Random Elevator Music (like in ROTT :D)

Post by Jarewill »

You could use the "random" function to randomize the song happening.

For example:

Code: Select all

If(random(1,4)==1){LocalSetMusic("GOINGUP"); delay(575);}
Else{delay(375);}
Place this instead of:

Code: Select all

LocalSetMusic("GOINGUP");
delay(575);
It picks a random number from 1 to 4 and changes the music if the number picked is 1.
So it should change the music with a 25% chance.

It should work, though I haven't tested it yet.
User avatar
Lexus Alyus
Posts: 4220
Joined: Tue Jul 15, 2003 5:07 pm
Location: Nottingham, UK
Contact:

Re: Random Elevator Music (like in ROTT :D)

Post by Lexus Alyus »

Cool, this works perfectly and exactly as I wanted :) Thanks a lot for the help. I fugured it would be something like that, but didn't know exactly how to implement random like this (my programming knowledge is practically non-existant :D).

Here's the final script I used, just in case anyone wants to do the same:

Code: Select all

{
Thing_Stop(0);
SetPlayerProperty(0, 1, PROP_FROZEN);
SetLineSpecial(1, 0);
If(random(1,4)==1)
	{
	LocalSetMusic("GOINGUP"); 
	delay(575);
	LocalSetMusic( "OWW");
	}
Else
	{
	delay(250);
	}
Teleport_NoFog(35,0);
Radius_Quake(1,10,0,1,0);
SetPlayerProperty(0, 0, PROP_FROZEN);
SetLineSpecial(1, Door_Animated, 0, 1, 8);
}
I freezed the palyer because it's otherwie possible to run out of the lift door before it closes, which looks silly when you mysteriously teleport to another lift. I also changed the inside door to change to a blank special to stop you from being able to open the door while the lift is in motion. Now I just need to play the lift moving sound at the beginning, which will be pretty easy.

Thanks again Jarewill, if I ever finish this then I'll definitely credit you :)

:twisted:
Post Reply

Return to “Scripting”