Raised This Month: $ Target: $400
 0% 

get_players & cs_get_user_team is inaccurate


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
bLacK-bLooD
AlliedModders Donor
Join Date: Jun 2008
Old 10-05-2014 , 03:30   get_players & cs_get_user_team is inaccurate
Reply With Quote #1

Hi, i am using a chat plugin that allows tags to be used by admins, but i often have problems with detecting the right team of players when they chat. As far as i have been able to research the problem, get_players doesn't update the index of the player if he has moved while alive, but it's not the case here. They just chat and all of a sudden they have wrong team color (as if he is CT but chat is displaying spectator or T for no reason)

So i am sharing here the code, perhaps someone can figure it out.

PHP Code:
public plugin_init {
    
register_clcmd("say","hook_say");
    
register_clcmd("say_team","hook_say2");
}

public 
hook_say(id) {
    if(
is_user_bot(id)) {
        return 
PLUGIN_CONTINUE;
    }
    
    if(!
is_user_connected(id)) {
        return 
PLUGIN_CONTINUE
    
}
    
    new 
nick[32];
    
get_user_name(id,nick,31);
    
    static 
chat[192];
    
read_args(chatsizeof(chat) - 1);
    
remove_quotes(chat);
    
    if(
equali(chat,"")) {
        return 
PLUGIN_CONTINUE;
    }
    
    if(( 
contain(chat"/who") != -|| contain(chat"/admin") != -|| contain(chat"/admins") != -1))
    
set_task(time_shower,"who_motd",id)
    
    if(
is_user_admin(id)) {
        for(new 
i=0i<MAX_GROUPSi++) {
            if(
get_user_flags(id) == g_RangFlag_Value[i]) {
                switch(
cs_get_user_team(id)) {
                    case 
CS_TEAM_T:
                    {
                        if(
is_user_alive(id)) {
                            
ColorChat(0,GREEN,"[%s] ^x03%s^x01: %s",g_Rang[i],nick,chat);
                        }
                        else if(!
is_user_alive(id)) {
                            
ColorChat(0,NORMAL,"*DEAD*^x04[%s] ^x03%s^x01: %s",g_Rang[i],nick,chat);
                            
                        }
                    }
                    case 
CS_TEAM_CT:
                    {
                        if(
is_user_alive(id)) {
                            
ColorChat(0,GREEN,"[%s] ^x03%s^x01: %s",g_Rang[i],nick,chat);
                        }
                        else if(!
is_user_alive(id)) {
                            
ColorChat(0,NORMAL,"*DEAD*^x04[%s] ^x03%s^x01: %s",g_Rang[i],nick,chat);
                            
                        }
                    }
                    case 
CS_TEAM_SPECTATOR:
                    {
                        
ColorChat(0,GREY,"*SPEC*^x04[%s] ^x03%s^x01: %s",g_Rang[i],nick,chat);
                    }
                }
            }
        }
        return 
PLUGIN_HANDLED;
    }
    else {        
    
        switch(
cs_get_user_team(id)) {
        
            case 
CS_TEAM_T:
            {
                if(
is_user_alive(id)) {
                    
ColorChat(0,RED,"%s^x01: %s",nick,chat);
                }
                else if(!
is_user_alive(id)) {
                    
ColorChat(0,NORMAL,"*DEAD*^x03%s^x01: %s",nick,chat);
                }
            }
            case 
CS_TEAM_CT:
            {
                if(
is_user_alive(id)) {
                    
ColorChat(0,BLUE,"%s^x01: %s",nick,chat);
                }
                else if(!
is_user_alive(id)) {
                    
ColorChat(0,NORMAL,"*DEAD*^x03%s^x01: %s",nick,chat);
                }
            }
            case 
CS_TEAM_SPECTATOR:
            {
                    
ColorChat(0,GREY,"%s^x01: %s",nick,chat);
            }
            
        }
        return 
PLUGIN_HANDLED;
        
    }
    return 
PLUGIN_CONTINUE;
}

