For direct access use https://forums.oldunreal.com
It's been quite a while since oldunreal had an overhaul, but we are moving to another server which require some updates and changes. The biggest change is the migration of our old reliable YaBB forum to phpBB. This system expects you to login with your username and old password known from YaBB.
If you experience any problems there is also the usual "password forgotten" function. Don't forget to clear your browser cache!
If you have any further concerns feel free to contact me: Smirftsch@oldunreal.com

music mutator?

The section related to UnrealScript and modding. This board is for coders to discuss and exchange experiences or ask questions.
User avatar
dustinechoes849
OldUnreal Member
Posts: 480
Joined: Sat Feb 28, 2015 1:56 am

music mutator?

Post by dustinechoes849 »

Aye m8,

I'm making an Unreal (227i) mutator, and I want it to change the level's music.

putting this into PostBeginPlay() didn't do anything

Code: Select all

      foreach AllActors( class 'Actor', P )
      {
      if( P.IsA('PlayerPawn') )
{
                  PlayerPawn(P).ClientSetMusic( Music'digsh.digsh', 1, 255, MTRAN_Segue );
                  

}
      }

[edit]Forgot to mention that "local actor P;" is at the start of the PostBeginPlay() [/edit]



any help is appreciated

thanks! :D :D
Last edited by dustinechoes849 on Sun Jan 15, 2017 5:19 pm, edited 1 time in total.
User avatar
[]KAOS[]Casey
OldUnreal Member
Posts: 4497
Joined: Sun Aug 07, 2011 4:22 am
Location: over there

Re: music mutator?

Post by []KAOS[]Casey »

ClientSetMusic requires the player to actually be in the level.



And through the power of digging up crappity smackin ancient code (6+ years) I present:

Code: Select all

class derp extends mutator;

event PostBeginPlay ()
{
      local int S;
      local int Q;
      local string thisMap;
      ThisMap=Level.GetLocalURL();
      S=InStr(ThisMap,"/") + 1;
      Q=InStr(ThisMap,"?");
      ThisMap=Mid(ThisMap,S,Q - S);
      if ( InStr(ThisMap,".unr") == -1 )
      {
            ThisMap=ThisMap $ ".unr";
      }
      if(ThisMap ~= "Something.unr")
      {
            Level.Song = music(DynamicLoadObject("digsh.digsh",class'Music'));
            Level.SongSection = 1;
      }
}
100000% untested.

Be sure to have music in server packages or otherwise load on client.. I don't know if this will be a problem if its a stock package. You could also hardcode the dependency, which would force clients to load it before connecting to the server.... If the mutator is also in server packages

with Song=music'digsh.digsh';
Last edited by []KAOS[]Casey on Sun Jan 15, 2017 6:39 pm, edited 1 time in total.
User avatar
dustinechoes849
OldUnreal Member
Posts: 480
Joined: Sat Feb 28, 2015 1:56 am

Re: music mutator?

Post by dustinechoes849 »

ClientSetMusic requires the player to actually be in the level.



And through the power of digging up crappity smackin ancient code (6+ years) I present:

Code: Select all

class derp extends mutator;

event PostBeginPlay ()
{
      local int S;
      local int Q;
      local string thisMap;
      ThisMap=Level.GetLocalURL();
      S=InStr(ThisMap,"/") + 1;
      Q=InStr(ThisMap,"?");
      ThisMap=Mid(ThisMap,S,Q - S);
      if ( InStr(ThisMap,".unr") == -1 )
      {
            ThisMap=ThisMap $ ".unr";
      }
      if(ThisMap ~= "Something.unr")
      {
            Level.Song = music(DynamicLoadObject("digsh.digsh",class'Music'));
            Level.SongSection = 1;
      }
}
100000% untested.

Be sure to have music in server packages or otherwise load on client.. I don't know if this will be a problem if its a stock package. You could also hardcode the dependency, which would force clients to load it before connecting to the server.... If the mutator is also in server packages

