Hm bem inovador demonbholder irei usar gostei da sua ideia creio qe outras pessoas irão usar tambem Rep+
- Fórum
- OTServ
- Recursos
- Scripting
- Mods, funções e outros
- Doorderstring(Tab)
2
1.4k
info
Grupo: Colaborador
Registrado: 27/12/10
Posts: 271
Reputação: +87
Gênero: Masculino

16 de maio de 2011 às 23:05
Editado Maio 16 por Pinpao

info
Grupo: Infante
Registrado: 13/10/08
Posts: 1.6k
Reputação: +420
Char no Tibia: Demonbholder
Faaala galera! Tudo tranquilo? Estreando a seção de bibliotecas, vamos a uma função que eu criei hoje a tarde.
Como funciona: O parâmetro da função deve obrigatoriamente ser uma tabela, uma array. Exemplo: doOrderString({'demon', 'casa', 'xtibia'})
A função vai ordenar essas strings, e retorna uma tabela assim: {'casa', 'demon', 'xtibia'}.
Função
function doOrderString(tab) local t = {} local a = {} local k = {} local b = {} if type(tab) ~= "table" then return error("Param should be a table") end for x, y in pairs(tab) do if type(y) == "string" then table.insert(t, string.lower(y)) end end if #t == 0 then return error("No strings in table") end for i = 1, #t do str = nil for c, d in pairs(t) do stats = FALSE for s = 1, #d do if str == nil or string.byte(str, s, s) ~= nil then if str == nil or (string.byte(d, s, s) < string.byte(str, s, s) and stats == FALSE) then str = d end if string.byte(d, s, s) ~= string.byte(str, s, s) then stats = TRUE end if s == #d and #str > #d then str = d end end end end table.insert(a, str) table.remove(t, table.find(t, str)) end for p, w in pairs(tab) do if type(w) == "string" then for e = 1, #w do table.insert(b, w) table.insert(b, table.find(a, string.lower(w))) end end end for d = 1, #a do table.insert(k, b[table.find(b, d) -1]) end return k endCaso, você não possua a função table.find, eu a criei, ai esta ela:
table.find
É isso, deve ter alguns erros na função e foi bem difícil criá-la. Até mais.
Editado Maio 14 por Demonbholder