UE1 - UT RMFXMusicTrigger (Enhanced MusicEvent trigger)

  • Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

RoninMastaFX

Unreal/UT Vet from Day 1
Heya! :) As part of the UT: Forgotten Classics BP, for one level, I need to code an advanced MusicEvent trigger, to allow multiple songs to be played w/o the use of a trigger needed to be activated. It plays the songs in order that they are listed (Song0 to Song9, 10 song slots), and the option to loop back to the first song once the looping is complete.

This is my code so far (it's based from the MusicEvent trigger, since extending it would cause some issues in the long run ^^ ):

Code:
//=========================================================
// RMFXMusicTrigger (Enhanced MusicEvent Trigger)
// Made by:  Mitchell "RoninMastaFX" LeBlanc
// Exclusively for UT: Forgotten Classics Bonus Pack
// Made in 2010
// Based from "MusicEvent" Copyright (c) Epic Games, Inc. & Digital Extremes
//=========================================================

class RMFXMusicTrigger extends Triggers

// Variables
var() music            Song0;
var() music            Song1;
var() music            Song2;
var() music            Song3;
var() music            Song4;
var() music            Song5;
var() music            Song6;
var() music            Song7;
var() music            Song8;
var() music            Song9;
var() byte             SongSection;
var() byte             CdTrack;
var() EMusicTransition Transition;
var() bool             bSilence;
var() bool             bOnceOnly;
var() bool             bAffectAllPlayers;
var() bool             bUseMultipleSongs;
var() bool             bLoopMultipleSongs;

// When gameplay starts
function BeginPlay()
{
	if( Song0==None )
	{
		Song0 = Level.Song0;
	}
	if( Song1==None )
	{
		Song1 = Level.Song1;
	}
	if( Song2==None )
	{
		Song2 = Level.Song2;
	}
	if( Song3==None )
	{
		Song3 = Level.Song3;
	}
	if( Song4==None )
	{
		Song4 = Level.Song4;
	}
	if( Song5==None )
	{
		Song5 = Level.Song5;
	}
	if( Song6==None )
	{
		Song6 = Level.Song6;
	}
	if( Song7==None )
	{
		Song7 = Level.Song7;
	}
	if( Song8==None )
	{
		Song8 = Level.Song8;
	}
	if( Song9==None )
	{
		Song9 = Level.Song9;
	}
	if( bSilence )
	{
		SongSection = 255;
		CdTrack     = 255;
	}
}

// When triggered
function Trigger( actor Other, pawn EventInstigator )
{
	local PlayerPawn P;
	local Pawn A;

	if( bAffectAllPlayers )
	{
		A = Level.PawnList;
		While ( A != None )
		{
			if ( A.IsA('PlayerPawn') )
				PlayerPawn(A).ClientSetMusic( Song0, Song1, Song2, Song3, Song4, Song5, Song6, Song7, Song8, Song9, SongSection, CdTrack, Transition );
			A = A.nextPawn;
		}
	}
	else
	{
		// Only affect the one player
		P = PlayerPawn(EventInstigator);
		if( P==None )
			return;
			
		// Go to music
		P.ClientSetMusic( Song0, Song1, Song2, Song3, Song4, Song5, Song6, Song7, Song8, Song9, SongSection, CdTrack, Transition );
	}	

	// Turn off if once-only
	if( bOnceOnly )
	{
		SetCollision(false,false,false);
		disable( 'Trigger' );
	}

        // Play multiple songs in order (Song0 to Song9)
	if( bUseMultipleSongs )
	{

        }

	// Loop back to Song0
	if( bLoopMultipleSongs )
	{

        }
}

defaultproperties
{
     CdTrack=255
     Transition=MTRAN_Fade
     bAffectAllPlayers=True
     bUseMultipleSongs=False
     bLoopMultipleSongs=False
}

I have left the "bUseMultipleSongs" & "bLoopMultipleSongs" booleans blank for now, as I don't want to code up something that proves itself useless. ^^ =/ Therefore, I politely ask someone to help me fill in those 2 blanks, and spot any typos or errors if need be! I am only a novice coder, so I still have a *LOT* to learn, but I am getting there slowly. ;)

Any help will be *MUCH* appreciated! :)

Take care for now, ^^
RoninMastaFX
 
Last edited:

Gizzy

The Banhammer Cometh
May 30, 2009
195
0
0
United Kingdom
Ok.. I'll have a crack at bLoopMultipleSongs. Since I only code weapons, I can try some pseudo code..:(

