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

Solved [TF2] Client is not in game bug


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
MAGNAT2645
Senior Member
Join Date: Nov 2015
Location: AlliedMods.net
Old 08-13-2019 , 16:53   [TF2] Client is not in game bug
Reply With Quote #1

SM logs this annoying "is not in game" error but i've put client check via userid.

Code:
L 08/11/2019 - 09:11:29: [SM] Exception reported: Client 3 is not in game
L 08/11/2019 - 09:11:29: [SM] Blaming: disabled/deathrun_redux.smx
L 08/11/2019 - 09:11:29: [SM] Call stack trace:
L 08/11/2019 - 09:11:29: [SM]   [0] IsPlayerAlive
L 08/11/2019 - 09:11:29: [SM]   [1] Line 1666, DeathRun Redux 2019::RespawnRebalanced
Code part #1:
Code:
public void OnPlayerSpawn(Event event, const char[] name, bool dontBroadcast) {
	if ( !g_bIsDRmap )
		return;

	int iClient = GetClientOfUserId( event.GetInt( "userid" ) );
	if ( !iClient )
		return;

	if ( g_bDisableFallDamage )
		TF2Attrib_SetByName( iClient, "cancel falling damage", 1.0 );

	int iCond = GetEntProp( iClient, Prop_Send, "m_nPlayerCond" );
	if ( iCond & PLAYERCOND_SPYCLOAK )
		SetEntProp( iClient, Prop_Send, "m_nPlayerCond", iCond | ~PLAYERCOND_SPYCLOAK );

	if ( GetClientTeam( iClient ) == TEAM_BLUE && iClient != g_iLastDeath ) {
		ChangeAliveClientTeam( iClient, TEAM_RED );
		CreateTimer( 0.2, RespawnRebalanced, GetClientUserId( iClient ) );
	}

	if ( g_bOnPreparation )
		SetEntityMoveType( iClient, MOVETYPE_NONE );
}
Code part #2:
Code:
	g_iLastDeath = iNewDeath;
	int iTeam;
	for ( int i = 1; i <= MaxClients; i++ ) {
		if ( !IsClientInGame( i ) )
			continue;

		iTeam = GetClientTeam( i );
		if ( iTeam < TEAM_RED )
			continue;

		if ( i == iNewDeath ) {
			if ( iTeam != TEAM_BLUE )
				ChangeAliveClientTeam( i, TEAM_BLUE );

			if ( TF2_GetPlayerClass( i ) == TFClass_Unknown )
				TF2_SetPlayerClass( i, TFClass_Scout, false, true );

			g_iQueuePriory[ i ] = 1;
		}
		else if ( iTeam != TEAM_RED )
			ChangeAliveClientTeam( i, TEAM_RED );

		CreateTimer( 0.2, RespawnRebalanced, GetClientUserId( i ) );
	}
RespawnRebalanced code:
Code:
public Action RespawnRebalanced(Handle timer, any data) {
	int iClient = GetClientOfUserId( data );
	if ( iClient && !IsPlayerAlive( iClient ) )
		TF2_RespawnPlayer( iClient );
}
__________________

Last edited by MAGNAT2645; 08-16-2019 at 08:11. Reason: I think, it's solved
MAGNAT2645 is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 08-13-2019 , 19:27   Re: [TF2] Client is not in game bug
Reply With Quote #2

Just to be clear, this is the only CreateTimer that uses the RespawnRebalanced callback?
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 08-13-2019 , 19:35   Re: [TF2] Client is not in game bug
Reply With Quote #3

I sometimes get that error. Very rare for me, but after testing I found it to be valid. The cause for me was running code on Bots who were kicked after checking if in game but before code could completely finish executing. A human player would join the game and a bot would be kicked at just the right moment to pop that error. As I said... very rare.
PC Gamer is offline
MAGNAT2645
Senior Member
Join Date: Nov 2015
Location: AlliedMods.net
Old 08-14-2019 , 03:21   Re: [TF2] Client is not in game bug
Reply With Quote #4

Quote:
Originally Posted by Powerlord View Post
Just to be clear, this is the only CreateTimer that uses the RespawnRebalanced callback?
Yes, i've checked that only these two timers uses RespawnRebalanced.
__________________
MAGNAT2645 is offline
MAGNAT2645
Senior Member
Join Date: Nov 2015
Location: AlliedMods.net
Old 08-14-2019 , 03:24   Re: [TF2] Client is not in game bug
Reply With Quote #5

Quote:
Originally Posted by PC Gamer View Post
I sometimes get that error. Very rare for me, but after testing I found it to be valid. The cause for me was running code on Bots who were kicked after checking if in game but before code could completely finish executing. A human player would join the game and a bot would be kicked at just the right moment to pop that error. As I said... very rare.
This error appears on public server with no bots.
__________________
MAGNAT2645 is offline
Whai
Senior Member
Join Date: Jul 2018
Old 08-14-2019 , 03:45   Re: [TF2] Client is not in game bug
Reply With Quote #6

You have to do that :
PHP Code:
if ( iClient )
   if ( !
IsPlayerAliveiClient ) )
      
TF2_RespawnPlayeriClient ); 
Because your code checks the client index is not equal to 0 BUT also checks at the SAME TIME if the player is alive
__________________

Last edited by Whai; 08-14-2019 at 03:46.
Whai is offline
MAGNAT2645
Senior Member
Join Date: Nov 2015
Location: AlliedMods.net
Old 08-14-2019 , 03:49   Re: [TF2] Client is not in game bug
Reply With Quote #7

But second part (IsPlayerAlive) won't execute if first part (iClient != 0) will return false...
__________________

Last edited by MAGNAT2645; 08-14-2019 at 03:50.
MAGNAT2645 is offline
Whai
Senior Member
Join Date: Jul 2018
Old 08-14-2019 , 03:52   Re: [TF2] Client is not in game bug
Reply With Quote #8

Client 0 is the world/console
__________________
Whai is offline
MAGNAT2645
Senior Member
Join Date: Nov 2015
Location: AlliedMods.net
Old 08-14-2019 , 03:57   Re: [TF2] Client is not in game bug
Reply With Quote #9

I know, but first part won't execute second part if [first] results to false
so this might be a bug

I mean, error prints client indexes higher than 0 but these clients aren't in the game.
__________________

Last edited by MAGNAT2645; 08-14-2019 at 04:03.
MAGNAT2645 is offline
Whai
Senior Member
Join Date: Jul 2018
Old 08-14-2019 , 04:05   Re: [TF2] Client is not in game bug
Reply With Quote #10

GetClientOfUserId is supposed return 0 if the userid is not valid as I understood so it should return 0 if the client is not in-game. I suggest to add IsClientInGame before IsPlayerAlive
__________________

Last edited by Whai; 08-14-2019 at 04:06.
Whai 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 00:50.


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