Clients should play sounds depending on audio preferences

Discussions about Coding and Scripting
Post Reply
Aldebaran
Masterful
Posts: 672
Joined: Thu Jan 28, 2016 7:30 pm

Clients should play sounds depending on audio preferences

Post by Aldebaran »

I need some help in scripting again...

My mutator should play a sound with the function PlayerPawn.ClientPlaySound() in all player clients, but ONLY if NOT "None" or "No Taunts" (used for voice packs) in Client Audio Preferences is active.

I thought this code should work, but it does not:

Code: Select all

foreach AllActors( class 'PlayerPawn', PP )
{
    if ((PP != None) && !TournamentPlayer(PP).bNoVoiceTaunts && !TournamentPlayer(PP).bNoVoiceMessages)
        PP.ClientPlaySound(Sound'testsound', False);
}
Regardless of the Client Audio Preferences every time the sound is played.

I think the cause lies in "TournamentPlayer(PP).bNoVoiceTaunts" and "TournamentPlayer(PP).bNoVoiceMessages", what should I write instead?
Last edited by Aldebaran on Thu May 23, 2019 4:25 pm, edited 1 time in total.
User avatar
The_Cowboy
Skilled
Posts: 165
Joined: Mon Jan 24, 2011 3:22 am
Personal rank: Codezilla

Re: Clients should play sounds depended on audio preferences

Post by The_Cowboy »