with Song=music'digsh.digsh';

Copied the big cluster of wacky code in, and it didn't work. But just putting in

Code: Select all

            Level.Song = music(DynamicLoadObject("digsh.digsh",class'Music'));
            Level.SongSection = 1;
worked though! Would just having those two lines work in multiplayer?

thanks m8
User avatar
Masterkent
OldUnreal Member
Posts: 1469
Joined: Fri Apr 05, 2013 12:41 pm

Re: music mutator?

Post by Masterkent »

Copied the big cluster of wacky code in, and it didn't work.
You are supposed to [red]use map with name Something.unr[/red] replace "Something.unr" with an actual map name. That's not a rational way to check map name though, you could simply use

Code: Select all

string(Outer.Name) ~= "PlaceholderForActualMapName"
instead.
Would just having those two lines work in multiplayer?
If the package 'digsh' is not loaded client-side, then no. You can call AddToPackagesMap("digsh") from the mutator's PostBeginPlay, then clients will be required to load this package.
User avatar
fake
Posts: 3
Joined: Sun Jan 15, 2017 9:27 pm

Re: music mutator?

Post by fake »

*sigh* I could have sworn there was already a mutator for this.

Also, if you want your code to be compatible with kosher versions {226b, 226f, 225f, 224} you would best look into moving that DynamicLoadObject call to execute client-side. Of course, you could always cater to the status quo[1] but that's just mesuggestion.


[1]Backwards compatibility is a poor man's ale at best; mispurposed and generally unsatisfying
"If you have any trouble sounding condescending, find a Unix user to show you how it's done."
--Scott Adams
User avatar
[]KAOS[]Casey
OldUnreal Member
Posts: 4497
Joined: Sun Aug 07, 2011 4:22 am
Location: over there

Re: music mutator?

Post by []KAOS[]Casey »

:) Song is const in ut99, so i know that previous code should only work offline. Especially because that jazz doesnt appear to be replicated

v1, compiles, untested.

Code: Select all

Class Herp extends Mutator;

Simulated Function PostBeginPlay()
{
      local String MapFileName;
      
      bAlwaysRelevant = true;

      MapFileName=string(Outer.Name);

      if(MapFileName ~= "dig")
      {
            SetMusic("digsh.digsh",1);
      }
}

Simulated Function SetMusic(String MusicString,int SongSection)
{
      local PlayerPawn LocalPlayer;
      local Music NewMusic;

      if(Level.Netmode == NM_DedicatedServer)
            return;

      ForEach AllActors(Class'PlayerPawn',LocalPlayer)
      {
            if( LocalPlayer != None )
            {
                  if(LocalPlayer.Player != None) //find our local player...
                  {
                        break;
                  }
            }
      }

      NewMusic = music(DynamicLoadObject(MusicString,class'Music'));
      if(NewMusic != None) //Don't try to load null -- probably just stops music but whatever.
      {
            LocalPlayer.ClientSetMusic( NewMusic, SongSection, 255, MTRAN_Instant );
      }
}

defaultproperties
{
        RemoteRole=ROLE_SimulatedProxy
}

1)  :exclamation Make sure mutator is ROLE_SimulatedProxy :exclamation
2) :exclamation Make sure mutator is in server packages
:exclamation
3) Set your mapnames to use specific songs, or remove my check and set all of them.

