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

Requesting custom WaterZoneInfo

The section related to UnrealScript and modding. This board is for coders to discuss and exchange experiences or ask questions.
Post Reply
User avatar
Krull0r
Global Moderator
Posts: 543
Joined: Sun Jul 01, 2007 4:07 pm

Requesting custom WaterZoneInfo

Post by Krull0r »

Hello.

I'm thinking about a custom Waterzone for Unreal Redux which plays a player attached looping underwater sound effect while the player is under water.

It is also important that only the player can hear the sound effect.
So he shouldn't become a sound source for other players.


Might this be possible?


Greetings Krull0r
Image
User avatar
Masterkent
OldUnreal Member
Posts: 1469
Joined: Fri Apr 05, 2013 12:41 pm

Re: Requesting custom WaterZoneInfo

Post by Masterkent »

I'm thinking about a custom Waterzone for Unreal Redux which plays a player attached looping underwater sound effect while the player is under water.
Do you need that working for all water zones or only for particular ones?

What region of a player (foot/middle/head) should reside in a water zone to make the sound played?
User avatar
Krull0r
Global Moderator
Posts: 543
Joined: Sun Jul 01, 2007 4:07 pm

Re: Requesting custom WaterZoneInfo

Post by Krull0r »

It should work for all WaterZone Info
Maybe with the possibility to place different sounds for each ZoneInfo

Using the Head region would be nice.
Image
User avatar
Bleeder91[NL]
OldUnreal Member
Posts: 1062
Joined: Sun Oct 04, 2009 7:22 pm

Re: Requesting custom WaterZoneInfo

Post by Bleeder91[NL] »

I used this ZoneAmbientSound before, which client-side relocates to the player once he's in the zone. I used this for rain sounds but your idea should work too. Some tinkering may be required like the offset from the player, but I'm sure you can figure it out (I'm unsure whether CalcCameraLocation is 227j+ only).

Code: Select all

//=============================================================================
// ZoneAmbientSound.
//=============================================================================
class ZoneAmbientSound expands AmbientSound;

var byte BaseVolume;
var ZoneInfo BaseZone;

Replication
{
      Reliable if(Role==ROLE_Authority)
            BaseZone, BaseVolume;
}

simulated function BeginPlay()
{
      BaseVolume=SoundVolume;
      BaseZone=Region.Zone;
      SoundVolume=0;
      ScaleGlow=0;
      DrawType=DT_None;
}

simulated function Tick(float DT)
{
      var PlayerPawn LocalPlayer;
      
      LocalPlayer=Level.GetLocalPlayerPawn();
      if(!bool(LocalPlayer)) { Disable('Tick'); return; }
      SetLocation(LocalPlayer.CalcCameraLocation+(vect(100,0,0)>>LocalPlayer.CalcCameraRotation));
      if(LocalPlayer.HeadRegion.Zone==BaseZone) ScaleGlow=FClamp(ScaleGlow+2*DT,0,1);
      else ScaleGlow=FClamp(ScaleGlow-2*DT,0,1);
      SoundVolume=BaseVolume*ScaleGlow;
}

defaultproperties
{
      bStatic=False
      bHidden=False
      bAlwaysRelevant=True
      RemoteRole=ROLE_SimulatedProxy
}
Last edited by Bleeder91[NL] on Mon Jun 11, 2018 5:34 pm, edited 1 time in total.
Image
User avatar
Masterkent
OldUnreal Member
Posts: 1469
Joined: Fri Apr 05, 2013 12:41 pm

Re: Requesting custom WaterZoneInfo

Post by Masterkent »

Is that sound supposed to be coming from the water or from the player's equipment?

Sometimes the location of the player's camera may be far from the head location (e.g. when using the 3rd person view or watching other player). So it's unclear what should happen, for example, when your head in under water, but your camera is not, or vice versa. Additionally, it's not clear whether spectators should hear such underwater sounds (when they observe the world from their own position or use a view from other actor).
User avatar
Krull0r
Global Moderator
Posts: 543
Joined: Sun Jul 01, 2007 4:07 pm

Re: Requesting custom WaterZoneInfo

Post by Krull0r »

Bleeder your sound actor works fine so far :)
The problem is now I'm also using DynamicWaterZoneInfo for water ( because of BSP holes ) and the sound do not check the Zone change.
I really like the fading after the player leaves or enters the ZoneInfo


