Problem With Chat
#1

When I Use This CODE in My GM.
I can't chat.

PHP код:
if(text[0] == '!')
    {
      new 
name[24], string[256];
      
GetPlayerName(playeridname24);
      
format(stringsizeof(string), "{AD855C}[Team Chat]%s: %s"nametext[1]);
      for(new 
0MAX_PLAYERSi++)
       {
        if(
IsPlayerConnected(i))
        {
        if(
GetPlayerTeam(playerid) == GetPlayerTeam(i))
        
SendClientMessage(i,yellowstring);
        }
      }
    }
    return 
0
Reply
#2

Is anything at all coming up?
Reply
#3

Quote:
Originally Posted by Celson
Посмотреть сообщение
Is anything at all coming up?
yes..nothing Appear when i chat
Reply
#4

pawn Код:
if(GetPlayerTeam(playerid) == GetPlayerTeam(i))
    SendClientMessage(i,yellow, string);
change to
pawn Код:
if(GetPlayerTeam(playerid) == GetPlayerTeam(i)) SendClientMessage(i,yellow, string);
or
pawn Код:
if(GetPlayerTeam(playerid) == GetPlayerTeam(i))
    {
        SendClientMessage(i,yellow, string);
    }

If that doesn't work, check your GetPlayerTeam shit
Reply
#5

Still the Problem
i can't chat
Reply
#6

pawn Код:
format(string, sizeof(string), "{AD855C}[Team Chat]%s: %s", name, text[1]);
Why are you using 'text[1]'?

just use 'text'. Specifying an index in the array will return a number (the strval) and won't display because you've defined it in your format as a string (%s)
Reply
#7

Quote:
Originally Posted by Rob_Maate
Посмотреть сообщение
pawn Код:
format(string, sizeof(string), "{AD855C}[Team Chat]%s: %s", name, text[1]);
Why are you using 'text[1]'?

just use 'text'. Specifying an index in the array will return a number (the strval) and won't display because you've defined it in your format as a string (%s)
The reason he would use text[1] is to strip text[0] from the output....text[0] represents ! and text[1] represents the rest
Reply
#8

Remember OnPlayerText always returns true to be able to chat. So the code should be:

pawn Код:
public OnPlayerText(playerid, text[])
{
    // Rest of the code
    return 1;
}
So maybe try this
pawn Код:
//
if(text[0] == '!')
    {
      new name[24], string[256];
      GetPlayerName(playerid, name, 24);
      format(string, sizeof(string), "{AD855C}[Team Chat]%s: %s", name, text[1]);

      for(new i = 0; i < MAX_PLAYERS; i++)
       {
        if(IsPlayerConnected(i))
        {
        if(GetPlayerTeam(playerid) == GetPlayerTeam(i))
        SendClientMessage(i,yellow, string);
        }
      }
    }
    return 1;
Reply
#9

Nope. In pawno, a string array is not stored as a string.

The reason we MUST specify the array size to be one cell larger than the string itself, is because the last member of the array must carry the value 0 for it to be compiled as a string.

Because pawn is like this, you can actually create string arrays like this:
pawn Код:
new weird[6];
weird[0] = 68;
weird[1] = 65;
weird[2] = 73;
weird[3] = 86;
weird[4] = 68;
weird[5] = 0;
printf("%s", weird);
The output would be "DAVID"

EDIT: Try this

pawn Код:
if(text[0] == 33)
{
    new name[MAX_PLAYER_NAME];
    string[256];
    GetPlayerName(playerid, name, 24);
    new modifier[128];
    for(new i=1; i<sizeof(text); i++)
    {
        modifier[i-1] = text[i];
    }
    format(string, sizeof(string), "{AD855C}[Team Chat]%s: %s", name, modifier);
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(GetPlayerTeam(playerid) == GetPlayerTeam(i))
            {
                SendClientMessage(i,yellow, string);
            }
        }
    }
    return 1;
}
Reply
#10

Rob, please look at this before you reply again....https://sampwiki.blast.hk/wiki/OnPlayerText


playerid The ID of the player who typed the text.
text[] The text the player typed.

Returns Returning 0 in this callback will stop the text from being sent


So text[0] would be the first letter typed, text[1] would be the second, and so forth.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)