Guest User

SendLongMessage - Dear`

a guest
Feb 15th, 2012
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.44 KB | None | 0 0
  1.  
  2. GetLastEmbColor(string[])
  3. {
  4.     new color[10];
  5.     for(new i = strlen(string); i != -1; i--)
  6.     {
  7.         if(string[i] == '}' && string[i - 7] == '{')
  8.         {
  9.             strmid(color, string, i - 6, i);
  10.             if(IsValidEmbColor(color))
  11.                 return color;
  12.         }
  13.     }
  14.     color[0] = 0;
  15.     return color;
  16. }
  17.  
  18. IsValidEmbColor(string[])
  19. {
  20.     for(new i, j = strlen(string); i != j; i++)
  21.     {
  22.         if(!IsValidHexChar(string[i]))
  23.             return 0;
  24.     }
  25.     return 1;
  26. }
  27.  
  28. IsValidHexChar(c)
  29. {
  30.     c = tolower(c);
  31.  
  32.     static const
  33.        hex_chars[] = {
  34.         '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
  35.     };
  36.  
  37.     for(new i; i < sizeof hex_chars; i++)
  38.         if(c == hex_chars[i])
  39.             return 1;
  40.     return 0;
  41. }
  42.  
  43.  
  44. SendLongMessage(playerid, color, message[], charlimit = 80, prefix[] = "")
  45. {
  46.     new start,
  47.         len = strlen(message),
  48.         prefixlen = strlen(prefix),
  49.         realcolor[7];
  50.     format(realcolor, sizeof realcolor, "%x", color);
  51.  
  52.     new idx = -1;
  53.     while(idx++ != len)
  54.     {
  55.         if((idx - start) == (charlimit - prefixlen))
  56.         {
  57.             new send[128 + 1];
  58.  
  59.             strmid(send, message, start, idx);
  60.             format(send, sizeof send, "%s{%s}%s", prefix, realcolor, send);
  61.  
  62.             SendClientMessage(playerid, -1, send);
  63.             format(realcolor, sizeof realcolor, "%s", GetLastEmbColor(send));
  64.             start = idx;
  65.         }
  66.         else if(idx == len)
  67.         {
  68.             new send[128 + 1];
  69.  
  70.             strmid(send, message, start, idx + 1);
  71.             format(send, sizeof send, "%s{%s}%s", prefix, realcolor, send);
  72.  
  73.             SendClientMessage(playerid, -1, send);
  74.         }
  75.         else
  76.         {
  77.  
  78.             if(message[idx] == '{')
  79.             {
  80.                 if(idx + 7 < len)
  81.                 {
  82.                     if(message[idx + 7] == '}')
  83.                     {
  84.                         if((idx + 7 + prefixlen) >= (start + charlimit))
  85.                         {
  86.                             new buff[9];
  87.                             strmid(buff, message, idx + 1, idx + 7);
  88.  
  89.                             if(IsValidEmbColor(buff))
  90.                             {
  91.                                 new send[128 + 1];
  92.                                 strmid(send, message, start, idx);
  93.                                 format(send, sizeof send, "%s{%s}%s", prefix, realcolor, send);
  94.  
  95.                                 SendClientMessage(playerid, -1, send);
  96.                                 format(realcolor, sizeof realcolor, "%s", GetLastEmbColor(send));
  97.                                 start = idx;
  98.                             }
  99.                         }
  100.                     }
  101.                 }
  102.             }
  103.             else if(message[idx] == '\n')
  104.             {
  105.                 new send[128 + 1];
  106.  
  107.                 strmid(send, message, start, idx);
  108.                 format(send, sizeof send, "%s{%s}%s", prefix, realcolor, send);
  109.  
  110.                 SendClientMessage(playerid, -1, send);
  111.                 format(realcolor, sizeof realcolor, "%s", GetLastEmbColor(send));
  112.                 start = idx;
  113.             }
  114.         }
  115.     }
  116.     return 1;
  117. }
  118. SendLongMessageToAll(color, message[], charlimit = 80, prefix[] = "")
  119. {
  120.     new start,
  121.         len = strlen(message),
  122.         prefixlen = strlen(prefix),
  123.         realcolor[7];
  124.     format(realcolor, sizeof realcolor, "%x", color);
  125.  
  126.     new idx = -1;
  127.     while(idx++ != len)
  128.     {
  129.         if((idx - start) == (charlimit - prefixlen))
  130.         {
  131.             new send[128 + 1];
  132.  
  133.             strmid(send, message, start, idx);
  134.             format(send, sizeof send, "%s{%s}%s", prefix, realcolor, send);
  135.  
  136.             SendClientMessageToAll(-1, send);
  137.             format(realcolor, sizeof realcolor, "%s", GetLastEmbColor(send));
  138.             start = idx;
  139.         }
  140.         else if(idx == len)
  141.         {
  142.             new send[128 + 1];
  143.  
  144.             strmid(send, message, start, idx + 1);
  145.             format(send, sizeof send, "%s{%s}%s", prefix, realcolor, send);
  146.  
  147.             SendClientMessageToAll(-1, send);
  148.         }
  149.         else
  150.         {
  151.  
  152.             if(message[idx] == '{')
  153.             {
  154.                 if(idx + 7 < len)
  155.                 {
  156.                     if(message[idx + 7] == '}')
  157.                     {
  158.                         if((idx + 7 + prefixlen) >= (start + charlimit))
  159.                         {
  160.                             new buff[9];
  161.                             strmid(buff, message, idx + 1, idx + 7);
  162.  
  163.                             if(IsValidEmbColor(buff))
  164.                             {
  165.                                 new send[128 + 1];
  166.                                 strmid(send, message, start, idx);
  167.                                 format(send, sizeof send, "%s{%s}%s", prefix, realcolor, send);
  168.  
  169.                                 SendClientMessageToAll(-1, send);
  170.                                 format(realcolor, sizeof realcolor, "%s", GetLastEmbColor(send));
  171.                                 start = idx;
  172.                             }
  173.                         }
  174.                     }
  175.                 }
  176.             }
  177.             else if(message[idx] == '\n')
  178.             {
  179.                 new send[128 + 1];
  180.  
  181.                 strmid(send, message, start, idx);
  182.                 format(send, sizeof send, "%s{%s}%s", prefix, realcolor, send);
  183.  
  184.                 SendClientMessageToAll(-1, send);
  185.                 format(realcolor, sizeof realcolor, "%s", GetLastEmbColor(send));
  186.                 start = idx;
  187.             }
  188.         }
  189.     }
  190.     return 1;
  191. }
Advertisement
Add Comment
Please, Sign In to add comment