I like to use such an actor for underwater background noises.
Image
User avatar
Masterkent
OldUnreal Member
Posts: 1469
Joined: Fri Apr 05, 2013 12:41 pm

Re: Requesting custom WaterZoneInfo

Post by Masterkent »

I never used dynamic zones and dunno how they work. Regarding ZoneAmbientSound, I'd probably implement it a bit differently.

For particular zones:

Code: Select all

class ZoneAmbientSound expands AmbientSound;

var(Sound) Sound ZoneSound;
 
var ZoneAmbientSound Next;

simulated event Tick(float DeltaTime)
{
      local PlayerPawn Player;
      local ZoneAmbientSoundSource SoundSource;

      if (Level.NetMode == NM_DedicatedServer)
      {
            Disable('Tick');
            return;
      }
      Player = Level.GetLocalPlayerPawn();
      if (Player == none)
            return;
      foreach Player.ChildActors(class'ZoneAmbientSoundSource', SoundSource)
      {
            SoundSource.AddZoneAmbientSound(self);
            Disable('Tick');
            return;
      }

      SoundSource = Player.Spawn(class'ZoneAmbientSoundSource', Player);
      if (SoundSource != none)
            SoundSource.AddZoneAmbientSound(self);
      Disable('Tick');
}

simulated function bool HandleZone(ZoneInfo Zone, Actor SoundSource)
{
      if (Level.GetLocZone(Location).Zone != Zone)
            return false;
      SetAmbientSoundOf(SoundSource);
      return true;
}

final simulated function SetAmbientSoundOf(Actor SoundSource)
{
      SoundSource.AmbientSound = ZoneSound;
      SoundSource.SoundPitch = SoundPitch;
      SoundSource.SoundVolume = SoundVolume;
}

defaultproperties
{
      bNoDelete=True
      bStatic=False
      RemoteRole=ROLE_SimulatedProxy
}
For all other water zones:

Code: Select all

class WaterZonesAmbientSound expands ZoneAmbientSound;

simulated function bool HandleZone(ZoneInfo Zone, Actor SoundSource)
{
      if (WaterZone(Zone) != none)
            SetAmbientSoundOf(SoundSource);
      return false;
}
The class of sound source (spawned by the implementation client-side, should not be placed in maps via UnrealEd):

Code: Select all

class ZoneAmbientSoundSource expands AmbientSound
      nousercreate;

var private ZoneAmbientSound First;
var private ZoneInfo LastOwnerCamZone;

event Tick(float DeltaTime)
{
      Update(PlayerPawn(Owner));
}

final function AddZoneAmbientSound(ZoneAmbientSound ZoneAmbientSound)
{
      ZoneAmbientSound.Next = First;
      First = ZoneAmbientSound;
      LastOwnerCamZone = none;
}

final function Update(PlayerPawn Player)
{
      if (Player == none || Player.bDeleteMe)
      {
            Destroy();
            return;
      }

      SetLocation(Player.CalcCameraLocation);
      Velocity = Player.Velocity;
      UpdateZoneAmbientSound(Player);
}

final function UpdateZoneAmbientSound(PlayerPawn Player)
{
      local ZoneAmbientSound ZoneAmbientSound;

      if (LastOwnerCamZone == Player.CameraRegion.Zone)
            return;

      LastOwnerCamZone = Player.CameraRegion.Zone;
      AmbientSound = none;

      for (ZoneAmbientSound = First; ZoneAmbientSound != none; ZoneAmbientSound = ZoneAmbientSound.Next)
            if (ZoneAmbientSound.HandleZone(LastOwnerCamZone, self))
                  return;
}

