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(playerid, color, 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 i = 0; i < times+1; i++)
{
strdel(buffer, 0, EX_SPLITLENGTH+5);
if(len-(i*EX_SPLITLENGTH)>EX_SPLITLENGTH)
{
strmid(buffer, final, EX_SPLITLENGTH*i, EX_SPLITLENGTH*(i+1));
format(buffer, sizeof(buffer), "%s ...", buffer);
}
else
{
strmid(buffer, final, EX_SPLITLENGTH*i, len);
}
SendClientMessage(playerid, color, buffer);
}
}
else
{
SendClientMessage(playerid, color, final);
}
}
forward ProxDetector(Float:radi, playerid, msg[],col1,col2,col3,col4,col5);
public ProxDetector(Float:radi, playerid, msg[],col1,col2,col3,col4,col5)
{
if(IsPlayerConnected(playerid))
{
new Float:posx, Float:posy, Float:posz;
new Float:oldposx, Float:oldposy, Float:oldposz;
new Float:tempposx, Float:tempposy, Float:tempposz;
GetPlayerPos(playerid, oldposx, oldposy, oldposz);
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i) && (GetPlayerVirtualWorld(playerid) == GetPlayerVirtualWorld(i)))
{
GetPlayerPos(i, posx, posy, posz);
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(i, col1, msg);
}
else if (((tempposx < radi/8) && (tempposx > -radi/8)) && ((tempposy < radi/8) && (tempposy > -radi/8)) && ((tempposz < radi/8) && (tempposz > -radi/8)))
{
SendSplitMessage(i, col2, msg);
}
else if (((tempposx < radi/4) && (tempposx > -radi/4)) && ((tempposy < radi/4) && (tempposy > -radi/4)) && ((tempposz < radi/4) && (tempposz > -radi/4)))
{
SendSplitMessage(i, col3, msg);
}
else if (((tempposx < radi/2) && (tempposx > -radi/2)) && ((tempposy < radi/2) && (tempposy > -radi/2)) && ((tempposz < radi/2) && (tempposz > -radi/2)))
{
SendSplitMessage(i, col4, msg);
}
else if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
{
SendSplitMessage(i, col5, msg);
}
}
else
{
SendSplitMessage(i, col1, msg);
}
}
}
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 string, sizeofextra = sizeof extra, maxLen = DEFAULT_SPLIT_MESSAGE_LEN, bool:cutAtSpace = true)
{
new iLen = strlen(string);
if(iLen > maxLen + 4)
{
new iPositionToCut = maxLen-1;
if(cutAtSpace)
{
new AfterSpace = strfind(string, " ", true, iPositionToCut-1);
if(AfterSpace != -1) iPositionToCut = AfterSpace;
}
// Wished to have substr
for(new i = iPositionToCut+1, l = 0; i < iLen; i++,l++) extra[l] = string[i];
strdel(string, iPositionToCut, iLen);
strcat(string, " ...", sizeofstring);
strins(extra, "... ", 0, sizeofextra);
return true;
}
return false;
}
Test:
PHP код:
new test[128], test2[128];
format(test, sizeof test, "The quick brown fox jumps over the lazy dog Repeat The quick brown fox jumps over the lazy dog");
if(SplittedMessage(test, test2, sizeof test, sizeof test2)) printf("Test string needs split!\nOutput: First Line: %s\nSecond: %s", test, test2);
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(strmsg, strmsgex, sizeof strmsg, sizeof strmsgex))
{
ProxDetector(YOURRADIUS, TARGETPLAYER, strmsg, YOURCOL1, YOURCOL2, YOURCOL3, YOURCOL4, YOURCOL5);
ProxDetector(YOURRADIUS, TARGETPLAYER, strmsgex, YOURCOL1, YOURCOL2, YOURCOL3, YOURCOL4, YOURCOL5);
}
else ProxDetector(YOURRADIUS, TARGETPLAYER, strmsg, YOURCOL1, YOURCOL2, YOURCOL3, YOURCOL4, YOURCOL5);
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(playerid, sendername, sizeof(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(playerid, red, "USAGE: /me [action]");
if(SplittedMessage(strmsg, strmsgex, sizeof strmsg, sizeof strmsgex))
{
ProxDetector(15.0, playerid, strmsg, COLOR_EMOTE, COLOR_EMOTE, COLOR_EMOTE, COLOR_EMOTE, COLOR_EMOTE);
ProxDetector(15.0, playerid, strmsgex, COLOR_EMOTE, COLOR_EMOTE, COLOR_EMOTE, COLOR_EMOTE, COLOR_EMOTE);
return 1;
}
else {
format(strmsg, sizeof(strmsg), "%s %s", sendername, result);
ProxDetector(15.0, playerid, strmsg,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(playerid, sendername, sizeof(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(playerid, red, "USAGE: /me [action]");
format(strmsg, sizeof(strmsg), "%s %s", sendername, result);
if(SplittedMessage(strmsg, strmsgex, sizeof strmsg, sizeof strmsgex))
{
ProxDetector(15.0, playerid, strmsg, COLOR_EMOTE, COLOR_EMOTE, COLOR_EMOTE, COLOR_EMOTE, COLOR_EMOTE);
ProxDetector(15.0, playerid, strmsgex, COLOR_EMOTE, COLOR_EMOTE, COLOR_EMOTE, COLOR_EMOTE, COLOR_EMOTE);
return 1;
}
else
{
ProxDetector(15.0, playerid, strmsg,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?