v2, which should eliminate issues such as Zombie crappity smacking with peoples netspeed and PlayerPawn not becoming relevant via race condition (? is this even possible? lets be paranoid! I can't exactly test right now) fast enough Soon...
Last edited by []KAOS[]Casey on Mon Jan 16, 2017 8:24 pm, edited 1 time in total.
User avatar
[]KAOS[]Casey
OldUnreal Member
Posts: 4497
Joined: Sun Aug 07, 2011 4:22 am
Location: over there

Re: music mutator?

Post by []KAOS[]Casey »

This version, v2, obsesses on your client and waits until your playerpawn exists(I don't know if this is an actual case tbh) then sets its music

Code: Select all

Class derp extends Mutator;

Simulated Function PostBeginPlay()
{
      bAlwaysRelevant = true;
      if(Level.Netmode == NM_DedicatedServer)
            return;
      SetTimer(0.000420, true); //sm0k3w33d3rryt1ck
}

Simulated Function Timer()
{
      local String MapFileName;
      local PlayerPawn LocalPlayer;


      ForEach AllActors(Class'PlayerPawn',LocalPlayer)
      {
            if( LocalPlayer != None )
            {
                  if(LocalPlayer.Player != None) //find our local player...
                  {
                        MapFileName=string(Outer.Name);

                        if(MapFileName ~= "dig")
                        {
                              SetMusic("digsh.digsh",1,LocalPlayer);
                        }
                        SetTimer(0.0,false);
                        break;
                  }
            }
      }
}

Simulated Function SetMusic(String MusicString,int SongSection,PlayerPawn LocalPlayer)
{
      
      local Music NewMusic;

      NewMusic = music(DynamicLoadObject(MusicString,class'Music'));
      if(NewMusic != None) //Don't try to load null -- probably just stops music but whatever.
      {
            LocalPlayer.ClientSetMusic( NewMusic, SongSection, 255, MTRAN_Instant );
      }
}

defaultproperties
{
        RemoteRole=ROLE_SimulatedProxy
}
Last edited by []KAOS[]Casey on Mon Jan 16, 2017 8:24 pm, edited 1 time in total.
jaden88

Re: music mutator?

Post by jaden88 »

This version, v2, obsesses on your client and waits until your playerpawn exists(I don't know if this is an actual case tbh) then sets its music

Code: Select all

Class derp extends Mutator;

Simulated Function PostBeginPlay()
{
      if(Level.Netmode == NM_DedicatedServer)
            return;
      SetTimer(0.000420, true); //sm0k3w33d3rryt1ck
}

Simulated Function Timer()
{
      local String MapFileName;
      local PlayerPawn LocalPlayer;


      ForEach AllActors(Class'PlayerPawn',LocalPlayer)
      {
            if( LocalPlayer != None )
            {
                  if(LocalPlayer.RemoteRole == ROLE_AutonomousProxy) //find our local player...
                  {
                        MapFileName=string(Outer.Name);

                        if(MapFileName ~= "dig")
                        {
                              SetMusic("digsh.digsh",1,LocalPlayer);
                        }
                        SetTimer(0.0,false);
                        break;
                  }
            }
      }
}

Simulated Function SetMusic(String MusicString,int SongSection,PlayerPawn LocalPlayer)
{
      
      local Music NewMusic;

      NewMusic = music(DynamicLoadObject(MusicString,class'Music'));
      if(NewMusic != None) //Don't try to load null -- probably just stops music but whatever.
      {
            LocalPlayer.ClientSetMusic( NewMusic, SongSection, 255, MTRAN_Instant );
      }
}

defaultproperties
{
        RemoteRole=ROLE_SimulatedProxy
}
+1 for obsession version. Isn't there some facility (whoa, interesting word choice..) in TwoTwoSeven that lets you detect when stuff replicates over? Eh, nevermind that wouldn't be useful here. Version Three would be where the server can craplicate over an arr@y of songs (strings) to the User so the Server could customize what songs play on what maps...

as "zeur" said I do believe there was a mod out there that did this already..
edit: if it exists, f@#% it (The Philosophy of FE) - this mod is already superior master race compared to that decrepit b$

Dude I just had an even better Captain Nefarious level idea... it is exceedingly useful and Not Morally Questionable at all. perhaps we could improve upon this design by having a udp uplink upload every single keypress to a remote server. it is then processed (obsessively logged) and packets are relayed back to the unreal client telling it what music to play! that way we can $MAKE_UP_SOME_HAIRBRAINED_FEATURE_TO_JUSTIFY_MORALLY_BANKRUPT_PLOT (maybe something to do with winamp or external music server) with ease! great idea huh?
Last edited by jaden88 on Mon Jan 16, 2017 7:20 pm, edited 1 time in total.
jaden88

Re: music mutator?

Post by jaden88 »

1)  :exclamation Make sure mutator is ROLE_SimulatedProxy :exclamation
2)  :exclamation Make sure mutator is in server packages
:exclamation
3) Set your mapnames to use specific songs, or remove my check and set all of them.
QFFT. The second "F" is colorful language. I couldn't tell you how many times I've parroted #2 over the years[/quote]
User avatar
Masterkent
OldUnreal Member
Posts: 1469
Joined: Fri Apr 05, 2013 12:41 pm

