AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   get_players & cs_get_user_team is inaccurate (https://forums.alliedmods.net/showthread.php?t=249391)

bLacK-bLooD 10-05-2014 03:30

get_players & cs_get_user_team is inaccurate
 
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.

Arkshine 10-05-2014 03:45

Re: get_players & cs_get_user_team is inaccurate
 
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.

bLacK-bLooD 10-05-2014 03:49

Re: get_players & cs_get_user_team is inaccurate
 
Code:

[  1] AMX Mod X, v1.8.2, Feb 14 2013, by AMX Mod X Dev Team, see http://www.amxmodx.org

Nextra 10-05-2014 09:11

Re: get_players & cs_get_user_team is inaccurate
 
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.

bLacK-bLooD 10-05-2014 09:13

Re: get_players & cs_get_user_team is inaccurate
 
Quote:

Originally Posted by Nextra (Post 2207390)
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?

neverminde 10-05-2014 09:37

Re: get_players & cs_get_user_team is inaccurate
 
^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 ?

bLacK-bLooD 10-05-2014 09:52

Re: get_players & cs_get_user_team is inaccurate
 
I don't think that's the problem, because you see, i display the messages using 0, which is for everyone, not id.

neverminde 10-05-2014 09:58

Re: get_players & cs_get_user_team is inaccurate
 
Quote:

Originally Posted by bLacK-bLooD (Post 2207419)
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

bLacK-bLooD 10-05-2014 10:06

Re: get_players & cs_get_user_team is inaccurate
 
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)

neverminde 10-05-2014 10:30

Re: get_players & cs_get_user_team is inaccurate
 
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


All times are GMT -4. The time now is 17:42.

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