defaultproperties
{
      bStatic=False
      RemoteRole=ROLE_None
}
The main differences are:

1. It's possible to assign a common ambient sound for all water zones in the map.

2. No network replication is used, so a greater number of other actors can be replicated without issues (max number of simultaneously net-relevant actors is about 1024).

3. Time-dependent fading doesn't make sense to me, so I wouldn't use it.

4. Whether and what sound is played depends on the location of the player's camera (which may be far from the head region).
Last edited by Masterkent on Fri Jun 29, 2018 10:11 am, edited 1 time in total.
User avatar
Bleeder91[NL]
OldUnreal Member
Posts: 1062
Joined: Sun Oct 04, 2009 7:22 pm

Re: Requesting custom WaterZoneInfo

Post by Bleeder91[NL] »

Thanks for the free optimization, Masterkent, it'll come in handy in the very near future. Much appreciated :P
Image
User avatar
Masterkent
OldUnreal Member
Posts: 1469
Joined: Fri Apr 05, 2013 12:41 pm

Re: Requesting custom WaterZoneInfo

Post by Masterkent »

Whether these optimizations are applicable depends on how you use such actors and what effects you want to achieve. bNoDelete is useful when the actor need not be spawned or destroyed dynamically and network clients can read its properties directly from the containing map. Dynamically spawnable actors cannot have default.bNoDelete == true. And if you want those fading effects, then two or more sounds can potentially be played simultaneously, so a single sound source won't suffice.
User avatar
Krull0r
Global Moderator
Posts: 543
Joined: Sun Jul 01, 2007 4:07 pm

Re: Requesting custom WaterZoneInfo

Post by Krull0r »

Works fine so far but entering a DynamicWaterZones has no effect :(
Image
User avatar
Masterkent
OldUnreal Member
Posts: 1469
Joined: Fri Apr 05, 2013 12:41 pm

Re: Requesting custom WaterZoneInfo

Post by Masterkent »

DynamicZoneInfo does not update Region of actors which are already present in its volume, and I'd consider this as a bug in DynamicZoneInfo itself.

My code may handle dynamic zones well after replacing

Code: Select all

simulated function bool HandleZone(ZoneInfo Zone, Actor SoundSource)
{
      if (Region.Zone != Zone)
            return false;
      SetAmbientSoundOf(SoundSource);
      return true;
}
with

Code: Select all

simulated function bool HandleZone(ZoneInfo Zone, Actor SoundSource)
{
      if (Level.GetLocZone(Location).Zone != Zone)
            return false;
      SetAmbientSoundOf(SoundSource);
      return true;
}
Bleeder's code can be changed similarly, but you'd need to either get rid of variable BaseZone or postpone its initialization somehow, because your DynamicZoneInfo actor may be initialized after the call to ZoneAmbientSound.BeginPlay, so during the execution of ZoneAmbientSound.BeginPlay expressions like

Code: Select all

BaseZone = Region.Zone
or

Code: Select all

BaseZone = Level.GetLocZone(Location).Zone
may behave as if the DynamicZoneInfo actor didn't exist.

The initialization order of DynamicZoneInfo and ZoneAmbientSound will probably depend on the order in which these actors are placed in the list of actors (or objects). Since you cannot reliably specify this order by means of UnrealEd, relying on the automatically chosen order, which luckily may produce the desirable behavior, wouldn't be a good idea.
User avatar
Krull0r
Global Moderator
Posts: 543
Joined: Sun Jul 01, 2007 4:07 pm

Re: Requesting custom WaterZoneInfo

Post by Krull0r »

Yes! This worked fine so far.

Only one more problem.
The game crashes and freezes with out any error message if I add more then one of that ambientsound.
Image
User avatar
Masterkent
OldUnreal Member
Posts: 1469
Joined: Fri Apr 05, 2013 12:41 pm

Re: Requesting custom WaterZoneInfo

Post by Masterkent »

Fixed
Post Reply

Return to “UScript Board”