7 Funções
Autor: PeJuGe
Comentário: [spoiler=Comentário]Estas são funções que eu já postei em sua maioria e estou postando novamente mas agora melhoradas, sendo nova apenas math.factorial.
Não explicarei, apenas postarei o script. Caso tenha alguma dúvida consulte o índice no início do script, em caso de persistência da dúvida poste-a abaixo.
Script:
--[[ PeJuGe(2010) . 7 Funções
DON'T REMOVE THE CREDITS
Exclusive For www.otserv.com.br
More Info: http://forums.otserv.com.br/showthread.php?p=1037724#post1037724
+ string.toup(txt)
* Returns the first letter upped.
+ getlocation(table, m)
* Returns the location of a value in a table
+ math.textreme(table, value)
* Returns the maximum and minimum value
+ math.multiple(value, param)
* Returns true or false
+ math.tmultiple(table, param)
* Returns the multiples of param from table
+ math.approx(value)
* Returns the nearest number
+ math.factorial(value)
* Returns the factored number
]]--
function string.toup(txt)
return string.upper(txt:sub(1, 1)) .. txt:sub(2)
end
function getlocation(table, m, r)
r = r or 1
return #table >= r and table[r] ~= m and getlocation(table, m, r + 1) or table[r] == m and r
end
function math.textreme(table, value, r)
r = r or {math.huge, -math.huge, 1}
r[1], r[2], r[3] = table[r[3]] < r[1] and table[r[3]] or r[1], table[r[3]] > r[1] and table[r[3]] or r[2], r[3] + 1
return r[3] == #table + 1 and {min = r[1], max = r[2]} or math.textreme(table, value, r)
end
function math.multiple(value, param)
return value % param == 0
end
function math.tmultiple(table, param, r)
r = r or {{}, 1}
r[1][#r[1] + 1], r[2] = math.multiple(table[r[2]], param) and table[r[2]] or nil, r[2] + 1
return r[2] == #table + 1 and r[1] or math.tmultiple(table, param, r)
end
function math.approx(value)
return math.floor(value + 0.5) > math.floor(value) and math.ceil(value) or math.floor(value)
end
function math.factorial(n)
return math.floor(n) > 1 and (math.floor(n) * math.factorial (n-1)) or 1
end
Bom, obrigado por ler meu tópico. Caso tenha alguma dúvida, reclamação ou sugestão, favor postar abaixo, pois sua dúvida pode pertencer também a outra pessoa.
Atenciosamente,
PeJuGe