SA-MP Forums Archive
Splitting message doesn't work - 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: Splitting message doesn't work (/showthread.php?tid=622556)



Splitting message doesn't work - cs_waller - 23.11.2016

The title pretty much speaks for itself, I tried what not but I can't get it working. I am mainly trying to split the messages in the common commands like /me /do /shout etcetera which Proxdetector mostly works for.
PHP код:
#define EX_SPLITLENGTH 118
stock SendSplitMessage(playeridcolor, final[])
{
    
#pragma unused playerid, color
    
new buffer[EX_SPLITLENGTH+5];
    new 
len strlen(final);
    if(
len>EX_SPLITLENGTH)
    {
        new 
times = (len/EX_SPLITLENGTH);
        for(new 
0times+1i++)
        {
            
strdel(buffer0EX_SPLITLENGTH+5);
            if(
len-(i*EX_SPLITLENGTH)>EX_SPLITLENGTH)
            {
                
strmid(buffer, final, EX_SPLITLENGTH*iEX_SPLITLENGTH*(i+1));
                
format(buffersizeof(buffer), "%s ..."buffer);
            }
            else
            {
                
strmid(buffer, final, EX_SPLITLENGTH*ilen);
            }
            
SendClientMessage(playeridcolorbuffer);
        }
    }
    else
    {
        
SendClientMessage(playeridcolor, final);
    }
}
forward ProxDetector(Float:radiplayeridmsg[],col1,col2,col3,col4,col5);
public 
ProxDetector(Float:radiplayeridmsg[],col1,col2,col3,col4,col5)
{
    if(
IsPlayerConnected(playerid))
    {
        new 
Float:posxFloat:posyFloat:posz;
        new 
Float:oldposxFloat:oldposyFloat:oldposz;
        new 
Float:tempposxFloat:tempposyFloat:tempposz;
        
GetPlayerPos(playeridoldposxoldposyoldposz);
        for(new 
0MAX_PLAYERSi++)
        {
        if(
IsPlayerConnected(i) && (GetPlayerVirtualWorld(playerid) == GetPlayerVirtualWorld(i)))
        {
        
GetPlayerPos(iposxposyposz);
        
tempposx = (oldposx -posx);
        
tempposy = (oldposy -posy);
        
tempposz = (oldposz -posz);
        if (((
tempposx radi/16) && (tempposx > -radi/16)) && ((tempposy radi/16) && (tempposy > -radi/16)) && ((tempposz radi/16) && (tempposz > -radi/16)))
        {
        
SendSplitMessage(icol1msg);
        }
        else if (((
tempposx radi/8) && (tempposx > -radi/8)) && ((tempposy radi/8) && (tempposy > -radi/8)) && ((tempposz radi/8) && (tempposz > -radi/8)))
        {
        
SendSplitMessage(icol2msg);
        }
        else if (((
tempposx radi/4) && (tempposx > -radi/4)) && ((tempposy radi/4) && (tempposy > -radi/4)) && ((tempposz radi/4) && (tempposz > -radi/4)))
        {
        
SendSplitMessage(icol3msg);
        }
        else if (((
tempposx radi/2) && (tempposx > -radi/2)) && ((tempposy radi/2) && (tempposy > -radi/2)) && ((tempposz radi/2) && (tempposz > -radi/2)))
        {
        
SendSplitMessage(icol4msg);
        }
        else if (((
tempposx radi) && (tempposx > -radi)) && ((tempposy radi) && (tempposy > -radi)) && ((tempposz radi) && (tempposz > -radi)))
        {
        
SendSplitMessage(icol5msg);
        }
        }
        else
        {
        
SendSplitMessage(icol1msg);
        }
        }
    }
    return 
1;

Anything is greatly appreciated. I get no errors, warnings or anything but when I get in game and use the commands, the characters are limited and are not getting splitted.


Re: Splitting message doesn't work - OneDay - 23.11.2016

use just strdel or strmid or format not all


Re: Splitting message doesn't work - SickAttack - 23.11.2016

https://github.com/Kevin-Reinke/Mess..._Multiple_Rows


Re: Splitting message doesn't work - cs_waller - 23.11.2016

Thanks for linking the include but I don't use zcmd(sorry if this sounded lame). I really don't understand OneDay's comment, what do you mean to use only one of the stated 3 functions? I've seen the splitting code on 2 different topics already after not getting it to work already and they are exactly the same with people stating it works. I don't know where the problem is.


Re: Splitting message doesn't work - Aliassassin123456 - 23.11.2016

Hope this helps! (Written just right now lol)
PHP код:
// By AliAssassiN
#define DEFAULT_SPLIT_MESSAGE_LEN 60
SplittedMessage(string[], extra[], sizeofstring sizeof stringsizeofextra sizeof extramaxLen DEFAULT_SPLIT_MESSAGE_LENbool:cutAtSpace true)
{
    new 
iLen strlen(string);
    if(
iLen maxLen 4)
    {
        new 
iPositionToCut maxLen-1;
        if(
cutAtSpace)
        {
             new 
AfterSpace strfind(string" "trueiPositionToCut-1);
             if(
AfterSpace != -1iPositionToCut AfterSpace;
        }
        
// Wished to have substr
        
for(new iPositionToCut+10iLeni++,l++) extra[l] = string[i];
        
strdel(stringiPositionToCutiLen);
        
strcat(string" ..."sizeofstring);
        
strins(extra"... "0sizeofextra);
        return 
true;
    }
    return 
false;

Test:
PHP код:
new test[128], test2[128];
format(testsizeof test"The quick brown fox jumps over the lazy dog Repeat The quick brown fox jumps over the lazy dog");
if(
SplittedMessage(testtest2sizeof testsizeof test2)) printf("Test string needs split!\nOutput: First Line: %s\nSecond: %s"testtest2);
else 
printf("Test string doesn't need split."); 
Output:
Код:
Test string needs split!
Output: First Line: The quick brown fox jumps over the lazy dog Repeat The quick ...
Second: ... brown fox jumps over the lazy dog
Also it doesn't support splitting to 3 lines or more.


Re: Splitting message doesn't work - cs_waller - 23.11.2016

Thank you for taking your time to help me with this but I have zero clue how to use it, sorry if that's an irritating question but is it possible to implent your code into the ProxDetector as most of my local chat commands are using it?


Re: Splitting message doesn't work - Aliassassin123456 - 23.11.2016

If you are going to use it within your ProxDetector function, follow this example:
PHP код:
new strmsgex[128];
if(
SplittedMessage(strmsgstrmsgexsizeof strmsgsizeof strmsgex))
{
    
ProxDetector(YOURRADIUSTARGETPLAYERstrmsgYOURCOL1YOURCOL2YOURCOL3YOURCOL4YOURCOL5);
    
ProxDetector(YOURRADIUSTARGETPLAYERstrmsgexYOURCOL1YOURCOL2YOURCOL3YOURCOL4YOURCOL5);
}
else 
ProxDetector(YOURRADIUSTARGETPLAYERstrmsgYOURCOL1YOURCOL2YOURCOL3YOURCOL4YOURCOL5); 
Where YOURRADIUS is the radius you want the players to see the message, TARGETPLAYER is the one who sent the message, strmsg is your string that you want it to be splitted, YOURCOL1 to COL5 is Prox Colors.
P.S. Replace those SendSplitMessage to SendPlayerMessage inside your ProxDetector function.


Re: Splitting message doesn't work - cs_waller - 24.11.2016

Tried it but still no effect.
PHP код:
    if(strcmp(cmd"/me"true) == 0)
    {
        new 
strmsg[128];
        new 
strmsgex[128];
        
GetPlayerName(playeridsendernamesizeof(sendername));
        new 
length strlen(cmdtext);
        while ((
idx length) && (cmdtext[idx] <= ' ')){idx++;}
        new 
offset idx,result[64];
        while ((
idx length) && ((idx offset) < (sizeof(result) - 1))){result[idx offset] = cmdtext[idx];idx++;}
        
result[idx offset] = EOS;
        if(!
strlen(result))return SendClientMessage(playeridred"USAGE: /me [action]");
        if(
SplittedMessage(strmsgstrmsgexsizeof strmsgsizeof strmsgex))
        {
        
ProxDetector(15.0playeridstrmsgCOLOR_EMOTECOLOR_EMOTECOLOR_EMOTECOLOR_EMOTECOLOR_EMOTE);
        
ProxDetector(15.0playeridstrmsgexCOLOR_EMOTECOLOR_EMOTECOLOR_EMOTECOLOR_EMOTECOLOR_EMOTE);
        return 
1;
        }
        else {
        
format(strmsgsizeof(strmsg), "%s %s"sendernameresult);
        
ProxDetector(15.0playeridstrmsg,COLOR_EMOTE,COLOR_EMOTE,COLOR_EMOTE,COLOR_EMOTE,COLOR_EMOTE);
        
printf("%s"rpstring);
        return 
1;
        }
    } 



Re: Splitting message doesn't work - Aliassassin123456 - 24.11.2016

Because you didn't code it right
Modify it to:
PHP код:
    if(strcmp(cmd"/me"true) == 0
    { 
        new 
strmsg[128]; 
        new 
strmsgex[128]; 
        
GetPlayerName(playeridsendernamesizeof(sendername)); 
        new 
length strlen(cmdtext); 
        while ((
idx length) && (cmdtext[idx] <= ' ')){idx++;} 
        new 
offset idx,result[64]; 
        while ((
idx length) && ((idx offset) < (sizeof(result) - 1))){result[idx offset] = cmdtext[idx];idx++;} 
        
result[idx offset] = EOS
        if(!
strlen(result))return SendClientMessage(playeridred"USAGE: /me [action]"); 
        
format(strmsgsizeof(strmsg), "%s %s"sendernameresult); 
        if(
SplittedMessage(strmsgstrmsgexsizeof strmsgsizeof strmsgex)) 
        { 
        
ProxDetector(15.0playeridstrmsgCOLOR_EMOTECOLOR_EMOTECOLOR_EMOTECOLOR_EMOTECOLOR_EMOTE); 
        
ProxDetector(15.0playeridstrmsgexCOLOR_EMOTECOLOR_EMOTECOLOR_EMOTECOLOR_EMOTECOLOR_EMOTE); 
        return 
1
        } 
        else 
        {
        
ProxDetector(15.0playeridstrmsg,COLOR_EMOTE,COLOR_EMOTE,COLOR_EMOTE,COLOR_EMOTE,COLOR_EMOTE); 
        
printf("%s"rpstring); 
        return 
1
        } 
    } 



Re: Splitting message doesn't work - cs_waller - 24.11.2016

The splitting here works but there is a new problem(or more like a bug?) The second message is not full which means that if I for example write "/me reaches into the left pocket of his jacket and takes out a deagle which safety he flicks to OFF and aims at the individuals ", the following thing is sent.
1st line - Name reaches into the left pocket of his jacket and takes ...
2nd line - ...out a deag.
Is there anything wrong with the command or it's just me screwing things up again?