function text_format(str) if string.len(str) > 30 then str = str .. "/n" end return str end
function text_format(str, sep) if string.len(str) > 30 then str = str .. "" .. sep .. "" end return str end
Ela tá bem simples precisa melhorar, mas funciona k.
Na segunda em sep você escolhe oque quer adicionar no final.
Entendi mals e a cada 30 caracteres vou editar aqui.











info
Grupo: Príncipe
Registrado: 19/08/10
Posts: 4k
Reputação: +1.1k
Gênero: Masculino
Ola galera, cabei de fazer essa funçao aki...
function textFormat(txt, sep) local t1 = string.explode(txt, sep) local final = {} local count = 0 if not sep or sep == "" then for w in string.gmatch(txt, "[%a!%d@#$%&*)(_-+=%[%]~><.,:;\/?}{^]" ) do if count+1 > 30 then w = "\n"..w count = 0 end table.insert(final, w) count = count+1 end elseif sep == "\n" then for i = 1, #t1 do local t2 = string.explode(t1[i], " ") for _, w in ipairs(t2) do if (#w+1)+count > 31 then w = "\n"..w count = 0 end table.insert(final, w.." ") count = count+#w end table.insert(final, "\n") count = 0 end elseif sep == " " then for _, w in ipairs(t1) do if (#w+1) + count > 30 then w = "\n"..w count = 0 end table.insert(final, w..sep) count = #w+count end end return table.concat(final) endoq ela faz: ela deve limitar o tamanho de uma string ah no maximo 30~31 letras, caso passe disso ela acresenta um '\n' pra fazer o resto da string ir pra proxima linha... eu tive q fazer essa funçao pois no OTClient a janela da funaço doShowTextDialog(...) nao faz essa limitaçao e entao n da pra ver o resto da string caso ela passe dessas 30~31 letras...
queria saber se alguem consegue diminuir essa funçao de algum jeito... pois achu q ela pode ta um pouco grande d+ e bem 'pesada'... e tb pra fins de aprendizado...
aki um exemplo de test:
local txt1 = "OLAPORRAFERROSEILAOQUETOFAZENDOAKI?COISADODEMOO.OHAHA"
local txt2 = "OLA PORRA FERRO SEILA OQUE TO FAZENDO AKI? COISA DO\nDEMO
HAHA !!234 $$&&"
local txt3 = "OLA PORRA FERRO SEILA 123 OQUE TO FAZENDO AKI? COISA DO DEMO
HAHA !!234 $$&&"
doShowTextDialog(cid, 12222, textFormat(txt2, "\n"))
Editado Janeiro 13 por Slicer