Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Function to be used in replacement of SendClientMessage(ToAll)
- // Lines wont be longer than 140 characters.
- // After the line reaches 100 characters, it will seek for the next available space to split the text into another line.
- // Colors are taken into account and increases the 100th mark by 8 (color length) for every color detected up to the 140th character (5 colors per line max) (this is so a colored lines don't end up being less than 100 text characters long)
- // In case there are more than 5 colors in one line, or the mark exceedes the 140th character limit with the colors, the line will still be split as the function automatically will start lowering the 140th mark until it finds less than 140 characters in one line.
- // Last color in one line is also detected and transfered to the next line that gets split.
- // PM me (CuervO SA-MP Forums) for any error or inconsistency that you encounter while using this function.
- stock RenderMessage(top, color, const text[])
- {
- new temp[156], tosearch = 0, colorint, posscolor, lastcol[12];
- new mess[356], colors, tempc; format(mess, 356, "%s",text);
- while(strlen(mess) > 0)
- {
- if(strlen(mess) < 140)
- {
- SendClientMessage(top, color, mess);
- break;
- }
- strmid(temp, mess, 0, 140);
- while(strfind(temp, "{", true) != -1)
- {
- tempc = strfind(temp, "{", true);
- if(temp[tempc+7] == '}')
- {
- colors ++;
- strdel(temp, tempc, tempc+7);
- }
- else
- {
- temp[tempc] = '0';
- continue;
- }
- }
- temp = "";
- if(strlen(mess) <= 100+colors*8 && strlen(mess) <= 140)
- {
- SendClientMessage(top, color, mess);
- break;
- }
- tosearch = strfind(mess," ",true, 100+colors*8)+1;
- while(tosearch > 140 || tosearch <= 0)
- {
- colors --;
- tosearch = strfind(mess," ",true,100+colors*8)+1;
- }
- if(strfind(mess,"{",true) != -1) //color codes detection , YAY
- {
- posscolor = strfind(mess,"{",true);
- if(mess[posscolor+7] == '}') //detected one color
- colorint = posscolor;
- while(strfind(mess,"{",true,colorint+1) != -1) //repeat until none are found
- {
- posscolor = strfind(mess,"{",true,colorint+1);
- if(posscolor > tosearch) //if next color will be on the other line, use last color found to render on the next line
- {
- posscolor = colorint;
- break;
- }
- if(mess[posscolor+7] == '}') //if found, then assign the color
- {
- colorint = posscolor;
- }
- else
- {
- posscolor = colorint; //else, leave the last color.
- break;
- }
- }
- if(colorint == posscolor) //if the color position equals the one that was found
- strmid(lastcol,mess,colorint,colorint+8); //get the last used color string.
- }
- strmid(temp, mess, 0, tosearch);
- SendClientMessage(top, color, temp);
- strdel(mess, 0, tosearch);
- strins(mess, lastcol, 0); //insert last used color into the new line to be processed.
- temp = "";
- tosearch = 0;
- colors = 0;
- }
- return 1;
- }
- stock RenderMessageToAll(color, const text[])
- {
- new temp[156], tosearch = 0, colorint, posscolor, lastcol[12];
- new mess[356], colors, tempc; format(mess, 356, "%s",text);
- while(strlen(mess) > 0)
- {
- if(strlen(mess) < 140)
- {
- SendClientMessageToAll(color, mess);
- break;
- }
- strmid(temp, mess, 0, 140);
- while(strfind(temp, "{", true) != -1)
- {
- tempc = strfind(temp, "{", true);
- if(temp[tempc+7] == '}')
- {
- colors ++;
- strdel(temp, tempc, tempc+7);
- }
- else
- {
- temp[tempc] = '0';
- continue;
- }
- }
- temp = "";
- if(strlen(mess) <= 100+colors*8 && strlen(mess) <= 140)
- {
- SendClientMessageToAll(color, mess);
- break;
- }
- tosearch = strfind(mess," ",true,100+colors*8)+1;
- while(tosearch > 140 || tosearch <= 0)
- {
- colors --;
- tosearch = strfind(mess," ",true,100+colors*8)+1;
- }
- if(strfind(mess,"{",true) != -1) //color codes detection , YAY
- {
- posscolor = strfind(mess,"{",true);
- if(mess[posscolor+7] == '}') //detected one color
- colorint = posscolor;
- while(strfind(mess,"{",true,colorint+1) != -1) //repeat until none are found
- {
- posscolor = strfind(mess,"{",true,colorint+1);
- if(posscolor > tosearch) //if next color will be on the other line, use last color found to render on the next line
- {
- posscolor = colorint;
- break;
- }
- if(mess[posscolor+7] == '}') //if found, then assign the color
- {
- colorint = posscolor;
- }
- else
- {
- posscolor = colorint; //else, leave the last color.
- break;
- }
- }
- if(colorint == posscolor) //if the color position equals the one that was found
- strmid(lastcol,mess,colorint,colorint+8); //get the last used color string.
- }
- strmid(temp, mess, 0, tosearch);
- SendClientMessageToAll(color, temp);
- strdel(mess,0,tosearch);
- strins(mess, lastcol, 0);
- temp = "";
- tosearch = 0;
- colors = 0;
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement