Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. function FormatLine( str, font, size )
  2.  
  3. if( not str ) then return; end
  4.  
  5. local start = 1;
  6. local c = 1;
  7.  
  8. surface.SetFont( font );
  9.  
  10. local endstr = "";
  11. local n = 0;
  12. local lastspace = 0;
  13. local lastspacemade = 0;
  14.  
  15. while( string.len( str ) > c ) do
  16.  
  17. local sub = string.sub( str, start, c );
  18.  
  19. if( string.sub( str, c, c ) == " " ) then
  20. lastspace = c;
  21. end
  22.  
  23. if( surface.GetTextSize( sub ) >= size and lastspace ~= lastspacemade ) then
  24.  
  25. local sub2;
  26.  
  27. if( lastspace == 0 ) then
  28. lastspace = c;
  29. lastspacemade = c;
  30. end
  31.  
  32. if( lastspace > 1 ) then
  33. sub2 = string.sub( str, start, lastspace - 1 );
  34. c = lastspace;
  35. else
  36. sub2 = string.sub( str, start, c );
  37. end
  38.  
  39. endstr = endstr .. sub2 .. "\n";
  40.  
  41. lastspace = c + 1;
  42. lastspacemade = lastspace;
  43.  
  44. start = c + 1;
  45. n = n + 1;
  46.  
  47. end
  48.  
  49. c = c + 1;
  50.  
  51. end
  52.  
  53. if( start < string.len( str ) ) then
  54.  
  55. endstr = endstr .. string.sub( str, start );
  56.  
  57. end
  58.  
  59. return endstr, n;
  60.  
  61. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement