Page 1 of 1

Music for area - trigger on/off when player entering/leaving

Posted: Fri Aug 07, 2020 1:31 pm
by Sat42
I made a parallel thread over at OldUnreal forums, if the answer arrives there first, I will post the solution here.


Title says it all: I have a corridor (of sorts) of convenient length leading to a bar; I want music (proper .umx, not sound) to kick in when the player enters the area, and the same track to fade away when the player exits the area. If the player backtracks for another visit, same music must kick in again and when leaving the area the music once more must fade away.

Of course the "fade in" trigger must be a bit further in than the "fade out" trigger (with what I've been playing with anyway).

That is the setup I am having trouble with, because I didn't have much time yet to look around so I am asking: how do you achieve the above, in such a way that the "fade in" and "fade out" music triggers can be triggered as much as one wants? (so there's always music in the bar, and never outside)

I would love a reply soon as I intend to share a little surprise map with my Dad next week for his birthday :P

Is there any ready-made, vanilla solution for triggering the same music track on/off when entering/leaving an area? It has to be (indefinitely) repeatable.

(Meanwhile I am trying to finish the actual map...)
Thanks for any help!

Re: Music for area - trigger on/off when player entering/leaving

Posted: Fri Aug 07, 2020 2:58 pm
by Terraniux
This is very easily done! Lots of my maps have this same idea, and not only with sound but with lights as well.... I'll prepare a map for you ;)

Re: Music for area - trigger on/off when player entering/leaving

Posted: Fri Aug 07, 2020 3:08 pm
by Sat42
Terraniux wrote:
Fri Aug 07, 2020 2:58 pm
This is very easily done! Lots of my maps have this same idea, and not only with sound but with lights as well.... I'll prepare a map for you ;)
That is great to hear, thanks a lot Terraniux!! :o Looking forward to a working example, once I have the template it will be so useful! (including for lights you say? even more useful!)

Re: Music for area - trigger on/off when player entering/leaving

Posted: Fri Aug 07, 2020 6:08 pm
by Terraniux
Try this! ( See attachment)

A little explaination:

1 Before starting, type "killpawns" in console to get rid of the bots.
2 Some triggers have intervals of 5 seconds ( toggle) and some of 1 minute to hear at least the music for a moment.
3 Left 1 room for you open to toy with as practice =)


You can edit however you like :)

Hope this helps... yell if something is unclear

Regards Terraniux

Re: Music for area - trigger on/off when player entering/leaving

Posted: Sat Aug 08, 2020 12:59 pm
by Sat42
Terraniux wrote:
Fri Aug 07, 2020 6:08 pm
Try this! ( See attachment)

A little explaination:

1 Before starting, type "killpawns" in console to get rid of the bots.
2 Some triggers have intervals of 5 seconds ( toggle) and some of 1 minute to hear at least the music for a moment.
3 Left 1 room for you open to toy with as practice =)


You can edit however you like :)

Hope this helps... yell if something is unclear

Regards Terraniux
Brilliant stuff this is! Thanks a lot for your help Terraniux!! :D
I played around to see how things work, I love that you integrated different triggers for the purpose of demonstration, that's awesome!

I see why I had problems too: turns out you can simply rely on Blank.umx to shut down the music whereas I was trying with the MusicEvent's bSilence property (never got it to work).
The best thing about your test map is it shows how you can easily add interactivity too (with the lights also): it's not just about an area music setup, but playing with switches etc. Gives me new ideas (beyond the bar I mentioned) :tu:

Thanks again for your help and I hope others will easily find this thread to benefit from your test map too!
P.S.: I like your custom .umx tracks!

Cheers :)

Re: Music for area - trigger on/off when player entering/leaving

Posted: Sat Aug 08, 2020 3:20 pm
by Terraniux
I've build entire disco's based on this concept! Great stuff! Haha :mrgreen:

Glad I could help.


Regards Terraniux

Re: Music for area - trigger on/off when player entering/leaving

Posted: Sat Aug 08, 2020 7:51 pm
by Sat42
:tu: Yeah I dig the disco concept too and thanks to gopostal I got a Disco Ball in the game too! 8)


To wrap things up here, I would like to share another solution I got over at OldUnreal:
Yrex got back to me with an elegant solution - a custom actor called literally AreaMusic, it's not online tested but for anyone making SP maps it's great - basically the actor allows you to define the music that will play in a zone (defined by a ZoneInfo actor) and so you enter the zone the music plays, you exit and the music can change/stop depending on what you told the AreaMusic to do in another zone.

It's not for interactivity, but for literally defining an ambient track for an area that doesn't require dynamic change of tracks it is probably the simplest solution.

Link to thread:
https://www.oldunreal.com/cgi-bin/yabb2 ... 1596751038

Direct link to yrex's test map with his custom AreaMusic actor:


Love this community! :D

EDIT: topic title can be marked as "[SOLVED]"

Re: Music for area - trigger on/off when player entering/leaving

Posted: Sat Aug 08, 2020 8:07 pm
by Red_Fist
I think you type

