Hm bem inovador demonbholder irei usar gostei da sua ideia creio qe outras pessoas irão usar tambem Rep+
- Forums
- OTServ
- Recursos
- Scripting
- Mods, funções e outros
- Doorderstring(Tab)
2
1.4k
info
Group: Colaborador
Joined: 27/12/10
Posts: 271
Reputation: +87
Gender: Masculino

16 de maio de 2011 às 23:05
Edited Maio 16 by Pinpao

info
Group: Infante
Joined: 13/10/08
Posts: 1.6k
Reputation: +420
Tibia Character: 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.
Edited Maio 14 by Demonbholder