public 
hook_say2(id) {
    if(
is_user_bot(id)) {
        return 
PLUGIN_CONTINUE;
    }
    
    if(!
is_user_connected(id)) {
        return 
PLUGIN_CONTINUE
    
}
    
    new 
nick[32];
    
get_user_name(id,nick,31);
    
    static 
chat[192];
    
read_args(chatsizeof(chat) - 1);
    
remove_quotes(chat);
    
    if(
equali(chat,"")) {
        return 
PLUGIN_CONTINUE;
    }
    
    if((
contain(chat"/who") != -|| contain(chat"/admin") != -|| contain(chat"/admins") != -1))
        
set_task(time_shower,"who_motd",id)
    
    if(
is_user_admin(id)) {
        for(new 
i=0i<MAX_GROUPSi++) {
            if(
get_user_flags(id) == g_RangFlag_Value[i]) {
                new 
players[32],num;
                
get_players(players,num,"c");
                
                for(new 
x=0x<numx++) {
                    if(
cs_get_user_team(id) == cs_get_user_team(players[x])) {
                        switch(
cs_get_user_team(id)) {
                            case 
CS_TEAM_T:
                            {
                                if(
is_user_alive(id)) {
                                    
ColorChat(players[x],NORMAL,"(Terrorist)^x04[%s]^x03%s^x01: %s",g_Rang[i],nick,chat);
                                }
                                else if(!
is_user_alive(id)) {
                                    
ColorChat(players[x],NORMAL,"*DEAD*^x03(Terrorist)^x04[%s]^x03%s^x01: %s",g_Rang[i],nick,chat);
                                    
                                }
                            }
                            case 
CS_TEAM_CT:
                            {
                                if(
is_user_alive(id)) {
                                    
ColorChat(players[x],NORMAL,"(Counter-Terrorist)^x04[%s]^x03%s^x01: %s",g_Rang[i],nick,chat);
                                }
                                else if(!
is_user_alive(id)) {
                                    
ColorChat(players[x],NORMAL,"*DEAD*^x03(Counter-Terrorist)^x04[%s]^x03%s^x01: %s",g_Rang[i],nick,chat);
                                    
                                }
                            }
                            case 
CS_TEAM_SPECTATOR:
                            {
                                
ColorChat(players[x],GREY,"(Spectator)^x04[%s]^x03%s^x01: %s",g_Rang[i],nick,chat);
                            }
                        }
                    }
                    
                    else {
                        if(
cs_get_user_team(id) == cs_get_user_team(players[x])) {
                            switch(
cs_get_user_team(id)) {
                                case 
CS_TEAM_T:
                                {
                                    if(
is_user_alive(id)) {
                                        
ColorChat(players[x],NORMAL,"(Terrorist)^x04[Admin]^x03 %s^x01: %s",nick,chat);
                                    }
                                    else if(!
is_user_alive(id)) {
                                        
ColorChat(players[x],NORMAL,"*DEAD*^x03(Terrorist)^x04[Admin]^x03 %s^x01: %s",nick,chat);
                                    }
                                }
                                case 
CS_TEAM_CT:
                                {
                                    if(
is_user_alive(id)) {
                                        
ColorChat(players[x],BLUE,"(Counter-Terrorist) %s^x04 (Admin) : %s",nick,chat);
                                    }
                                    else if(!
is_user_alive(id)) {
                                        
ColorChat(players[x],NORMAL,"*DEAD*^x03(Counter-Terrorist)^x04[ADMIN]^x03 %s^x01: %s",nick,chat);
                                    }
                                }
                                case 
CS_TEAM_SPECTATOR:
                                {
                                    
ColorChat(players[x],GREY,"(Spectator)^x04[ADMIN]^x03 %s^x01: %s",nick,chat);
                                }
                            }
                        }
                    }
                }
                return 
PLUGIN_HANDLED;
            }
        }
    }
    else {
        new 
players[32],num;
        
get_players(players,num,"c");
        
        for(new 
x=0x<numx++) {
            if(
cs_get_user_team(id) == cs_get_user_team(players[x])) {
                switch(
cs_get_user_team(id)) {
                    case 
CS_TEAM_T:
                    {
                        if(
is_user_alive(id)) {
                            
ColorChat(players[x],NORMAL,"(Terrorist)^x03 %s^x01: %s",nick,chat);
                        }
                        else if(!
is_user_alive(id)) {
                            
ColorChat(players[x],NORMAL,"*Mort*(Terrorist)^x03 %s^x01: %s",nick,chat);
                        }
                    }
                    case 
CS_TEAM_CT:
                    {
                        if(
is_user_alive(id)) {
                            
ColorChat(players[x],NORMAL,"(Counter-Terrorist)^x03 %s^x01: %s",nick,chat);
                        }
                        else if(!
is_user_alive(id)) {
                            
ColorChat(players[x],NORMAL,"*Mort*(Counter-Terrorist)^x03 %s^x01: %s",nick,chat);
                        }
                    }
                    case 
CS_TEAM_SPECTATOR:
                    {
                        if(
is_user_alive(id)) {
                            
ColorChat(players[x],GREY,"(Spectator) %s^x01: %s",nick,chat);
                        }
                        
                    }
                }
            }
            return 
PLUGIN_HANDLED;
        }
    }
    return 
PLUGIN_CONTINUE;

I also want to mention that admins have the same problem when displaying a message in chat (wrong team)

Thank you and have a nice day.

Last edited by bLacK-bLooD; 10-05-2014 at 03:32.
bLacK-bLooD is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 10-05-2014 , 03:45   Re: get_players & cs_get_user_team is inaccurate
Reply With Quote #2

What AMXX version do you use?

Actually I'm not sure to understand your problem. Please give a concrete and reproducible way which shows the issue. If you do nothing except chat it should be easy to give an example.
__________________

Last edited by Arkshine; 10-05-2014 at 03:50.
Arkshine is offline
bLacK-bLooD
AlliedModders Donor
Join Date: Jun 2008
Old 10-05-2014 , 03:49   Re: get_players & cs_get_user_team is inaccurate
Reply With Quote #3

Code:
[  1] AMX Mod X, v1.8.2, Feb 14 2013, by AMX Mod X Dev Team, see http://www.amxmodx.org
bLacK-bLooD is offline
Nextra
Veteran Member
Join Date: Apr 2008
Location: Germany
Old 10-05-2014 , 09:11   Re: get_players & cs_get_user_team is inaccurate
Reply With Quote #4

There have been some issues around player teams resolved with 1.8.3, but it is conceptually impossible for cs_get_user_team to return the wrong value, as it is mod dependent and directly looks at the team offset in the client's private data.
__________________
In Flames we trust!
Nextra is offline
bLacK-bLooD
AlliedModders Donor
Join Date: Jun 2008
Old 10-05-2014 , 09:13   Re: get_players & cs_get_user_team is inaccurate
Reply With Quote #5

Quote:
Originally Posted by Nextra View Post
There have been some issues around player teams resolved with 1.8.3, but it is conceptually impossible for cs_get_user_team to return the wrong value, as it is mod dependent and directly looks at the team offset in the client's private data.
Then why would it happen to me? Is the code fine?
bLacK-bLooD is offline
neverminde
Senior Member
Join Date: Feb 2011
Location: St.Piter
Old 10-05-2014 , 09:37   Re: get_players & cs_get_user_team is inaccurate
Reply With Quote #6

^x03
because this one use USER team color ?

so admin is CT. chatting: Hello
CTs see blue name: "Hello"
Ts see red name: "Hello"

Yup ?

Last edited by neverminde; 10-05-2014 at 09:40.
neverminde is offline
bLacK-bLooD
AlliedModders Donor
Join Date: Jun 2008
Old 10-05-2014 , 09:52   Re: get_players & cs_get_user_team is inaccurate
Reply With Quote #7

I don't think that's the problem, because you see, i display the messages using 0, which is for everyone, not id.
bLacK-bLooD is offline
neverminde
Senior Member
Join Date: Feb 2011
Location: St.Piter
Old 10-05-2014 , 09:58   Re: get_players & cs_get_user_team is inaccurate
Reply With Quote #8

Quote:
Originally Posted by bLacK-bLooD View Post
I don't think that's the problem, because you see, i display the messages using 0, which is for everyone, not id.
You need to send RED color if admin is T, not team color
team color for T is red
team color for CT is blue

you send !teamcolor name: !normal chat message
neverminde is offline
bLacK-bLooD
AlliedModders Donor
Join Date: Jun 2008
Old 10-05-2014 , 10:06   Re: get_players & cs_get_user_team is inaccurate
Reply With Quote #9

Ok, i get what you mean, but isn't this what i am already doing?

Take this for instance:

PHP Code:
            case CS_TEAM_T:
            {
                if(
is_user_alive(id)) {
                    
ColorChat(0,RED,"%s^x01: %s",nick,chat);
                }
                else if(!
is_user_alive(id)) {
                    
ColorChat(0,NORMAL,"*DEAD*^x03%s^x01: %s",nick,chat);
                }
            } 
If the player is alive, we go for the red color, because that's the T's color. If the player is dead then we go for ^x03 (!teamcolor as you said)
bLacK-bLooD is offline
neverminde
Senior Member
Join Date: Feb 2011
Location: St.Piter
Old 10-05-2014 , 10:30   Re: get_players & cs_get_user_team is inaccurate
Reply With Quote #10

Just look at Admin chat colors plugin method

https://forums.alliedmods.net/showthread.php?t=63610

PHP Code:
changeTeamInfo (playercolor)        // Changes user's team according to color choosen

public changeTeamInfo (playerteam[])
{
    
message_begin (MSG_ONEteamInfo_player)    // Tells to to modify teamInfo (Which is responsable for which time player is)
    
write_byte (player)                // Write byte needed
    
write_string (team)                // Changes player's team
    
message_end()                    // Also Needed

Author changes team if it's different with admin team. For correct color
neverminde 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 17:42.


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