PDA

View Full Version : [UT'99] How to interact with an actor, when level ends


Raven
17th Sep 2005, 08:53 AM
I build mp3 player, and the problem is, that when I play mp3 in one level, and load another, mp3 keep playing :/. I tried 'event Destroyed' and mutator:

class RMp3PlayerStopper extends Mutator;

var RMp3Player JukeBox;

function AddMutator(Mutator M)
{
if ( M.IsA('RMp3PlayerStopper') )
{
return; //only allow one mutator
}
Super.AddMutator(M);
}


function BeginPlay()
{
foreach AllActors(class'RMp3Player', JukeBox)
break;
log("Mp3Player: mutator begins play");
}

function bool HandleEndGame()
{
ShutDownMusicSys();
Super.HandleEndGame();
return False;
}

function ShutDownMusicSys()
{
log("Mp3Player: shuttin gdown");
JukeBox.ShutDown();
JukeBox.Destroy();
}


but nothing works. So my question is: how to interact with an actor, when level is about to change?

Raven
17th Sep 2005, 03:43 PM
I've tried something else. I decide to spawn mp3player in entry level


(..)
simulated function PostBeginPlay()
{
if (Level.NetMode != NM_DedicatedServer)
SetTimer(1.0,true);
}

simulated function Timer()
{

if (Level.NetMode == NM_DedicatedServer) return;

if (Level.LevelAction == LEVACT_None) {
foreach AllActors(class'PlayerPawn',PP)
break;

if (PP == none) return;

foreach PP.GetEntryLevel().AllActors(class'RMp3Player',JukeBox)
break;

if (JukeBox == none)
JukeBox = PP.GetEntryLevel().Spawn(class'RMp3Player');

JukeBox.ReadPlayerPawn(PP);

Mp3PlayerInit();
SetTimer(0, false);
}
}
(..)


and check if new level is loading, and then stop playing sound


class RMp3Player extends Actor
native
config(user)
NoUserCreate;

var native string Directory;
var config int MusicVolume;
var bool bWasInitialized;
var PlayerPawn PP;
var LevelInfo CurLevel, OldLevel;
//var bool bDoFade;
//var bool bIsPaused;

native(2230) final function bool MusicSystemInit(); //Initialize music system
native(2331) final function bool PlaySong(string title); //Plays song (use only for the first time)
native(2432) final function StopSong(); //Stop playing new song
native(2533) final function ChangeVolume(int Volume); //Changes volume
native(2634) final function PlayNewSong(string title); //Plays new song
native(2735) final function ShutDown(); //Shuts down music system
//native(2836) final function PauseMusic(bool PauseMusic); //Pause music

function ReadPlayerPawn(PlayerPawn PlP)
{
PP=PlP;
OldLevel = PlP.level;
}


event Tick(float Delta)
{
if (PP == none || !bWasInitialized) return;

CurLevel = PP.player.console.viewport.actor.level;

if (CurLevel != OldLevel && CurLevel != Level)
// if(PP.player.console.viewport.actor.level.LevelAction == LEVACT_Loading)
{
log("Mp3Player: InShuttingDown");
if(bWasInitialized)
{
ShutDown();
bWasInitialized=false;
}
// Destroy();
}
}

defaultproperties
{
Directory="../music/"
MusicVolume=128
bHidden=True
}

but then UT just hangs up with 'loading' screen. Nothig important appears in the log (just normal ut logs) :/

Raven
19th Sep 2005, 02:14 AM
I solved this problem :). I don't know why, but all problems (ut hangs up) was caused by one of the native functions. So now I use another for shutting down this bastard. Mp3Player can be found: http://turniej.unreal.pl/mp3player/indexen.html and http://turniej.unreal.pl/mp3player/RvMp3Player.zip.