Send message from string with \n
#1

Hi,

I have a random string but i want to send player messages until \n for ex:

Код:
blablablablabla\nUjUjUjUjUjUj\nZuzuzuzuzu\nPapapapapa\nBobobobobobos
Player could get messages"

blablablablabla
UjUjUjUjUjUj
Zuzuzuzuzu
Papapapapa
Bobobobobobos
Reply
#2

Im coding it, just wait. I'll update this post.
Reply
#3

Sending messages through different SendClientMessage's is the only solution of it, you can not use \n in it.
Reply
#4

PHP код:
public OnPlayerText(playeridtext[])
{
    new 
count=0lastpos=0;
    while(
strfind(text"\n"truelastpos)!=-1)
    {
         
lastpos=strfind(text"\n"truelastpos);
         
count++;
    }
    if(
count>0)
    {
         new 
messages[16][256];
         
lastpos=0;
         
count=0;
         while(
strfind(text"\n"truelastpos)!=-1)
         {
              
format(messages[count], sizeof(messages[]), "%s"text[lastpos]);
              
lastpos=strfind(text"\n"truelastpos);
              
strdel(messages[count], lastpossizeof(messages[]));
              
count++;
         }
         for(new 
i=0i<sizeof (messages[]); i++)
         {
              new 
string[256], playername[MAX_PLAYER_NAME];
              
GetPlayerName(playeridplayernamesizeof(playername));
              
format(stringsizeof(string), "%s[%d]: %s"playernameplayeridmessages[i]);
              
SendClientMessageToAll(GetPlayerColor(playerid), string);
              return 
0;
         }
    }
    return 
1;

I didn't test it yet.
Reply
#5

Quote:
Originally Posted by ATGOggy
Посмотреть сообщение
PHP код:
// CODE 
I didn't test it yet.
Way to complicated
pawn Код:
public OnPlayerText(playerid, text[]) {
    new
        idx
    ;
    if((idx = strfind(text, \"\n", true)) != -1) {
        new
            start = 0
        ;
        do {
            text[idx + start] = EOS;

            SendPlayerMessageToAll(playerid, text[start]);

            start += idx + 2;
        } while((idx = strfind(text[start], \"\n", true)) != -1);

        SendPlayerMessageToAll(playerid, text[start]);
        return false;
    }
    return true;
}
You could also use the "split" function or sscanf with p<\n> (if that works) although this /\ is probably the fastest version
Reply
#6

Not work.
Reply
#7

Why complication?

Код:
stock SendMessage(playerid,color,msg[])
{
    new idx1,idx2,str[128];
    while(++idx1)
   {
        if(msg[idx1] == '\n') 
       { 
               strmid(string,msg,idx2,idx1);
              SendClientMessage(playerid,color,str);
              idx2 = idx1;
       }
   }
}
#Nero_3D your code won't compile
SendClientMessageToAll doesn't accept playerid argument(its actually color)
Reply
#8

Is message lenght is 5000-6000 symbols it works too?
Reply
#9

PHP код:
#define SendMessage(%0,%1,%2,%3,%4)\
SendClientMessage(playerid,%4,%0); \
SendClientMessage(playerid,%4,%1); \
SendClientMessage(playerid,%4,%2); \
SendClientMessage(playerid,%4,%3); 
PHP код:
SendMessage("text1","text2","text3","text4",color
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)