AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [SOLVE]My code make say team message print to everyone. (https://forums.alliedmods.net/showthread.php?t=163371)

GarbageBox 07-29-2011 14:53

[SOLVE]My code make say team message print to everyone.
 
I want to re-write the say team and I'm using a stock version color chat.
But when I test it, I found out that it print the team say message to another team.
How can fix it?
Code:

new szName[32], szTag[24];
new iPlayers[32], iNum;
//...
public hook_say_team(id)
{
        new szMessages[192];
        read_args(szMessages, 191);
        remove_quotes(szMessages);       
       
        get_user_name(id, szName, 31);
       
        new szAlive = is_user_alive(id);
       
        if(szMessages[0] != '@')
        {
                new szTeam[33], szDead[33];
                if(get_user_team(id) == 1)
                {
                        szTeam = "(TR)";
                        szDead = "*DEAD*";
                }
                else if(get_user_team(id) == 2)
                {
                        szTeam = "(CT)";
                        szDead = "*DEAD*";
                }
                else if(get_user_team(id) == 3)
                {
                        szTeam = "(SPEC)";
                        szDead = "";
                }
                (szAlive ? client_printc(0, "^x04%s ^x03%s ^x01: %s", szTeam, szName, szMessages) : client_printc(0, "^x01%s ^x04%s ^x03%s ^x01: %s", szDead, szTeam, szName, szMessages));
        }
        else
        {
                if(get_user_flags(id) & ADMIN_ADMIN)
                        szTag = "(ADMIN)"
                else
                        szTag = "(PLAYER)"
                       
                get_players(iPlayers , iNum , "ch");
               
                for(new i = 0; i < iNum; i++)
                {
                        if(get_user_flags(iPlayers[i]) & ADMIN_CHAT)
                        {
                                client_printc(iPlayers[i], "^x04%s ^x03%s ^x01: %s", szTag, szName, szMessages[1]);
                        }
                        if(get_user_flags(iPlayers[i]) & ADMIN_USER)
                        {
                                client_printc(id, "^x04%s ^x03%s ^x01: %s", szTag, szName, szMessages[1]);
                        }
                }
        }
}

stock client_printc(const id, const string[], {Float, Sql, Resul,_}:...)
{
        new msg[191], players[32], count = 1;
        vformat(msg, sizeof msg - 1, string, 3);
       
        replace_all(msg,190,"\g","^4");
        replace_all(msg,190,"\y","^1");
        replace_all(msg,190,"\t","^3");
       
        if(id)
                players[0] = id;
        else
                get_players(players,count,"ch");
       
        new index;
        for (new i = 0 ; i < count ; i++)
        {
                index = players[i];
                message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText"),_, index);
                write_byte(index);
                write_string(msg);
                message_end(); 
        } 
}


Exolent[jNr] 07-29-2011 16:12

Re: My code make say team message print to everyone.
 
Code:

                (szAlive ? client_printc(0, "^x04%s ^x03%s ^x01: %s", szTeam, szName, szMessages) : client_printc(0, "^x01%s ^x04%s ^x03%s ^x01: %s", szDead, szTeam, szName, szMessages));
That's why. You are using 0 for player index to print to, which is all players.

GarbageBox 07-30-2011 01:15

Re: My code make say team message print to everyone.
 
If I use id, it will print the message to myself only, other teammate can't see.

nikhilgupta345 07-30-2011 02:16

Re: My code make say team message print to everyone.
 
You have to make a loop and determine whether you want to display the message to the player or not by checking his team. And if you want to show the message to him, put that line there. (the client_printc line with the id of the user you are checking).


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

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