Advertisement
cnl_cnl_cnl

Untitled

Feb 10th, 2025
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. -- splits (text) up into (chunkSize) pieces
  2. -- will try break on spaces if possible
  3. function u.splitByChunk(text, chunkSize)
  4. local result = {}
  5.  
  6. local posText = 1
  7. local ixResult = 1
  8.  
  9. local more = true
  10. local safety = 99
  11.  
  12. text, _ = text:gsub("\n"," ")
  13.  
  14. while more or safety < 1 do
  15. safety = safety - 1
  16.  
  17. local sub = text:sub(posText, posText+chunkSize -1)
  18.  
  19. if posText + chunkSize >= text:len() then
  20. more = false
  21. result[ixResult] = sub
  22. else
  23.  
  24. local posBreak = string.find(sub, " [^ ]*$") or chunkSize
  25. sub = text:sub(posText, posText+posBreak -1)
  26. result[ixResult] = sub
  27. posText = posText + posBreak
  28. ixResult = ixResult + 1
  29.  
  30. end
  31. end
  32.  
  33. return result
  34. end
  35.  
  36. function cnl_mb_imm.setr_desc(desc)
  37. send("setr desc")
  38. local text = u.splitByChunk(desc:trim(),80)
  39. for i = 1,#text do send(text[i]:trim()) end
  40. send("@")
  41. end
  42.  
  43. function cnl_mb_imm.format(txt)
  44. txt = txt:gsub("\n"," ")
  45. txt = u.splitByChunk(txt.trim(),80)
  46. for i = 1,#txt do send(text[i]:trim()) end
  47. end
  48.  
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement