SA-MP Forums Archive
Team Chat Help - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Team Chat Help (/showthread.php?tid=319584)



Team Chat Help - SpiderWalk - 19.02.2012

I have problem but i dont know how to fix it.

Problem is in this:When i type "!Hi" all 2 teams see that message not just 1 team but all teams see that message and i dont know how to fix that!

pawn Код:
new string[256];
    new playername[MAX_PLAYER_NAME];
    if(text[0] == '!' && text[1] != 0)
    {
        GetPlayerName( playerid, playername, MAX_PLAYER_NAME );
        format( string, 128, "[Team-Chat] %s: %s", playername, text[1] );
        if(GetPlayerTeam(playerid) == 1)
        {
            for(new i = 0; i < MAX_PLAYERS; i++ )
            {
                SendClientMessage( i, yellow, string );
            }
        }
        if(GetPlayerTeam(playerid) == 2)
        {
            for(new i = 0; i < MAX_PLAYERS; i++ )
            {
                SendClientMessage( i, yellow, string );
            }
        }
        return 0;
    }



Re: Team Chat Help - emokidx - 19.02.2012

try
pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++ )
{
            if(GetPlayerTeam(i) == 1 && IsPlayerConnected(i))
            {
                SendClientMessage( i, yellow, string );
            }
}
for(new i = 0; i < MAX_PLAYERS; i++ )
{
        if(GetPlayerTeam(i) == 2 && IsPlayerConnected(i))
        {
                SendClientMessage( i, yellow, string );
        }
}



AW: Team Chat Help - Nero_3D - 19.02.2012

Quote:
Originally Posted by SpiderWalk
Посмотреть сообщение
I have problem but i dont know how to fix it.

Problem is in this:When i type "!Hi" all 2 teams see that message not just 1 team but all teams see that message and i dont know how to fix that!

pawn Код:
//CODE
its because you send the message to everyone

pawn Код:
//
    if( (text[0] == '!') && (text[1] != 0) ) {
        new
            i,
            string[256],
            team = GetPlayerTeam(playerid)
        ;
        GetPlayerName( playerid, string, MAX_PLAYER_NAME );
        format( string, sizeof string, "[Team-Chat] %s: %s", string, text[1] );
        for( ; i != MAX_PLAYERS; ++i ) {
            if( GetPlayerTeam(i) == team ) {
                SendClientMessage( i, yellow, string );
            }
        }
        return 0;
    }