AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Solved "Client X is not connected" directly after IsClientConnected (https://forums.alliedmods.net/showthread.php?t=306196)

Dragokas 03-20-2018 12:04

"Client X is not connected" directly after IsClientConnected
 
Quote:

L 03/19/2018 - 19:07:46: [SM] Native "EmitSound" reported: Client 18 is not connected
L 03/19/2018 - 19:07:46: [SM] Displaying call stack trace for plugin "l4d_crowned_horde.smx":
L 03/19/2018 - 19:07:46: [SM] [0] Line 370, E:\SM Plugins\SM 1.3 Compiler\include\sdktools_sound.inc::EmitSoun dToClient()
L 03/19/2018 - 19:07:46: [SM] [1] Line 479, l4d_crowned_horde.sp::PlaySound()
L 03/19/2018 - 19:07:46: [SM] [2] Line 302, l4d_crowned_horde.sp::Event_WitchHarasserSet( )
Code:

        new i;
        for (i = 1; i <= GetMaxClients(); i++)
        {
                if (!IsClientConnected(i))
                {
                        continue;
                }
                if (IsFakeClient(i))
                {
                        continue;
                }

                EmitSoundToClient(i, sound_witch, witch_id, SNDCHAN_AUTO, SNDLEVEL_NORMAL, SND_NOFLAGS, SNDVOL_NORMAL, SNDPITCH_NORMAL, -1, NULL_VECTOR, NULL_VECTOR, true, 0.0);
        }

Looks like exception by design? :)

Nothing that I can improve here to prevent it?

StealthGus 03-20-2018 12:37

Re: "Client X is not connected" directly after IsClientConnected
 
You aren't checking for IsClientConnected, you're checking !IsClientConnected or if client is not connected. Same thing with your "IsFakeClient". And then you're having it continue to a function that is trying to perform something on a client that is either not there or is a fake client.

You should change it to something like this:

PHP Code:

for (int i 1MaxClientsi++) {
  if (
IsClientConnected(i) && !IsFakeClient(i)) {
    
EmitSoundToClient(isound_witchwitch_idSNDCHAN_AUTOSNDLEVEL_NORMALSND_NOFLAGSSNDVOL_NORMALSNDPITCH_NORMAL, -1NULL_VECTORNULL_VECTORtrue0.0);
  }



Visual77 03-20-2018 12:48

Re: "Client X is not connected" directly after IsClientConnected
 
Old syntax because your plugin is written in old syntax. There's no point playing sounds to clients that can't hear them anyway, that's why you check IsClientInGame.

Code:

for (new i = 1; i <= MaxClients; i++)
{
        if (IsClientInGame(i) && !IsFakeClient(i))
        {
                EmitSoundToClient(i, sound_witch, witch_id, SNDCHAN_AUTO, SNDLEVEL_NORMAL, SND_NOFLAGS, SNDVOL_NORMAL, SNDPITCH_NORMAL, -1, NULL_VECTOR, NULL_VECTOR, true, 0.0);
        }
}


hleV 03-20-2018 12:51

Re: "Client X is not connected" directly after IsClientConnected
 
Quote:

Originally Posted by StealthGus (Post 2583844)
You aren't checking for IsClientConnected, you're checking !IsClientConnected or if client is not connected. Same thing with your "IsFakeClient". And then you're having it continue to a function that is trying to perform something on a client that is either not there or is a fake client.

You should change it to something like this:

PHP Code:

for (int i 1MaxClientsi++) {
  if (
IsClientConnected(i) && !IsFakeClient(i)) {
    
EmitSoundToClient(isound_witchwitch_idSNDCHAN_AUTOSNDLEVEL_NORMALSND_NOFLAGSSNDVOL_NORMALSNDPITCH_NORMAL, -1NULL_VECTORNULL_VECTORtrue0.0);
  }



His conditions are correct. If not connected = skip. If fakeclient = skip. Otherwise Emit sound.

Dragokas 03-20-2018 13:01

Re: "Client X is not connected" directly after IsClientConnected
 
StealthGus,

1) as far as I know from C++, 'continue' command in 'for' cycles mean skipping all lines until last scope of "for" command and starting new iteration, so EmitSoundToClient will be skipped if IsClientConnected is not connected or if fake client. So,
your code example should be a functionally analogue. Would you like to say that "continue" behaviour is somehow different in SourcePawn?

2) How
Code:

(1) && (2)
considered in SourcePawn: will (2) be called if (1) is false ?

Visual77 03-20-2018 13:23

Re: "Client X is not connected" directly after IsClientConnected
 
Quote:

Originally Posted by Dragokas (Post 2583849)
considered in SourcePawn: will (2) be called if (1) is false ?

(2) will not be called if (1) is false.

Mitchell 03-20-2018 14:14

Re: "Client X is not connected" directly after IsClientConnected
 
The error maybe misleading, the player is probably needed to be in game (fully connected) to emit to.

Dragokas 03-20-2018 17:21

Re: "Client X is not connected" directly after IsClientConnected
 
Good point, thanks.

Ahh, missed Visual77 answer.
Quote:

Reply With Quote Multi-Quote This Message Quick reply to this message #3
Old syntax because your plugin is written in old syntax. There's no point playing sounds to clients that can't hear them anyway, that's why you check IsClientInGame.
Thanks.

BTW. Not my code/code style, so I'll leave that syntax as is for now.

Fyren 03-20-2018 19:04

Re: "Client X is not connected" directly after IsClientConnected
 
Quote:

Originally Posted by Dragokas (Post 2583839)
Nothing that I can improve here to prevent it?

Looking at the EmitSound code, the error message should really say like "client is not in game" as Visual77 said. You could file an issue on Github if you want.

headline 03-20-2018 20:07

Re: "Client X is not connected" directly after IsClientConnected
 
Quote:

Originally Posted by Fyren (Post 2583916)
Looking at the EmitSound code, the error message should really say like "client is not in game" as Visual77 said. You could file an issue on Github if you want.

Since Fyren has said this, I made a pull request that improves this error. Creating an issue is no longer necessary :p


All times are GMT -4. The time now is 01:12.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.