// Loop back to Song0
if( bLoopMultipleSongs )
{
If Song9 is currently playing, and it has finished
Change the song to Song0
If Song9 isn't playing
Then do nothing
}

That's my idea. Might be a much better solution though. (One that actually involves code)
Might not even need the last two lines either...
 
Last edited:

RoninMastaFX

Unreal/UT Vet from Day 1
Code:
//==============================================================================
// Enhanced MusicEvent Trigger
// Made by:  Mitchell "RoninMastaFX" LeBlanc & Gershom "BlackCheetah" Ikpe
// Exclusively for UT: Forgotten Classics Bonus Pack
// Made in 2010
// Based from "MusicEvent" Copyright (c) Epic Games, Inc. & Digital Extremes
//==============================================================================

class EnhancedMusicEvent extends mutator;

// Variables
var config Struct MusicSong
{
	var() string           SongName;
	var() float            SongDuration;
} SongInfo[9];

var() Music Song[9];

var() float LastSongTime;
var() PlayerPawn       Listener;
var() byte	       TrackNumber;
var() byte             SongSection;
var() byte             CdTrack;
var() EMusicTransition Transition;
var() bool             bSilence;
var() bool             bOnceOnly;
var() bool             bAffectAllPlayers;
var() bool             bUseMultipleSongs;
var bool bPlaying;

// When gameplay starts
function BeginPlay()
{

	local int i;

	for( i = 0; i<9; i++)
	{
		if(Songinfo[i].songname != "")
			song[i] = Music(DynamicLoadObject(Songinfo[i].songname, class'Music'));
	}
	if( song[0] ==None )
	{
		Song[0] = Level.Song;
	}
	if( bSilence )
	{
		SongSection = 255;
		CdTrack     = 255;
	}

	Disable('Tick');
}

// When triggered
function modifyplayer( pawn other )
{
	local PlayerPawn P;
	local Pawn A;

	if(bPlaying == true)
	{
		super.modifyplayer(other);
		return;
	}

	bPlaying = true;

	if( bAffectAllPlayers )
	{
		A = Level.PawnList;
		While ( A != None )
		{
			if ( A.IsA('PlayerPawn') )
				PlayerPawn(A).ClientSetMusic( Song[0], SongSection, CdTrack, Transition );
			A = A.nextPawn;
		}

		TrackNumber++;
	}
	else
	{
		// Only affect the one player
		P = PlayerPawn(other);
		if( P==None )
			return;
			
		// Go to music
		P.ClientSetMusic( Song[0], SongSection, CdTrack, Transition );
		Listener = P;
		TrackNumber++;
	}	

	// Turn off if once-only
	if( bOnceOnly )
	{
		SetCollision(false,false,false);
		disable( 'Trigger' );
		Disable('Tick');
	}

        // Play multiple songs in order (Song0 to Song9)
	if( bUseMultipleSongs )
	{
		Enable('Tick');
        }
}

function Tick(float delta)
{
	local PlayerPawn P;
	local Pawn A;

	if( SongInfo[tracknumber].SongDuration > level.timeseconds - LastSongTime )
		return;
	
	LastSongTime = Level.timeseconds;

	if( bAffectAllPlayers )
	{
		A = Level.PawnList;
		While ( A != None )
		{
			if ( A.IsA('PlayerPawn') )
				PlayerPawn(A).ClientSetMusic( Song[tracknumber], SongSection, CdTrack, Transition );
			A = A.nextPawn;
		}

		TrackNumber++;
	}
	else
	{
		// Only affect the one player
		P = Listener;
		if( P==None )
			return;
			
		// Go to music
		P.ClientSetMusic( Song[tracknumber], SongSection, CdTrack, Transition );
		TrackNumber++;
	}

	if( Tracknumber > 9)
		Tracknumber = 0;
}

defaultproperties
{
     CdTrack=255
     Transition=MTRAN_Fade
     bAffectAllPlayers=True
     bUseMultipleSongs=True
}

Code has been perfected by BlackCheetah! :D Many thanks to him! :)

Do whatever with this code...I don't really care (although credits to me and BlackCheetah would be nice ;) )
 

Attachments

  • EnhancedMusicEvent.zip
    2.4 KB · Views: 4

War_Master

Member
May 27, 2005
702
0
16
In the for loop you're looking for 10 slots but in the variables you only have 9 slots. You need to make the struct and array 10 slots.

Code:
// Variables
var config Struct MusicSong
{
	var() string           SongName;
	var() float            SongDuration;
} SongInfo[10];

var() Music Song[10];