Raised This Month: $32 Target: $400
 8% 

Solved "Client X is not connected" directly after IsClientConnected


Post New Thread Reply   
 
Thread Tools Display Modes
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 03-21-2018 , 00:46   Re: "Client X is not connected" directly after IsClientConnected
Reply With Quote #11

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

No, Sourcepawn uses "lazy" or "short-circuit" evaluation. This allows you to do things like this:

Code:
if (0 < index <= MaxClients && IsClientInGame(index))
Passing an index that is less than 1 or greater than MaxClients to IsClientInGame() will cause errors, but the above snippet is safe, as the first part of the conditional ensures that invalid indexes will never make it to the second part.
__________________

Last edited by ddhoward; 03-21-2018 at 14:22.
ddhoward is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 03-21-2018 , 12:19   Re: "Client X is not connected" directly after IsClientConnected
Reply With Quote #12

Headline, nice, thanks.

Last edited by Dragokas; 03-21-2018 at 12:25.
Dragokas is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 03-21-2018 , 12:25   Re: "Client X is not connected" directly after IsClientConnected
Reply With Quote #13

ddhoward, so, your example in SourcePawn do:

1) 0 < index
2) index <= MaxClients
...

not:

1) 0 < index
2) (bool result) <= MaxClients
as C++ do.

?
Dragokas is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 03-21-2018 , 15:33   Re: "Client X is not connected" directly after IsClientConnected
Reply With Quote #14

Ok, here is another one I can't understand and explain:

Quote:
L 03/19/2018 - 20:402: [SM] Native "GetClientTeam" reported: Client 2 is not in game
L 03/19/2018 - 20:402: [SM] Displaying call stack trace for plugin "MuLS.smx":
L 03/19/2018 - 20:402: [SM] [0] Line 801, plugin.sp::HasIdlePlayer()
L 03/19/2018 - 20:402: [SM] [1] Line 680, plugin.sp::TotalFreeBots()
L 03/19/2018 - 20:402: [SM] [2] Line 164, plugin.sp::JoinTeam()
L 03/19/2018 - 20:402: [SM] [3] Line 412, plugin.sp::Timer_AutoJoinTeam()
Code:
public bool HasIdlePlayer(int bot)
{
	if(!IsFakeClient(bot))
		return false
	
	if(IsClientConnected(bot) && IsClientInGame(bot))
	{
		if((GetClientTeam(bot) == TEAM_SURVIVORS) && IsAlive(bot))
		{
			if(IsFakeClient(bot))
			{
				int client = GetClientOfUserId(GetEntProp(bot, Prop_Send, "m_humanSpectatorUserID"))			
				if(client)
				{
					if(!IsFakeClient(client) && (GetClientTeam(client) == TEAM_SPECTATORS))
						return true
				}
			}
		}
	}
	return false
}
This time IsClientInGame is directly before GetClientTeam call.
Dragokas is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 03-21-2018 , 16:49   Re: "Client X is not connected" directly after IsClientConnected
Reply With Quote #15

Quote:
Originally Posted by Dragokas View Post
ddhoward, so, your example in SourcePawn do:

1) 0 < index
2) index <= MaxClients
...

not:

1) 0 < index
2) (bool result) <= MaxClients
as C++ do.

?
Yes, in SP you can do 1 < x < 10 to check if x is between 1 and 10. It's not like in C++.

Quote:
This time IsClientInGame is directly before GetClientTeam call.
There's two calls. If it's the one for the client, you don't do a check.
Fyren is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 03-21-2018 , 20:52   Re: "Client X is not connected" directly after IsClientConnected
Reply With Quote #16

Quote:
Originally Posted by Dragokas View Post
-snip-
Why two different IsFakeClient() calls to the same index?

You're calling IsFakeClient() before IsClientConnected(), which will result in errors. The index passed to IsFakeClient must have a client.

IsClientInGame() is a function that breaks Sourcemod's typical behavior in that it is not necessary to call IsClientConnected() through it. IsClientInGame() includes its own IsClientConnected() check.


Here's your code but cleaned up. I'm thinking that you're trying to determine if the passed index is populated by a living bot on the Survivors team, with a human spectator on him?

PHP Code:
public bool HasIdlePlayer(int bot)
{
    if(
IsClientInGame(bot) && IsFakeClient(bot))
    {
        if(
IsPlayerAlive(bot) && GetClientTeam(bot) == TEAM_SURVIVORS)
        {
            
int client GetClientOfUserId(GetEntProp(botProp_Send"m_humanSpectatorUserID"))            
            if(
client)
            {
                if(
IsClientInGame(client) && !IsFakeClient(client) && GetClientTeam(client) == TEAM_SPECTATORS)
                    return 
true
            
}
        }
    }
    return 
false

__________________

Last edited by ddhoward; 03-21-2018 at 20:58.
ddhoward is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 03-22-2018 , 11:59   Re: "Client X is not connected" directly after IsClientConnected
Reply With Quote #17

Quote:
There's two calls. If it's the one for the client, you don't do a check.
What you mean? Here is a check:
Code:
	if(IsClientConnected(bot) && IsClientInGame(bot))
	{
		if((GetClientTeam(bot) == TEAM_SURVIVORS) && IsAlive(bot))
Two calls. Yes. But will something change if I write it inline?

ddhoward, you are right. Fixed now. Thank you. Again, not my code, so I didn't done optimization yet.
However, SM log say that exception raised in GetClientTeam(), not IsFakeClient().
BTW, thanks for IsClientInGame explanation.

Last edited by Dragokas; 03-22-2018 at 11:59.
Dragokas is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 03-22-2018 , 15:26   Re: "Client X is not connected" directly after IsClientConnected
Reply With Quote #18

I mean here:
PHP Code:
                int client GetClientOfUserId(GetEntProp(botProp_Send"m_humanSpectatorUserID"))            
                if(
client)
                {
                    if(!
IsFakeClient(client) && (GetClientTeam(client) == TEAM_SPECTATORS))
                        return 
true
                

You call GetClientTeam in two places. ddhoward's change adds another IsClientInGame check for the client one.

Last edited by Fyren; 03-22-2018 at 15:26.
Fyren is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 03-22-2018 , 15:38   Re: "Client X is not connected" directly after IsClientConnected
Reply With Quote #19

Fyren, ahh, I see. Thanks.
Dragokas is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 10:04.


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