Re: music mutator?

Post by Masterkent »

Song is const in ut99
I'm making an Unreal (227i) mutator

Code: Select all

                  if(LocalPlayer.RemoteRole == ROLE_AutonomousProxy) //find our local player...
won't work in singleplayer mode. Without changing RemoteRole to Role it won't work in multiplayer too.

Code: Select all

defaultproperties
{
        RemoteRole=ROLE_SimulatedProxy
}
something's missing here.
1)  :exclamation Make sure mutator is ROLE_SimulatedProxy :exclamation
2)  :exclamation Make sure mutator is in server packages
:exclamation
2.718281828459) make sure the mutator is net-relevant (otherwise it won't be ever replicated) - e.g., set its bAlwaysRelevant to true.
This version, v2, obsesses on your client and waits until your playerpawn exists
I presume, in case of 227i, that's still unreliable (after fixing net-relevancy). Where's the guarantee that replicated function call

Code: Select all

NewPlayer.ClientSetMusic(NewPlayer.Song,NewPlayer.SongSection,Level.CdTrack,MTRAN_FastFade)
from GameInfo.PostLogin won't be executed after derp.Timer()?

If there are two reliable function calls C1 and C2 and the call C1 is initiated before C2 on the host machine, then C1 is guaranteed to be executed before C2 on the target machine. Is there any strong ordering for calls of a reliably replicated function and a simulated function PostBeginPlay for a newly replicated actor?
Last edited by Masterkent on Mon Jan 16, 2017 8:45 pm, edited 1 time in total.
User avatar
[]KAOS[]Casey
OldUnreal Member
Posts: 4497
Joined: Sun Aug 07, 2011 4:22 am
Location: over there

Re: music mutator?

Post by []KAOS[]Casey »

Edited the code to set bAlwaysRelevant = true, and check for local player by checking PlayerPawn.Player != None to work offline. This is what happens when you just brew up code without actually trying to test it... whoops!

As far as race condition with login -- yeah, I'm not sure about how to guarantee that aside from delaying execution with another timer. The best way to do this is with a new gametype.
Last edited by []KAOS[]Casey on Mon Jan 16, 2017 8:27 pm, edited 1 time in total.
User avatar
Masterkent
OldUnreal Member
Posts: 1469
Joined: Fri Apr 05, 2013 12:41 pm

Re: music mutator?

Post by Masterkent »

I'd just use server-side modification of Level.Song (regardless of whether it's const-qualified in the target game or not - IIRC, in UScript, the const-qualifier affects only compile-time checks and can be bypassed).
User avatar
TCP_Wolf
Administrator
Posts: 1078
Joined: Sun Mar 03, 2002 12:04 pm

Re: music mutator?

Post by TCP_Wolf »

*sigh* I could have sworn there was already a mutator for this.
Not a mutator but a runnable primitive server side mod from ages ago

http://wolf.tcpclan.net/projects/Unreal/SUSongPlayer.html
-=]HONESTY PAYS[=-

Return to “UScript Board”