Posts: 723
Threads: 366
Joined: Jun 2016
Hi,
Who can give good message splitter? like if you write a lot of text, in commands, /say and something, need to send message in new line
Posts: 1,266
Threads: 6
Joined: Oct 2014
29.11.2016, 11:36
(
Последний раз редактировалось jlalt; 04.12.2016 в 03:40.
)
You can simple do one by using sscanf like below.
PHP код:
SendMessageZ(const playerid, const color, message[])
{
new len = strlen(message);
if(len > 128)
{
new message1[150], color2;
GetMessageColor(message, color2, len);
sscanf(message,"s[128]",message1);
SendClientMessage(playerid, color, message1);
sscanf(message[127],"s[128]",message1);
if(color2 != -999999)
{
format(message1, sizeof message1,"{%d}%s",color2,message1);
return SendClientMessage(playerid, color, message1);
}
else
{
return SendClientMessage(playerid, color, message1);
}
}
else
{
return SendClientMessage(playerid, color, message);
}
}
GetMessageColor(const message[], &color2, len)
{
new strcolor[9];
for(new i = (len-1); i > -1; i--)
{
if(i > 6 && message[i] == '}' && message[i-7] == '{')
{
strmid(strcolor, message, i-6, i);
color2 = strval(strcolor);
break;
}
}
return 1;
}
Posts: 723
Threads: 366
Joined: Jun 2016
When can by?
if(color2 != -999999)
{
Posts: 1,266
Threads: 6
Joined: Oct 2014
Quote:
Originally Posted by MerryDeer
When can by?
if(color2 != -999999)
{
|
when there's a custom color used in the message words.
you can learn more about it here
https://sampwiki.blast.hk/wiki/Colors_L...olor_embedding
and here
https://sampforum.blast.hk/showthread.php?tid=250389
Posts: 723
Threads: 366
Joined: Jun 2016
What is bad with this function:
Код:
stock SMessage(playerid,color,str[],len=128,lines=20){
if(!len||!str[0])return true;
new c=0,x=0;if(len>128||len<0)len=128;
for(new i=0,j,y=0;i<lines;y=0,i++){
for(j=x+_:!i;j<x+len&&str[j];j++){
if(str[j]<33){if(str[j-1]>32)y=j;}
}if(!str[j])j=-1;else{
if(!y){
if(str[j]>32||str[j-1]<33)c=str[j];else c=0;y=j;
}else c=0;str[y]=0;
}if(playerid<0)SendClientMessageToAll(color,str[x]);
else SendClientMessage(playerid,color,str[x]);
if(j<0)break;str[y]=c;x=y+(c?0:1);
}return true;
}