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

Solved [ANY] Native "ChangeClientTeam" reported: Client 32 is not in game


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
eyal282
Veteran Member
Join Date: Aug 2011
Old 01-15-2018 , 16:05   [ANY] Native "ChangeClientTeam" reported: Client 32 is not in game
Reply With Quote #1

I have this code for L4D2 ( It uses functions that work for all games though... ) and when I try shuffling the teams, I get the error in the title.

PHP Code:
#include <sourcemod>

native L4DStats_GetClientRank(client);

public 
Plugin:myinfo 
{
    
name "sm_rankshuffle",
    
author "Eyal282",
    
description "Shuffle teams by the rank of the players.",
    
version "1.0",
    
url "None."
}
public 
OnPluginStart()
{
    
RegAdminCmd("sm_rankshuffle"RankShuffleADMFLAG_KICK);
}

public 
Action:RankShuffle(clientargs)
{
    new 
players[MaxClients], num;
    
    for(new 
i=0;MaxClients;i++)
    {
        
players[i] = -1;
    }
    for(new 
i=1;<= MaxClients;i++)
    {
        if(!
IsClientInGame(client))
            continue;
            
        else if(
IsFakeClient(client))
            continue;
            
        else if(
GetClientTeam(client) == 1)
            continue;
            
        
players[num] = i;
        
num++;
    }
    
    
SortCustom1D(playersMaxClientsSortByRank);

    
    
// Just like Amx Mod X :D
    
    
new bool:Survivor false;
    for(new 
ii=0;ii num;ii++)
    {
        new 
players[ii];
        
        if(!
IsClientInGame(client))
            continue;
            
        else if(
IsFakeClient(client))
            continue;
    
        
ChangeClientTeam(iSurvivor 3);
        
Survivor = !Survivor;
    }
    
    
PrintToChatAll("\x03%N\x01 has shuffled the teams based \x04on rank!"client);
}

// @return                -1 if first should go before second
 // 0 if first is equal to second
 // 1 if first should go after second
