SA-MP Forums Archive
Team chat - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Team chat (/showthread.php?tid=257663)



Team chat - Wesley221 - 27.05.2011

Hey guys,

I can't find out how to make team chats..
Anyone could give me a hand making it, or give me a link to a tutorial or something?

NOTE:
Yes, i did search on ******, and also tried to do one(https://sampforum.blast.hk/showthread.php?tid=123655), but it gave me several errors.

Hope you guys can help me out
~Wesley


Re: Team chat - (SF)Noobanatior - 27.05.2011

something like this
pawn Код:
for(new i=0;i<MAX_PLAYERS;i++){
    if(!IsPlayerConnected(i))continue;
    if(team[playerid] == team){
        SendClientMessage(i,colour,"message");
    }
}
how are your teams selected


Re: Team chat - Unknown_Killer - 27.05.2011

this is a full example how u make team chat
PHP код:
#include <a_samp>
#include <foreach>
#define COLOR_YELLOW 0xFFFF00AA
#define team_1 0
#define team_2 1
static gTeam[MAX_PLAYERS];
new 
nameee[20];
public 
OnPlayerCommandText(playeridcmdtext[])
{
new 
string[100];
new 
cmd[256];
if(
strcmp(cmd"/chat",true) == || strcmp(cmd"/c"true) == 0)
{
   for(new 
i=0i<256i++)
   {
      if( 
gTeam[playerid] == team_1)
      {
      
GetPlayerName(playerid,nameee,sizeof(nameee));format(string,sizeof(string),"Team Chat (%s) says :    %s",nameee,cmdtext[3]);Sendteam1Message(COLOR_YELLOWstring);
        }
      if( 
gTeam[playerid] == team_2) {
      
GetPlayerName(playerid,nameee,sizeof(nameee));    format(string,sizeof(string),"Team Chat (%s) says : %s",nameee,cmdtext[3]);Sendteam2Message(COLOR_YELLOWstring);
        }
   }
   return 
1;
   }
return 
1;
}
Sendteam1Message(colortext[])
{
    foreach(
Playeri) {
        if (
gTeam[i] == team_1 ) {
            
SendClientMessage(icolortext);
        }
    }
    return 
1;
}
Sendteam2Message(colortext[])
{
    foreach(
Playeri) {
        if (
gTeam[i] == team_2) {
            
SendClientMessage(icolortext);
        }
    }
    return 
1;




Re: Team chat - Wesley221 - 27.05.2011

pawn Код:
public OnPlayerText(playerid, text[])
{
    if(text[0] == '!')
    {
        new NameP[256], string[256], cmdtext[256];
        for(new i=0; i<256; i++)
        {
            if(gTeam[playerid] == Stunt)
            {
                GetPlayerName(playerid,NameP,sizeof(NameP));
                format(string,sizeof(string),"|- Stunt Chat -| (%s): %s",NameP,cmdtext[3]);
                SendStuntMessage(COLOR_YELLOW, string);
            }

            if( gTeam[playerid] == Trucker)
            {
                GetPlayerName(playerid,NameP,sizeof(NameP));
                format(string,sizeof(string),"|- Trucker Chat -| (%s): %s",NameP,cmdtext[3]);
                SendTruckerMessage(COLOR_YELLOW, string);
            }
        }
    }

    return 1;
}
pawn Код:
SendStuntMessage(color, text[])
{
    foreach(Player, i)
    {
        if (gTeam[i] == Stunt)
        {
            SendClientMessage(i, color, text);
        }
    }
    return 1;
}

SendTruckerMessage(color, text[])
{
    foreach(Player, i)
    {
        if(gTeam[i] == Trucker)
        {
            SendClientMessage(i, color, text);
        }
    }
    return 1;
}
I got it like this, but when i go in-game and type "! test 123 text", it just says: "! test 123 text"
What am i doing wrong?

Quote:

Try Again in 22 seconds...




Re: Team chat - Wesley221 - 27.05.2011

Hmm.. my bad; i wasn't Stunt/Trucker.. hehe

But when i do ! test, it just gives me alot of "|- Stunt Chat -| Name:"
But it doesnt display the text after Name: 'in here'

What should i do?

Edit:
I fixed the spam thing, but now the only problem is that it doesnt show the text.

"|- Stunt Chat -| Wesley221: "
"! test"

Thats how i get it, and not |- Stunt Chat -| Wesley221: test"


Re: Team chat - Unknown_Killer - 27.05.2011

try this

PHP код:
public OnPlayerText(playeridtext[])
{
    if(
text[0] == '!')
    {
        new 
NameP[256], string[256];
        for(new 
i=0i<256i++)
        {
            if(
gTeam[playerid] == Stunt)
            {
                
GetPlayerName(playerid,NameP,sizeof(NameP));
                
format(string,sizeof(string),"|- Stunt Chat -| (%s): %s",NameP,text[1]);
                
SendStuntMessage(COLOR_YELLOWstring);
            }
            if( 
gTeam[playerid] == Trucker)
            {
                
GetPlayerName(playerid,NameP,sizeof(NameP));
                
format(string,sizeof(string),"|- Trucker Chat -| (%s): %s",NameP,text[1]);
                
SendTruckerMessage(COLOR_YELLOWstring);
            }
        }
    }
    return 
1;




Re: Team chat - Wesley221 - 27.05.2011

Still doesnt work.

This is what i get:

"|- Stunt Chat -| Wesley221: "
"! test"

EDIT:
Changed some things, and it works fine now, except it's saying "! test" under the "|- Stunt Chat -| Wesley221: test"

"|- Stunt Chat -| Wesley221: test"
"Wesley221(0): ! test"


Re: Team chat - Unknown_Killer - 27.05.2011

hmmm try also this

PHP код:
public OnPlayerText(playeridtext[])
{
    if(
text[0] == '!')
    {
        for(new 
i=0i<256i++)
        {
            if(
gTeam[playerid] == team_1)
            {
                new 
string[128]; GetPlayerName(playerid,string,sizeof(string));
                
format(string,sizeof(string),"|- Stunt Chat -| (%s): %s",string,text[1]);
                
Sendteam1Message(COLOR_YELLOWstring);
            }
            if( 
gTeam[playerid] == team_2)
            {
                new 
string[128]; GetPlayerName(playerid,string,sizeof(string));
                
format(string,sizeof(string),"|- Trucker Chat -| (%s): %s",string,text[1]);
                
Sendteam2Message(COLOR_YELLOWstring);
            }
        }
    }
    return 
1;

i hope this works


Re: Team chat - Wesley221 - 27.05.2011

Ah nevermind, i found the solution

pawn Код:
if(text[0] == '!')
    {
        new NameP[256], string[256];
        for(new i=0; i<256; i++)
        {
            if(gTeam[playerid] == Stunt)
            {
                GetPlayerName(playerid,NameP,sizeof(NameP));
                format(string,sizeof(string),"|- Stunt Chat -| %s: %s",NameP,text[1]);
                SendStuntMessage(COLOR_YELLOW, string);
                return 0;
            }

            if( gTeam[playerid] == Trucker)
            {
                GetPlayerName(playerid,NameP,sizeof(NameP));
                format(string,sizeof(string),"|- Trucker Chat -| %s: %s",NameP,text[1]);
                SendTruckerMessage(COLOR_YELLOW, string);
                return 0;
            }
        }
    }
Just had to change the "return 1;" to "return 0;"
Thanks for your help!
~Wesley