Well you see that the variables bNoVoiceTaunts and bNoVoiceMessages are clientside variables. The sever has no clue what they are set to by the client. So server "assumes" them to be false (the default) and thus plays sound on all the clients. You need to replicate the variables to server by writing appropriate replication block (I won't kill the fun by writing it here :loool: ) and then use the check statement. GLHF with uscript.
Feralidragon wrote:Trial and error is sometimes better than any tutorial, because we learn how it works for ourselfs, which kills any doubts about anything :tu:
Patreon: https://www.patreon.com/FreeandOpen
User avatar
sektor2111
Godlike
Posts: 6403
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Clients should play sounds depended on audio preferences

Post by sektor2111 »

I would fire some notifier code right in client without even to blink if this would be my job. I don't see why server should play a sound for each PlayerPawn (poor innocent server...), so to speak "replication" has cheap solution less expensive even for bandwidth... in hoping that ACE won't get mad again for some "misbehaving" demanded on purpose...
User avatar
The_Cowboy
Skilled
Posts: 165
Joined: Mon Jan 24, 2011 3:22 am
Personal rank: Codezilla

Re: Clients should play sounds depended on audio preferences

Post by The_Cowboy »

sektor2111 wrote: I don't see why server should play a sound for each PlayerPawn (poor innocent server...),
Have you really read the op? It is not upto you to "see why server should play a sound". The server actually plays the sound on all clients
Aldebaran wrote: Regardless of the Client Audio Preferences every time the sound is played.
Write again if you have anything useful to.
Feralidragon wrote:Trial and error is sometimes better than any tutorial, because we learn how it works for ourselfs, which kills any doubts about anything :tu:
Patreon: https://www.patreon.com/FreeandOpen
Aldebaran
Masterful
Posts: 672
Joined: Thu Jan 28, 2016 7:30 pm

Re: Clients should play sounds depending on audio preference

Post by Aldebaran »

OK, then it will be more difficult than I supposed. Thank you for the tip!
User avatar
The_Cowboy
Skilled
Posts: 165
Joined: Mon Jan 24, 2011 3:22 am
Personal rank: Codezilla

Re: Clients should play sounds depending on audio preference

Post by The_Cowboy »

Also see viewtopic.php?f=15&t=11331 on dealing with the sever-client communication protocols.
Feralidragon wrote:Trial and error is sometimes better than any tutorial, because we learn how it works for ourselfs, which kills any doubts about anything :tu:
Patreon: https://www.patreon.com/FreeandOpen
User avatar
sektor2111
Godlike
Posts: 6403
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Clients should play sounds depending on audio preference

Post by sektor2111 »

I don't need to run any sound in any server when is about custom stuff. I used to spawn custom AmbientSounds in clients without a single problem (in map MH-Forbidden, btw where are missing two or three sounds for those torches), exactly as I have dynamic coronas, dynamic lights, and all these are client-side exactly like decals (of course decals are natively supported in clients). Since I'm working for custom patch plugins I've learned how to replicate almost without a lot of replication - replicated thing is a notifier which returns execution to none if is in a Server and keeps spawning or moving into a state code when is in client or non-dedicated server, is actually piece of cake... Higor hinted me with such things and later I could do similar stuff simplified. All actors used this way (CLIENT target) don't have RemoteRole. and YES I'm not running any light or sound in server when is about custom actors non-mapped actors, simple as that. Bots don't care about lights and sounds - player has problems here, so I help only player.
Sample:

Code: Select all

simulated function PostBeginPlay()
{
	local actor A;

	if ( Level.NetMode == NM_DedicatedServer )
		return;

	Super.PostBeginPlay();
	log ("Deco Notify Initialized...");
	ForEach AllActors(class'actor',A)
	{
		if ( A.IsA('Lamp1') )
		{
			A.ScaleGlow = 240;
			A.bUnlit = True;
			if ( A.DrawScale == 1.000000 )
				Spawn(class'Crn_Light',,,A.Location+vect(0,0,64)).LightBrightness=16;
			continue;
		}
		if ( A.IsA('Lantern2') )
		{
			A.ScaleGlow = 240;
			A.bUnlit = True;
			Spawn(class'Crn_Light',,,A.Location).LightBrightness=12;
			continue;
		}
		if ( A.IsA('Lantern') )
		{
			A.ScaleGlow = 240;
			A.bUnlit = True;
			Spawn(class'Crn_Light',,,A.Location).LightBrightness=12;
			continue;
		}
		if ( A.IsA('TorchFlame') )
		{
			Spawn(class'BurningLight',,,A.Location+vect(0,0,1));
			continue;
		}
		if (string(A.Name) ~= "WaterZone0") // Position 320
		{
			WaterZone(A).AmbientBrightness += 4;
			WaterZone(A).ViewFog = vect(0.02,0.02,0.02);
			WaterZone(A).Default.ViewFog = vect(0.02,0.02,0.02);
			continue;
		}
		if (string(A.Name) ~= "Mover17") // Position 323
		{
			Mover(A).KeyPos[1] = vect(0,182,0);
			continue;
		}
		if (string(A.Name) ~= "WaterZone1") // Position 912
		{
			WaterZone(A).AmbientBrightness += 4;
			WaterZone(A).ViewFog = vect(0.02,0.02,0.02);
			WaterZone(A).Default.ViewFog = vect(0.02,0.02,0.02);
			continue;
		}
		if ( string(A.Name) ~= "Mover35" ) // Position 954
		{
			Mover(A).BasePos = vect(1920,-11152,1326);
			continue;
		}
		if (string(A.Name) ~= "Mover9") // Position 960
		{
			Mover(A).KeyPos[1] = vect(0,-384,0);
			continue;
		}
		if (string(A.Name) ~= "Mover37") // Position 961
		{
			Mover(A).KeyPos[1] = vect(0,320,0);
			continue;
		}
		if (string(A.Name) ~= "Mover42") // Position 962
		{
			Mover(A).KeyPos[1] = vect(0,320,0);
			continue;
		}
		if (string(A.Name) ~= "Mover43") // Position 963
		{
			Mover(A).KeyPos[1] = vect(0,-320,0);
			continue;
		}
	}
	A = none;
	SpawnOtherStuff();
}
SpawnOtherStuff is already working only in client because everything was logged before as it's all tested... and code has been already stopped before in dedicated server. I even have a basic log for confirmation if plugin is loaded and something did not went wrong.
Here can be hunted Level's Owner (the one with Console because we are in client) and if client-sound has a failure I can spawn another actor nearby owner location and making sound and... dying.
@Aldebaran - Do you recall that MonsterShadow stuff which I sent you ? Feel free to do stunts there because it works almost in the same way - Client-Side, my friend, Client-Side...
Last edited by sektor2111 on Fri May 24, 2019 7:15 pm, edited 1 time in total.
User avatar
The_Cowboy
Skilled
Posts: 165
Joined: Mon Jan 24, 2011 3:22 am
Personal rank: Codezilla

Re: Clients should play sounds depending on audio preference

Post by The_Cowboy »

sektor2111 wrote:replicated thing is a notifier which returns execution to none if is in a Server and keeps spawning or moving into a state code when is in client or non-dedicated server, is actually piece of cake... Higor hinted me with such things and later I could do similar stuff simplified.
Ok this is another reason why the netcode document needed reincarnation. Replication is certainly much more than that. It also works in the reverse (client->server) and what about updating the variables that changed serverside during the gameplay. We don't want dumb clients to keep using the stale values, do we?
sektor2111 wrote:I don't need to run any sound in any server when is about custom stuff.
You simply and most certainly misinterpret replication.
sektor2111 wrote: Sample:

Code: Select all

simulated function PostBeginPlay()
{
	local actor A;

	if ( Level.NetMode == NM_DedicatedServer )
		return;

	Super.PostBeginPlay();
	log ("Deco Notify Initialized...");
	ForEach AllActors(class'actor',A)
	{
		if ( A.IsA('Lamp1') )
		{
			A.ScaleGlow = 240;
			A.bUnlit = True;
			if ( A.DrawScale == 1.000000 )
				Spawn(class'Crn_Light',,,A.Location+vect(0,0,64)).LightBrightness=16;
			continue;
		}
		if ( A.IsA('Lantern2') )
		{
			A.ScaleGlow = 240;
			A.bUnlit = True;
			Spawn(class'Crn_Light',,,A.Location).LightBrightness=12;
			continue;
		}
		if ( A.IsA('Lantern') )
		{
			A.ScaleGlow = 240;
			A.bUnlit = True;
			Spawn(class'Crn_Light',,,A.Location).LightBrightness=12;
			continue;
		}
		if ( A.IsA('TorchFlame') )
		{
			Spawn(class'BurningLight',,,A.Location+vect(0,0,1));
			continue;
		}
		if (string(A.Name) ~= "WaterZone0") // Position 320
		{
			WaterZone(A).AmbientBrightness += 4;
			WaterZone(A).ViewFog = vect(0.02,0.02,0.02);
			WaterZone(A).Default.ViewFog = vect(0.02,0.02,0.02);
			continue;
		}
		if (string(A.Name) ~= "Mover17") // Position 323
		{
			Mover(A).KeyPos[1] = vect(0,182,0);
			continue;
		}
		if (string(A.Name) ~= "WaterZone1") // Position 912
		{
			WaterZone(A).AmbientBrightness += 4;
			WaterZone(A).ViewFog = vect(0.02,0.02,0.02);
			WaterZone(A).Default.ViewFog = vect(0.02,0.02,0.02);
			continue;
		}
		if ( string(A.Name) ~= "Mover35" ) // Position 954
		{
			Mover(A).BasePos = vect(1920,-11152,1326);
			continue;
		}
		if (string(A.Name) ~= "Mover9") // Position 960
		{
			Mover(A).KeyPos[1] = vect(0,-384,0);
			continue;
		}
		if (string(A.Name) ~= "Mover37") // Position 961
		{
			Mover(A).KeyPos[1] = vect(0,320,0);
			continue;
		}
		if (string(A.Name) ~= "Mover42") // Position 962
		{
			Mover(A).KeyPos[1] = vect(0,320,0);
			continue;
		}
		if (string(A.Name) ~= "Mover43") // Position 963
		{
			Mover(A).KeyPos[1] = vect(0,-320,0);
			continue;
		}
	}
	A = none;
	SpawnOtherStuff();
}
SpawnOtherStuff is already working only in client because everything was logged before as it's all tested... and code has been already stopped before in dedicated server. I even have a basic log for confirmation if plugin is loaded and something did not went wrong.
Here can be hunted Level's Owner (the one with Console because we are in client) and if client-sound has a failure I can spawn another actor nearby owner location and making sound and... dying.
@Aldebaran - Do you recall that MonsterShadow stuff which I sent you ? Feel free to do stunts there because it works almost in the same way - Client-Side, my friend, Client-Side...
The code you have posted is called on client when the Actor is spawned and not by direct will of the server (or author for that matter). It basically translates to the scenario where you are bound to keep on spawning the Actor in order to do something clientside (as if the 50000 number wasn't enough) which I doubt the op is really interested in.

All this can be easily avoided by writing a simple replication block in the mutator class itself (which is an Actor). I mean while you are at it, why not spawn a custom scoreboard and do more stuff clientside.

I gave the example of replicating variables because op was wondering what is wrong with that routine which is written (as I would like to call Server Primary). It is supposed to make decisions on the server if or not to play the sound. One can write the Client Primary code where client can decide if they want to play the sound. Server just notifies that the sound should be played. There your "trigger" method works which can again be achieved by writing replication block.
Feralidragon wrote:Trial and error is sometimes better than any tutorial, because we learn how it works for ourselfs, which kills any doubts about anything :tu:
Patreon: https://www.patreon.com/FreeandOpen
Aldebaran
Masterful
Posts: 672
Joined: Thu Jan 28, 2016 7:30 pm

Re: Clients should play sounds depending on audio preference

Post by Aldebaran »

The code I want to use is neither for maps nor monster hunt mod. I had made a mutator that plays a voice/noise sound for all players if they want to have some audio output like "Hi" and so on after pressing a key, like a voice pack but usable for all players without additional installation. This mutator works but the sounds are output also if players have voice sounds deactivated in audio preferences and that's not good.
sektor2111 wrote:Do you recall that MonsterShadow stuff which I sent you ?
Yes it works great. I will have a look into it...
User avatar
sektor2111
Godlike
Posts: 6403
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Clients should play sounds depending on audio preference

Post by sektor2111 »

@Aldebaran
Get Owner and get his values when you work inside client - this has nothing with server for the moment. If values are matching your conditions PLAY the damn sound. If Client is not cooperating spawn a "sounder" around it.
The_Cowboy wrote:We don't want dumb clients to keep using the stale values, do we?
They won't keep anything unless you want this - some MapVote was running a timer in client all game for a stupid logo, it's not my case. All stuff means actors removed at once with Level when machine is traveling to next map. I repeat: I do not have any problem with this way of doing, I would like to know these 6-8 years ago...
The_Cowboy wrote:You simply and most certainly misinterpret replication.
Not all time, I wrote replication stuff, also I wrote "fake replication" - plugins here... etc. Dynamic coronas which I modified last time are simply stand-alone craps in client - just for preventing usage of network because it's pointless for what they have to do. Replication makes no sense for checking client's position toward a light, this is doable by client itself without server's participation, simple as that. Definitely an actor dedicated for client doesn't need a server to take a look at it. Server is sending package initializing spawning and letting client to work as should without any processing. Can you get what I mean ? If not I'll share Coroner mutator and you'll see what I'm talking about. That one is a client bitch without any replication block declared and you can put log lines and see what, how, when and where it's working.

More client stuff ? Sure...
Kelly did that Brut. Let's say that after a small discussion I was able to drop some projectiles only in client spawning graffiti in maps VIA patch plugins, for doing such hard-coded tasks you don't need any server tracking just primary replication replicating evil actor and letting it to work in desired side when reached there.
User avatar
The_Cowboy
Skilled
Posts: 165
Joined: Mon Jan 24, 2011 3:22 am
Personal rank: Codezilla

Re: Clients should play sounds depending on audio preference

Post by The_Cowboy »

Ok, if you can do hell lot of stuff client side, why do you even need a server. Just keep on playing with the, what's the phrase, "stand-alone" craps in the client. Just because you can avoid replication for the purposes you never needed it doesn't diminish its importance. For instance
sektor2111 wrote:@Aldebaran
Get Owner and get his values when you work inside client - this has nothing with server for the moment. If values are matching your conditions PLAY the damn sound. If Client is not cooperating spawn a "sounder" around it.
and when exactly do you reckon this routine should be executed (other words, how will the dumb client know when to PLAY or NOT PLAY)? Some magic? No wait, I know, let's set a timer client side with the loop of 0.5 seconds. Yeah that works without replication.
Feralidragon wrote:Trial and error is sometimes better than any tutorial, because we learn how it works for ourselfs, which kills any doubts about anything :tu:
Patreon: https://www.patreon.com/FreeandOpen
User avatar
sektor2111
Godlike
Posts: 6403
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Clients should play sounds depending on audio preference

Post by sektor2111 »

The_Cowboy wrote:Just because you can avoid replication for the purposes you never needed it doesn't diminish its importance
Yes.... very important especially in UE1 when you are working in 1024 channels and you want to track 200+ actors... indeed, excepting replication has no benefits... Seriously ? What for ? Are you planing to hog channels when you can avoid this ? Why to not avoid bunching data and making a server to work if it doesn't have to ? Server doesn't need lights. Dark maps ? Help client not server. 16 Clients why sending data to all of them if they can work separately without issues. But... I'm not bother to explain advantages, you can do what you want because I won't make a mess in server for a job addressing client.

@Aldebaran:
If that Shadow thing was possible easily, allow me to setup some logging in a modified Coroner and I'll tell you results in PM.
User avatar
The_Cowboy
Skilled
Posts: 165
Joined: Mon Jan 24, 2011 3:22 am
Personal rank: Codezilla

Re: Clients should play sounds depending on audio preference

Post by The_Cowboy »

You still don't get it. It is not about lightning or maps or monsters or that sort. Read the ops later posts. I asked a simple question try answering that.
Last edited by The_Cowboy on Sat May 25, 2019 12:17 am, edited 1 time in total.
Feralidragon wrote:Trial and error is sometimes better than any tutorial, because we learn how it works for ourselfs, which kills any doubts about anything :tu:
Patreon: https://www.patreon.com/FreeandOpen
User avatar
sektor2111
Godlike
Posts: 6403
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Clients should play sounds depending on audio preference

Post by sektor2111 »

@Aldebaran
PM sent - check how do works in your environment. For me a simple test confirmed that is operational - I used a CaptureSound2 :) .
Must be declared in ServerPackages, if you will use a custom sound, it also has to be imported into package...
You can add a check if that PlayerPawn is TournamentPlayer and not spectator or whatever... check classes for those variables and use what is suitable for your needs.
Post Reply