AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Solved [TF2] Client is not in game bug (https://forums.alliedmods.net/showthread.php?t=318088)

MAGNAT2645 08-13-2019 16:53

[TF2] Client is not in game bug
 
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 );
}


Powerlord 08-13-2019 19:27

Re: [TF2] Client is not in game bug
 
Just to be clear, this is the only CreateTimer that uses the RespawnRebalanced callback?

PC Gamer 08-13-2019 19:35

Re: [TF2] Client is not in game bug
 
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.

MAGNAT2645 08-14-2019 03:21

Re: [TF2] Client is not in game bug
 
Quote:

Originally Posted by Powerlord (Post 2663122)
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 08-14-2019 03:24

Re: [TF2] Client is not in game bug
 
Quote:

Originally Posted by PC Gamer (Post 2663123)
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.

Whai 08-14-2019 03:45

Re: [TF2] Client is not in game bug
 
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

MAGNAT2645 08-14-2019 03:49

Re: [TF2] Client is not in game bug
 
But second part (IsPlayerAlive) won't execute if first part (iClient != 0) will return false...

Whai 08-14-2019 03:52

Re: [TF2] Client is not in game bug
 
Client 0 is the world/console

MAGNAT2645 08-14-2019 03:57

Re: [TF2] Client is not in game bug
 
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.

Whai 08-14-2019 04:05

Re: [TF2] Client is not in game bug
 
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


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

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