killall bot
or
killall bots

I get confused from addbot 8 or addbots 8

Re: Music for area - trigger on/off when player entering/leaving

Posted: Sat Aug 08, 2020 11:42 pm
by Barbie
Sat42 wrote:
Sat Aug 08, 2020 7:51 pm
custom AreaMusic actor
For the ones interested in this:
Source code of Actor 'AreaMusic'
Show

Code: Select all

//=============================================================================
// AreaMusic. Not tested online.
//=============================================================================
class AreaMusic expands Info;

struct ZoneMusic
{
	var() ZoneInfo Zone;
	var() Music Song;
	var() byte SongSection;
	var() byte CdTrack;
	var() EMusicTransition Transition;
};

var() ZoneMusic ZoneSongs[32];

var PlayerPawn player;
var ZoneInfo oldPlayerZone;

function PostBeginPlay()
{
	SetTimer(1,false);
}

function Timer()
{
	local Pawn P;
	for(P=Level.PawnList;P!=none;P=P.NextPawn)
	{
		if(PlayerPawn(P) != none && Spectator(P)==none)
		{
			player = PlayerPawn(P);
			break;
		}
	}
}

function Tick(float deltaTime)
{
	local byte i;
	
	if(player != none)
	{
		if(player.Region.Zone != oldPlayerZone)
		{
			for(i=0;i<32;i++)
			{
				if(ZoneSongs[i].Zone == player.Region.Zone)
				{
					player.ClientSetMusic( ZoneSongs[i].Song, ZoneSongs[i].SongSection,
						ZoneSongs[i].CdTrack, ZoneSongs[i].Transition );
					break;
				}
			}
			
			oldPlayerZone = player.Region.Zone;
		}
	}
}
<smart aleck mode>
Because Tick() is called multiple times per second and music change is not needed within milliseconds, I would have preferred Timer() for checking the Zone. Timer() is cheaper than Tick().
And because music selection is done by polling what is the worst proceed, I would have used the Zone Events ActorEntered() and ActorLeaving(). Event driven procedures are cheaper than polling.
</smart aleck mode>

Re: Music for area - trigger on/off when player entering/leaving

Posted: Sun Aug 09, 2020 8:11 am
by sektor2111
Barbie wrote:
Sat Aug 08, 2020 11:42 pm
I would have used the Zone Events ActorEntered() and ActorLeaving(). Event driven procedures are cheaper than polling.
Entirely agree, that's why a zone has entry code and exit code, not only for physics checks.

Re: Music for area - trigger on/off when player entering/leaving

Posted: Sun Aug 09, 2020 11:30 am
by Sat42
sektor2111 wrote:
Sun Aug 09, 2020 8:11 am
Barbie wrote:
Sat Aug 08, 2020 11:42 pm
I would have used the Zone Events ActorEntered() and ActorLeaving(). Event driven procedures are cheaper than polling.
Entirely agree, that's why a zone has entry code and exit code, not only for physics checks.
A bit above my head I'm afraid!
Certainly for SP the AreaMusic actor code shared above is fine, I can imagine you are thinking about online play. If one of you can make an "online tested" optimised version, feel free to do so.

Thanks for raising awareness to the Zone Events ActorEntered() and ActorLeaving(), I didn't know about them beyond, implicitly, the physics checks between zones.

Re: Music for area - trigger on/off when player entering/leaving

Posted: Sun Aug 09, 2020 7:43 pm
by Barbie
The problem of that code is that it is designed for a single player only (and works fine then). Let's switch to multi player: should all players get the same music? If so and Player A is in Zone 1 with music alpha and Player B in Zone 2 with music beta, what music should be played for both?

So this makes sense only, if different players can get different music. In this case above code has to be changed.
Sat42 wrote:
Sun Aug 09, 2020 11:30 am
Thanks for raising awareness to the Zone Events ActorEntered() and ActorLeaving()
These events can only used by code. But there is a possibility to raise an Event, when a player enters a zone: it is at ZoneInfo>ZonePlayerEvent.

Re: Music for area - trigger on/off when player entering/leaving

Posted: Mon Aug 10, 2020 9:03 am
by Sat42
Barbie wrote:
Sun Aug 09, 2020 7:43 pm
The problem of that code is that it is designed for a single player only (and works fine then). Let's switch to multi player: should all players get the same music? If so and Player A is in Zone 1 with music alpha and Player B in Zone 2 with music beta, what music should be played for both?

So this makes sense only, if different players can get different music. In this case above code has to be changed.
Sat42 wrote:
Sun Aug 09, 2020 11:30 am
Thanks for raising awareness to the Zone Events ActorEntered() and ActorLeaving()
These events can only used by code. But there is a possibility to raise an Event, when a player enters a zone: it is at ZoneInfo>ZonePlayerEvent.
You're making a lot of sense, thanks for elaborating! Maybe someone will be willing to pick this up and make the changes required for multiplayer?
Then we can all just use that (also for coop on otherwise SP maps).