public SortByRank(player1player2, Array[], Handle:hndl)
{
    if(
player1 == -&& player2 == -1
        return 
0;
    
    else if(
player1 == -&& player2 != -1)
        return 
1;
    
    else if(
player1 != -&& player2 == -1)
        return -
1;
    
    
// Until here, invalid players that should go last.
    
else if(L4DStats_GetClientRank(player1) == -420 && L4DStats_GetClientRank(player1) == L4DStats_GetClientRank(player2)) // Both are yet to be updated.
        
return 0;
        
    if(
L4DStats_GetClientRank(player1) == -420)
        return 
1;
        
    if(
L4DStats_GetClientRank(player2) == -420)
        return -
1;
    
    if(
L4DStats_GetClientRank(player1) < L4DStats_GetClientRank(player2))
        return -
1;
    
    return 
1;


Edit: SOLVED!

PHP Code:
#include <sourcemod>

native L4DStats_GetClientRank(client);

public 
Plugin:myinfo 
{
    
name "sm_rankshuffle",
    
author "Eyal282",
    
description "Shuffle teams by the rank of the players.",
    
version "1.0",
    
url "None."
}
public 
OnPluginStart()
{
    
RegAdminCmd("sm_rankshuffle"RankShuffleADMFLAG_KICK);
}

public 
Action:RankShuffle(clientargs)
{
    new 
players[MAXPLAYERS], num;
    
    for(new 
i=0;<= MaxClients;i++)
    {
        
players[i] = -1;
    }
    
    for(new 
i=1;<= MaxClients;i++)
    {
        if(!
IsClientInGame(client))
            continue;
            
        else if(
IsFakeClient(client))
            continue;
            
        else if(
GetClientTeam(client) == 1)
            continue;
            
        
players[num] = i;
        
num++;
    }
    
    
SortCustom1D(playersMAXPLAYERSSortByRank);

    
    
// Just like Amx Mod X :D
    
    
new bool:Survivor false;
    for(new 
ii=0;ii num;ii++)
    {
        new 
target players[ii];
        
        if(!
IsClientInGame(target))
            continue;
            
        else if(
IsFakeClient(target))
            continue;
    
        
ChangeClientTeam(targetSurvivor 3);
        
Survivor = !Survivor;
    }
    
    
PrintToChatAll("\x03%N\x01 has shuffled the teams based \x04on rank!"client);
    
    
AdminFakeClientCommand(client"sm_setpoints @all 200");
}

// @return                -1 if first should go before second
 // 0 if first is equal to second
 // 1 if first should go after second
public SortByRank(player1player2, Array[], Handle:hndl)
{
    if(!
IsPlayer(player1))
        
player1 = -1;
    
    if(!
IsPlayer(player2))
        
player2 = -1;
        
    if(
player1 == -&& player2 == -1
        return 
0;
    
    else if(
player1 == -&& player2 != -1)
        return 
1;
    
    else if(
player1 != -&& player2 == -1)
        return -
1;
    
    
// Until here, invalid players that should go last.
    
else if(L4DStats_GetClientRank(player1) == -420 && L4DStats_GetClientRank(player1) == L4DStats_GetClientRank(player2)) // Both are yet to be updated.
        
return 0;
        
    if(
L4DStats_GetClientRank(player1) == -420)
        return 
1;
        
    if(
L4DStats_GetClientRank(player2) == -420)
        return -
1;
    
    if(
L4DStats_GetClientRank(player1) < L4DStats_GetClientRank(player2))
        return -
1;
    
    return 
1;
}

stock IsPlayer(index)
{
    return ( 
index && index <= MaxClients ) ? true false;
}

stock AdminFakeClientCommand(clientString:Command[])
{
        new 
bits GetUserFlagBits(client); 
        
SetUserFlagBits(clientADMFLAG_ROOT); 
        
FakeClientCommand(clientCommand); 
        
SetUserFlagBits(clientbits); 


Last edited by eyal282; 01-16-2018 at 07:28.
eyal282 is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 01-15-2018 , 16:11   Re: [ANY] Native "ChangeClientTeam" reported: Client 32 is not in game
Reply With Quote #2

You have some instances where you're using "client" instead of the loop's variable. All of your IsClientInGame, IsFakeClient, and GetClientTeam checks are checking the command user, instead of the client it should be in the loop.
__________________
ddhoward is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 01-15-2018 , 17:15   Re: [ANY] Native "ChangeClientTeam" reported: Client 32 is not in game
Reply With Quote #3

Quote:
Originally Posted by ddhoward View Post
You have some instances where you're using "client" instead of the loop's variable. All of your IsClientInGame, IsFakeClient, and GetClientTeam checks are checking the command user, instead of the client it should be in the loop.
I get invalid memory access error on the line:

PHP Code:

players
[num] = i

Last edited by eyal282; 01-15-2018 at 17:31.
eyal282 is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 01-15-2018 , 20:17   Re: [ANY] Native "ChangeClientTeam" reported: Client 32 is not in game
Reply With Quote #4

Post your new code.
__________________
ddhoward is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 01-16-2018 , 02:18   Re: [ANY] Native "ChangeClientTeam" reported: Client 32 is not in game
Reply With Quote #5

PHP Code:
#include <sourcemod>

native L4DStats_GetClientRank(client);

public 
Plugin:myinfo 
{
    
name "sm_rankshuffle",
    
author "Eyal282",
    
description "Shuffle teams by the rank of the players.",
    
version "1.0",
    
url "None."
}
public 
OnPluginStart()
{
    
RegAdminCmd("sm_rankshuffle"RankShuffleADMFLAG_KICK);
}

public 
Action:RankShuffle(clientargs)
{
    new 
players[MaxClients-1], num;
    
    for(new 
i=0;MaxClients-1;i++)
    {
        
players[i] = -1;
    }
    
    for(new 
i=1;<= MaxClients;i++)
    {
        if(!
IsClientInGame(client))
            continue;
            
        else if(
IsFakeClient(client))
            continue;
            
        else if(
GetClientTeam(client) == 1)
            continue;
            
        
players[num] = i;
        
num++;
    }
    
    
SortCustom1D(playersMaxClients-1SortByRank);

    
    
// Just like Amx Mod X :D
    
    
new bool:Survivor false;
    for(new 
ii=0;ii num;ii++)
    {
        new 
target players[ii];
        
        if(!
IsClientInGame(target))
            continue;
            
        else if(
IsFakeClient(target))
            continue;
    
        
ChangeClientTeam(targetSurvivor 3);
        
Survivor = !Survivor;
    }
    
    
PrintToChatAll("\x03%N\x01 has shuffled the teams based \x04on rank!"client);
}

// @return                -1 if first should go before second
 // 0 if first is equal to second
 // 1 if first should go after second
public SortByRank(player1player2, Array[], Handle:hndl)
{
    if(
player1 == -&& player2 == -1
        return 
0;
    
    else if(
player1 == -&& player2 != -1)
        return 
1;
    
    else if(
player1 != -&& player2 == -1)
        return -
1;
    
    
// Until here, invalid players that should go last.
    
else if(L4DStats_GetClientRank(player1) == -420 && L4DStats_GetClientRank(player1) == L4DStats_GetClientRank(player2)) // Both are yet to be updated.
        
return 0;
        
    if(
L4DStats_GetClientRank(player1) == -420)
        return 
1;
        
    if(
L4DStats_GetClientRank(player2) == -420)
        return -
1;
    
    if(
L4DStats_GetClientRank(player1) < L4DStats_GetClientRank(player2))
        return -
1;
    
    return 
1;

eyal282 is offline
pride95
Senior Member
Join Date: Aug 2015
Old 01-16-2018 , 06:32   Re: [ANY] Native "ChangeClientTeam" reported: Client 32 is not in game
Reply With Quote #6

[QUOTE=eyal282;2572251]
PHP Code:
#include <sourcemod>

native L4DStats_GetClientRank(client);

public 
Plugin:myinfo 
{
    
name "sm_rankshuffle",
    
author "Eyal282",
    
description "Shuffle teams by the rank of the players.",
    
version "1.0",
    
url "None."
}
public 
OnPluginStart()
{
    
RegAdminCmd("sm_rankshuffle"RankShuffleADMFLAG_KICK);
}

public 
Action:RankShuffle(clientargs)
{
    new 
players[MAXPLAYERS 1], num// MAXPLAYERS + 1
    
    
for(new i=1;<= MaxClients;i++) // int i = 1
    
{
        
players[i] = -1;
    }
    
    for(new 
i=1;<= MaxClients;i++)
    {
        if(!
IsClientInGame(client))
            continue;
            
        else if(
IsFakeClient(client))
            continue;
            
        else if(
GetClientTeam(client) == 1)
            continue;
            
        
players[num] = i;
        
num++;
    }
    
    
SortCustom1D(playersMaxClients-1SortByRank);

    
    
// Just like Amx Mod X :D
    
    
new bool:Survivor false;
    for(new 
ii=0;ii num;ii++)
    {
        new 
target players[ii];
        
        if(!
IsClientInGame(target))
            continue;
            
        else if(
IsFakeClient(target))
            continue;
    
        
ChangeClientTeam(targetSurvivor 3);
        
Survivor = !Survivor;
    }
    
    
PrintToChatAll("\x03%N\x01 has shuffled the teams based \x04on rank!"client);
}

// @return                -1 if first should go before second
 // 0 if first is equal to second
 // 1 if first should go after second
public SortByRank(player1player2, Array[], Handle:hndl)
{
    if(
player1 == -&& player2 == -1
        return 
0;
    
    else if(
player1 == -&& player2 != -1)
        return 
1;
    
    else if(
player1 != -&& player2 == -1)
        return -
1;
    
    
// Until here, invalid players that should go last.
    
else if(L4DStats_GetClientRank(player1) == -420 && L4DStats_GetClientRank(player1) == L4DStats_GetClientRank(player2)) // Both are yet to be updated.
        
return 0;
        
    if(
L4DStats_GetClientRank(player1) == -420)
        return 
1;
        
    if(
L4DStats_GetClientRank(player2) == -420)
        return -
1;
    
    if(
L4DStats_GetClientRank(player1) < L4DStats_GetClientRank(player2))
        return -
1;
    
    return 
1;

pride95 is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 01-16-2018 , 07:15   Re: [ANY] Native "ChangeClientTeam" reported: Client 32 is not in game
Reply With Quote #7

[QUOTE=pride95;2572283]
Quote:
Originally Posted by eyal282 View Post
PHP Code:
#include <sourcemod>

native L4DStats_GetClientRank(client);

public 
Plugin:myinfo 
{
    
name "sm_rankshuffle",
    
author "Eyal282",
    
description "Shuffle teams by the rank of the players.",
    
version "1.0",
    
url "None."
}
public 
OnPluginStart()
{
    
RegAdminCmd("sm_rankshuffle"RankShuffleADMFLAG_KICK);
}

public 
Action:RankShuffle(clientargs)
{
    new 
players[MAXPLAYERS 1], num// MAXPLAYERS + 1
    
    
for(new i=1;<= MaxClients;i++) // int i = 1
    
{
        
players[i] = -1;
    }
    
    for(new 
i=1;<= MaxClients;i++)
    {
        if(!
IsClientInGame(client))
            continue;
            
        else if(
IsFakeClient(client))
            continue;
            
        else if(
GetClientTeam(client) == 1)
            continue;
            
        
players[num] = i;
        
num++;
    }
    
    
SortCustom1D(playersMaxClients-1SortByRank);

    
    
// Just like Amx Mod X :D
    
    
new bool:Survivor false;
    for(new 
ii=0;ii num;ii++)
    {
        new 
target players[ii];
        
        if(!
IsClientInGame(target))
            continue;
            
        else if(
IsFakeClient(target))
            continue;
    
        
ChangeClientTeam(targetSurvivor 3);
        
Survivor = !Survivor;
    }
    
    
PrintToChatAll("\x03%N\x01 has shuffled the teams based \x04on rank!"client);
}

// @return                -1 if first should go before second
 // 0 if first is equal to second
 // 1 if first should go after second
public SortByRank(player1player2, Array[], Handle:hndl)
{
    if(
player1 == -&& player2 == -1
        return 
0;
    
    else if(
player1 == -&& player2 != -1)
        return 
1;
    
    else if(
player1 != -&& player2 == -1)
        return -
1;
    
    
// Until here, invalid players that should go last.
    
else if(L4DStats_GetClientRank(player1) == -420 && L4DStats_GetClientRank(player1) == L4DStats_GetClientRank(player2)) // Both are yet to be updated.
        
return 0;
        
    if(
L4DStats_GetClientRank(player1) == -420)
        return 
1;
        
    if(
L4DStats_GetClientRank(player2) == -420)
        return -
1;
    
    if(
L4DStats_GetClientRank(player1) < L4DStats_GetClientRank(player2))
        return -
1;
    
    return 
1;

Using MAXPLAYERS instead of MAXPLAYERS+1 can throw an error?
eyal282 is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 01-16-2018 , 17:36   Re: [ANY] Native "ChangeClientTeam" reported: Client 32 is not in game
Reply With Quote #8

[QUOTE=eyal282;2572293]
Quote:
Originally Posted by pride95 View Post
Using MAXPLAYERS instead of MAXPLAYERS+1 can throw an error?
It doesn't matter if you use MAXPLAYERS or MaxClients, really, but if you have this (what you started with):

PHP Code:
new players[MaxClients-1];
...
for(new 
i=1;<= MaxClients;i++)
  do 
something with players[i
Then obviously your indices are going to be wrong. Think about what happens if there's only one client so MaxClients is 1.
Fyren is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 01-16-2018 , 17:56   Re: [ANY] Native "ChangeClientTeam" reported: Client 32 is not in game
Reply With Quote #9

[QUOTE=Fyren;2572406]
Quote:
Originally Posted by eyal282 View Post

It doesn't matter if you use MAXPLAYERS or MaxClients, really, but if you have this (what you started with):

PHP Code:
new players[MaxClients-1];
...
for(new 
i=1;<= MaxClients;i++)
  do 
something with players[i
Then obviously your indices are going to be wrong. Think about what happens if there's only one client so MaxClients is 1.
I'm talking about MAXPLAYERS vs MAXPLAYERS + 1, half of the plugins use MAXPLAYERS and others use MAXPLAYERS + 1, not related to MaxClients at all.
eyal282 is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 01-16-2018 , 19:55   Re: [ANY] Native "ChangeClientTeam" reported: Client 32 is not in game
Reply With Quote #10

You're still using (client) where you shouldn't be, and you shouldn't be declaring the "players" array with size MaxClient-1. also why not combine the two loops

PHP Code:
public Action:RankShuffle(clientargs)
{
    new 
players[MaxClients-1], num;
    
    for(new 
i=0;MaxClients-1;i++)
    {
        
players[i] = -1;
    }
    
    for(new 
i=1;<= MaxClients;i++)
    {
        if(!
IsClientInGame(client))
            continue;
            
        else if(
IsFakeClient(client))
            continue;
            
        else if(
GetClientTeam(client) == 1)
            continue;
            
        
players[num] = i;
        
num++;
    } 
becomes

PHP Code:
public Action:RankShuffle(clientargs)
{
    new 
players[MaxClients], num;
    
    for(new 
i=1;<= MaxClients;i++)
    {
       
players[i-1] = -1;

        if(!
IsClientInGame(i))
            continue;
            
        else if(
IsFakeClient(i))
            continue;
            
        else if(
GetClientTeam(i) == 1)
            continue;
            
        
players[num] = i;
        
num++;
    } 
__________________

Last edited by ddhoward; 01-16-2018 at 23:46.
ddhoward is offline
Reply



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 11:34.


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