SA-MP Forums Archive
Send message from string with \n - 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: Send message from string with \n (/showthread.php?tid=571017)



Send message from string with \n - Banditukas - 15.04.2015

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


Re: Send message from string with \n - ATGOggy - 15.04.2015

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


Re: Send message from string with \n - BroZeus - 15.04.2015

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


Re: Send message from string with \n - ATGOggy - 15.04.2015

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.


AW: Re: Send message from string with \n - Nero_3D - 15.04.2015

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


Re: Send message from string with \n - Banditukas - 15.04.2015

Not work.


Re: Send message from string with \n - Yashas - 15.04.2015

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)


Re: Send message from string with \n - Banditukas - 15.04.2015

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


Re: Send message from string with \n - Azula - 15.04.2015

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