Advertisement
Guest User

Untitled

a guest
Feb 27th, 2015
638
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.60 KB | None | 0 0
  1. // Function to be used in replacement of SendClientMessage(ToAll)
  2. // Lines wont be longer than 140 characters.
  3. // After the line reaches 100 characters, it will seek for the next available space to split the text into another line.
  4. // 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)
  5. // 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.
  6. // Last color in one line is also detected and transfered to the next line that gets split.
  7. // PM me (CuervO SA-MP Forums) for any error or inconsistency that you encounter while using this function.
  8.  
  9.  
  10.  
  11. stock RenderMessage(top, color, const text[])
  12. {
  13. new temp[156], tosearch = 0, colorint, posscolor, lastcol[12];
  14. new mess[356], colors, tempc; format(mess, 356, "%s",text);
  15.  
  16. while(strlen(mess) > 0)
  17. {
  18. if(strlen(mess) < 140)
  19. {
  20. SendClientMessage(top, color, mess);
  21. break;
  22. }
  23.  
  24. strmid(temp, mess, 0, 140);
  25. while(strfind(temp, "{", true) != -1)
  26. {
  27. tempc = strfind(temp, "{", true);
  28. if(temp[tempc+7] == '}')
  29. {
  30. colors ++;
  31. strdel(temp, tempc, tempc+7);
  32. }
  33. else
  34. {
  35. temp[tempc] = '0';
  36. continue;
  37. }
  38. }
  39. temp = "";
  40.  
  41. if(strlen(mess) <= 100+colors*8 && strlen(mess) <= 140)
  42. {
  43. SendClientMessage(top, color, mess);
  44. break;
  45. }
  46. tosearch = strfind(mess," ",true, 100+colors*8)+1;
  47. while(tosearch > 140 || tosearch <= 0)
  48. {
  49. colors --;
  50. tosearch = strfind(mess," ",true,100+colors*8)+1;
  51. }
  52.  
  53. if(strfind(mess,"{",true) != -1) //color codes detection , YAY
  54. {
  55. posscolor = strfind(mess,"{",true);
  56.  
  57. if(mess[posscolor+7] == '}') //detected one color
  58. colorint = posscolor;
  59.  
  60. while(strfind(mess,"{",true,colorint+1) != -1) //repeat until none are found
  61. {
  62. posscolor = strfind(mess,"{",true,colorint+1);
  63. if(posscolor > tosearch) //if next color will be on the other line, use last color found to render on the next line
  64. {
  65. posscolor = colorint;
  66. break;
  67. }
  68. if(mess[posscolor+7] == '}') //if found, then assign the color
  69. {
  70. colorint = posscolor;
  71. }
  72. else
  73. {
  74. posscolor = colorint; //else, leave the last color.
  75. break;
  76. }
  77. }
  78.  
  79. if(colorint == posscolor) //if the color position equals the one that was found
  80. strmid(lastcol,mess,colorint,colorint+8); //get the last used color string.
  81. }
  82.  
  83. strmid(temp, mess, 0, tosearch);
  84. SendClientMessage(top, color, temp);
  85. strdel(mess, 0, tosearch);
  86. strins(mess, lastcol, 0); //insert last used color into the new line to be processed.
  87.  
  88. temp = "";
  89. tosearch = 0;
  90. colors = 0;
  91. }
  92. return 1;
  93. }
  94.  
  95. stock RenderMessageToAll(color, const text[])
  96. {
  97. new temp[156], tosearch = 0, colorint, posscolor, lastcol[12];
  98. new mess[356], colors, tempc; format(mess, 356, "%s",text);
  99.  
  100. while(strlen(mess) > 0)
  101. {
  102. if(strlen(mess) < 140)
  103. {
  104. SendClientMessageToAll(color, mess);
  105. break;
  106. }
  107.  
  108. strmid(temp, mess, 0, 140);
  109. while(strfind(temp, "{", true) != -1)
  110. {
  111. tempc = strfind(temp, "{", true);
  112. if(temp[tempc+7] == '}')
  113. {
  114. colors ++;
  115. strdel(temp, tempc, tempc+7);
  116. }
  117. else
  118. {
  119. temp[tempc] = '0';
  120. continue;
  121. }
  122. }
  123. temp = "";
  124.  
  125. if(strlen(mess) <= 100+colors*8 && strlen(mess) <= 140)
  126. {
  127. SendClientMessageToAll(color, mess);
  128. break;
  129. }
  130. tosearch = strfind(mess," ",true,100+colors*8)+1;
  131. while(tosearch > 140 || tosearch <= 0)
  132. {
  133. colors --;
  134. tosearch = strfind(mess," ",true,100+colors*8)+1;
  135. }
  136.  
  137. if(strfind(mess,"{",true) != -1) //color codes detection , YAY
  138. {
  139. posscolor = strfind(mess,"{",true);
  140.  
  141. if(mess[posscolor+7] == '}') //detected one color
  142. colorint = posscolor;
  143.  
  144. while(strfind(mess,"{",true,colorint+1) != -1) //repeat until none are found
  145. {
  146. posscolor = strfind(mess,"{",true,colorint+1);
  147. if(posscolor > tosearch) //if next color will be on the other line, use last color found to render on the next line
  148. {
  149. posscolor = colorint;
  150. break;
  151. }
  152. if(mess[posscolor+7] == '}') //if found, then assign the color
  153. {
  154. colorint = posscolor;
  155. }
  156. else
  157. {
  158. posscolor = colorint; //else, leave the last color.
  159. break;
  160. }
  161. }
  162.  
  163. if(colorint == posscolor) //if the color position equals the one that was found
  164. strmid(lastcol,mess,colorint,colorint+8); //get the last used color string.
  165. }
  166.  
  167. strmid(temp, mess, 0, tosearch);
  168. SendClientMessageToAll(color, temp);
  169. strdel(mess,0,tosearch);
  170. strins(mess, lastcol, 0);
  171.  
  172. temp = "";
  173. tosearch = 0;
  174. colors = 0;
  175. }
  176. return 1;
  177. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement