Cant Use Chat
#1

I cant see my chat and others chat in my server, other player experienced the same situation aswell, I think the problem is from OnPlayerText, but I dont have any clue what is the error

PHP код:
public OnPlayerText(playeridtext[])
{
    new 
string[MAX_PLAYERS], var = GetPlayerVirtualWorld(playerid);
    
//
     
if(text[0] == '@' && Account[playerid][Admin] >= 1)
      {
           
format(stringsizeof(string), "** |Admin Chat| %s: %s **"IsPlayerName(playerid), text[1]);
        for(new 
0MAX_PLAYERSi++)
          {
            if(
IsPlayerConnected(i) && Account[i][Admin] >= 1)
              {
              
SendClientMessage(i0x0AFFC9FFstring);
              return 
0;
            }
        }
    }
    if(
text[0] == '!' && Account[playerid][Vip] >= 1)
    {
        
format(stringsizeof(string), "~> |Vip Chat| %s: %s <~"IsPlayerName(playerid), text[1]);
         for(new 
0MAX_PLAYERSi++)
           {
             if(
IsPlayerConnected(i) && Account[i][Vip] >= 1)
               {
               
SendClientMessage(i0xFF0099AAstring);
               return 
0;
            }
        }
       }
      else
    {
         
format(stringsizeof(string), "%s (%d): {FFFFFF}%s"IsPlayerName(playerid), playeridtext);
           for(new 
0MAX_PLAYERSi++)
            {
              if(
IsPlayerConnected(i))
               {
                    if(
GetPlayerVirtualWorld(i) == var)
                  {
                       
SendClientMessage(iGetPlayerColor(playerid), string);
                       return 
0;
                  }
            }
        }
       }
       return 
1;

Help please
Reply
#2

Quote:
Originally Posted by AfiqIqbal
Посмотреть сообщение
I cant see my chat and others chat in my server, other player experienced the same situation aswell, I think the problem is from OnPlayerText, but I dont have any clue what is the error

PHP код:
public OnPlayerText(playeridtext[])
{
    new 
string[MAX_PLAYERS], var = GetPlayerVirtualWorld(playerid);
    
//
     
if(text[0] == '@' && Account[playerid][Admin] >= 1)
      {
           
format(stringsizeof(string), "** |Admin Chat| %s: %s **"IsPlayerName(playerid), text[1]);
        for(new 
0MAX_PLAYERSi++)
          {
            if(
IsPlayerConnected(i) && Account[i][Admin] >= 1)
              {
              
SendClientMessage(i0x0AFFC9FFstring);
              return 
0;
            }
        }
    }
    if(
text[0] == '!' && Account[playerid][Vip] >= 1)
    {
        
format(stringsizeof(string), "~> |Vip Chat| %s: %s <~"IsPlayerName(playerid), text[1]);
         for(new 
0MAX_PLAYERSi++)
           {
             if(
IsPlayerConnected(i) && Account[i][Vip] >= 1)
               {
               
SendClientMessage(i0xFF0099AAstring);
               return 
0;
            }
        }
       }
      else
    {
         
format(stringsizeof(string), "%s (%d): {FFFFFF}%s"IsPlayerName(playerid), playeridtext);
           for(new 
0MAX_PLAYERSi++)
            {
              if(
IsPlayerConnected(i))
               {
                    if(
GetPlayerVirtualWorld(i) == var)
                  {
                       
SendClientMessage(iGetPlayerColor(playerid), string);
                       return 
0;
                  }
            }
        }
       }
       return 
1;

Help please
Код:
public OnPlayerText(playerid, text[])
{
    new string[144];
    //
     if(text[0] == '@' && Account[playerid][Admin] >= 1)
      {
           format(string, sizeof(string), "** |Admin Chat| %s: %s **", IsPlayerName(playerid), text[1]);
        for(new i = 0; i < MAX_PLAYERS; i++)
          {
            if(IsPlayerConnected(i) && Account[i][Admin] >= 1)
              {
              SendClientMessage(i, 0x0AFFC9FF, string);
              return 0;
            }
        }
    }
    if(text[0] == '!' && Account[playerid][Vip] >= 1)
    {
        format(string, sizeof(string), "~> |Vip Chat| %s: %s <~", IsPlayerName(playerid), text[1]);
         for(new i = 0; i < MAX_PLAYERS; i++)
           {
             if(IsPlayerConnected(i) && Account[i][Vip] >= 1)
               {
               SendClientMessage(i, 0xFF0099AA, string);
               return 0;
            }
        }
       }

         format(string, sizeof(string), "%s (%d): {FFFFFF}%s", IsPlayerName(playerid), playerid, text);
         SendClientMessageToAll(GetPlayerColor(playerid), string);

       return 1;
}
Reply
#3

Quote:
Originally Posted by ForCop
Посмотреть сообщение
Код:
public OnPlayerText(playerid, text[])
{
    new string[144];
    //
     if(text[0] == '@' && Account[playerid][Admin] >= 1)
      {
           format(string, sizeof(string), "** |Admin Chat| %s: %s **", IsPlayerName(playerid), text[1]);
        for(new i = 0; i < MAX_PLAYERS; i++)
          {
            if(IsPlayerConnected(i) && Account[i][Admin] >= 1)
              {
              SendClientMessage(i, 0x0AFFC9FF, string);
              return 0;
            }
        }
    }
    if(text[0] == '!' && Account[playerid][Vip] >= 1)
    {
        format(string, sizeof(string), "~> |Vip Chat| %s: %s <~", IsPlayerName(playerid), text[1]);
         for(new i = 0; i < MAX_PLAYERS; i++)
           {
             if(IsPlayerConnected(i) && Account[i][Vip] >= 1)
               {
               SendClientMessage(i, 0xFF0099AA, string);
               return 0;
            }
        }
       }

         format(string, sizeof(string), "%s (%d): {FFFFFF}%s", IsPlayerName(playerid), playerid, text);
         SendClientMessageToAll(GetPlayerColor(playerid), string);

       return 1;
}
what?? can you please explain to me what is the error in my code rather than giving me a raw code that you write back from scratch, I want to learn .
Reply
#4

Quote:
Originally Posted by AfiqIqbal
Посмотреть сообщение
what?? can you please explain to me what is the error in my code rather than giving me a raw code that you write back from scratch, I want to learn .
error: in your code, messages could only see the players that are in your virtual world.
Reply
#5

new string[MAX_PLAYERS], - would likely be too big to send.
change to
new string[ 144 ], - this is the largest string you can send with SendClientMessage.


ForCop already changed that in his code but he also removed the functionality to send the message within your virtual world and left another mistake.
You return 0 every loop iteration within vip, admin and normal chats. Move the return 0; outside of the loops like this. When you return 0; it stops everything so you only want to return after you send the correct messages to everyone you need.

PHP код:
if(text[0] == '@' && Account[playerid][Admin] >= 1
      { 
           
format(stringsizeof(string), "** |Admin Chat| %s: %s **"IsPlayerName(playerid), text[1]); 
        for(new 
0MAX_PLAYERSi++) 
          { 
            if(
IsPlayerConnected(i) && Account[i][Admin] >= 1
              { 
              
SendClientMessage(i0x0AFFC9FFstring); 
            } 
        } 
        return 
0;
    } 
Reply
#6

Quote:
Originally Posted by AdamsLT
Посмотреть сообщение
new string[MAX_PLAYERS], - would likely be too big to send.
change to
new string[ 144 ], - this is the largest string you can send with SendClientMessage.


ForCop already changed that in his code but he also removed the functionality to send the message within your virtual world and left another mistake.
You return 0 every loop iteration within vip, admin and normal chats. Move the return 0; outside of the loops like this. When you return 0; it stops everything so you only want to return after you send the correct messages to everyone you need.

PHP код:
if(text[0] == '@' && Account[playerid][Admin] >= 1
      { 
           
format(stringsizeof(string), "** |Admin Chat| %s: %s **"IsPlayerName(playerid), text[1]); 
        for(new 
0MAX_PLAYERSi++) 
          { 
            if(
IsPlayerConnected(i) && Account[i][Admin] >= 1
              { 
              
SendClientMessage(i0x0AFFC9FFstring); 
            } 
        } 
        return 
0;
    } 
It's working for a while then my player says that they can't chat, but I can see their chat and my player id is 0, what I found is only id 0 can read the chat, how to fix this??
Reply
#7

PHP код:
    if(strcmp(text[0],"@",false,1) == 0)
    {
        
text[0] = 25//removes '@' from text. (replaces with space)
        
format(text,256"** |Admin Chat| %s:%s **"IsPlayerName(playerid),text); 
        for(new 
0GetPlayerPoolSize(); <= ji++)
        {
            if(
Account[i][Admin] >= && IsPlayerConnected(i))
            {
                
SendClientMessage(i0x0AFFC9FFtext);
            }
        }
        
format(text,256,""); // clears formatting of 'text' (it's importat for later callback, otherwise players texts will be messed-up)
        
return 0// to prevent default text from sending.
    

Reply
#8

PHP код:
public OnPlayerText(playeridtext[])
{
    new 
string[144];
    if(
text[0] == '@' && Account[playerid][Admin] >= 1)
    {
        
format(stringsizeof(string), "** |Admin Chat| %s: %s **"IsPlayerName(playerid), text[1]);
        for(new 
0GetPlayerPoolSize(); <= ji++)
        {
            if(
IsPlayerConnected(i) && Account[i][Admin] >= 1)
                
SendClientMessage(i0x0AFFC9FFstring);
        }
        return 
0;
    }
    if(
text[0] == '!' && Account[playerid][Vip] >= 1)
    {
        
format(stringsizeof(string), "~> |Vip Chat| %s: %s <~"IsPlayerName(playerid), text[1]);
        for(new 
0GetPlayerPoolSize(); <= ji++)
        {
            if(
IsPlayerConnected(i) && Account[i][Vip] >= 1)
                
SendClientMessage(i0xFF0099AAstring);
        }
        return 
0;
    }
    new var = 
GetPlayerVirtualWorld(playerid), pl_color GetPlayerColor(playerid);
    
format(stringsizeof(string), "%s (%d): {FFFFFF}%s"IsPlayerName(playerid), playeridtext);
    for(new 
0GetPlayerPoolSize(); <= ji++)
    {
        if(!
IsPlayerConnected(i) || GetPlayerVirtualWorld(i) != var) continue;
        
SendClientMessage(ipl_colorstring);
    }
    return 
0;

You were using 'return' within a loop, which would result in the loop being broken after the first iteration. (Meaning if the loop started at 0, the loop would only iterate through player ID 0 and then would not continue)

https://sampwiki.blast.hk/wiki/Control_Structures#return

Also, I've changed your loops to make use of the function 'GetPlayerPoolSize' which returns the highest player ID being used on your server.

https://sampwiki.blast.hk/wiki/GetPlayerPoolSize
Reply
#9

Quote:
Originally Posted by Mugala
Посмотреть сообщение
PHP код:
    if(strcmp(text[0],"@",false,1) == 0)
    {
        
text[0] = 25//removes '@' from text. (replaces with space)
        
format(text,256"** |Admin Chat| %s:%s **"IsPlayerName(playerid),text); 
        for(new 
0GetPlayerPoolSize(); <= ji++)
        {
            if(
Account[i][Admin] >= && IsPlayerConnected(i))
            {
                
SendClientMessage(i0x0AFFC9FFtext);
            }
        }
        
format(text,256,""); // clears formatting of 'text' (it's importat for later callback, otherwise players texts will be messed-up)
        
return 0// to prevent default text from sending.
    

thanks but .. players can use admin chat and vip chat . the only problem is the main chat is not working, maybe i return 0; at the wrong bracket or what?
Reply
#10

Quote:
Originally Posted by AfiqIqbal
Посмотреть сообщение
thanks but .. players can use admin chat and vip chat . the only problem is the main chat is not working, maybe i return 0; at the wrong bracket or what?
yes, you're preventing this in wrong bracket. can you show me the whole OnPlayerText?
by the way, you can prevent player with this code if(Account[playerid][Admin] < 1) return SendClientMessage(playerid,-1,"You aren't an admin.");

PHP код:
    if(strcmp(text[0],"@",false,1) == 0
    { 
        if(
Account[playerid][Admin] < 1) return SendClientMessage(playerid,-1,"You aren't an admin");// prevent normal player from typing in admin chat.
        
text[0] = 25//removes '@' from text. (replaces with space) 
        
format(text,256"** |Admin Chat| %s:%s **"IsPlayerName(playerid),text);  
        for(new 
0GetPlayerPoolSize(); <= ji++) 
        { 
            if(
Account[i][Admin] >= && IsPlayerConnected(i)) 
            { 
                
SendClientMessage(i0x0AFFC9FFtext); 
            } 
        } 
        
format(text,256,""); // clears formatting of 'text' (it's importat for later callback, otherwise players texts will be messed-up) 
        
return 0// to prevent default text from sending. 
    

Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)