Conde2 0 #1 Posted September 29, 2009 (edited) Tópico das Funções !! Bom a idéia é igual ao do Tópico do POG !! Mas neste tópico vamos reconstruir funções e postalas aqui xD A idéia não é fazer novas funções e sim reconstruir as existentes =D Para começar vou dar um exemplo: function math.minn(a, if a >= b then return b else return a end end function math.maxx(a, if a <= b then return b else return a end end Essas funções fazem o mesmo papel que a math.max e math.min. Agora quero ver se vocês conseguem =P Algumas funções legais de se recriar: string.reverse string.gsub Edited September 29, 2009 by Conde2 Share this post Link to post Share on other sites
Iseme 0 #2 Posted September 30, 2009 (edited) Algumas math functions que fiz : Math.pow: function math.powC(n, e) r = n if not e then e = 2 end e = e-1 for x=1,e do r = r*n end return r end math.abs: function math.absC(n) if n < 0 then return n*(-1) end return n end math.sqrt: function math.sqrtC(n, i) if n < 0 then return false end if not i then i = 30 end a = 0 r = n/2 while a < i do a=a+1 ant = r r = (n/r+r)/2 if ant == r then break end end return r end Legal recriar funções. :x Vou tentar umas de string agora. //Iseme Edited January 23, 2011 by Mickfern Share this post Link to post Share on other sites
Mock 32 #3 Posted September 30, 2009 (edited) Otimo topico conde2 Caso alguem poste uma coisa inutil aki q n seje relativo ao topico eu irei deletar. function printT(...) for i,b in pairs({...}) do io.write(tostring() io.write('\t') end io.write('\n') end Edited January 23, 2011 by Mickfern Share this post Link to post Share on other sites
Dark Billie 0 #4 Posted September 30, 2009 (edited) Noob invasion D: function doTransformItem(uid, newid) local pos = getThingPos(uid) local item = getThingFromPos(pos) return doRemoveItem(item.uid) and doCreateItem(newid, 1, pos) end Dava pra criar as de otserver né? ._." Edited January 23, 2011 by Mickfern Share this post Link to post Share on other sites
Iseme 0 #5 Posted September 30, 2009 (edited) function math.maxC(...) array = {...} higher = false for k, v in pairs(array) do if not higher or v > higher then higher = v end end return higher end function math.minC(...) array = {...} lower = false for k, v in pairs(array) do if not lower or v < lower then lower = v end end return lower end //Iseme Edited January 23, 2011 by Mickfern Share this post Link to post Share on other sites
Eventide 7 #6 Posted September 30, 2009 (edited) function math.pow(x, pow) return x^pow end function math.rad(x, radc) return x^-radc end --- POG bônus -- passando funções C/C++ por Lanes sem usar objetos Linda handle = lanes.gen("*", function(args) args.c_function1() args.c_function2() end ) c_args = {c_function1, c_function2} handle(c_args) quero ver quem faz tonumber ae.. =)~ Edited January 23, 2011 by Eventide Share this post Link to post Share on other sites
Conde2 0 #7 Posted September 30, 2009 (edited) @Tópico Ai vai mais uma função bem básica xD Essa é umas das mais basicas kkkkkk function math.sqrtt(x) return x^0.5 end @Dark Billie É que recriar funções de LUA é mais divertido eu acho xD Mais depois eu posto algumas de OTServer aqui !!! Tenta fazer algumas ai pra ver como é legal !! @Iseme Vejo que você se empenhou em fazer as funções xD Parabens velho você tem futuro em... !!! @Evesys Quero ver você recriar a math.random !!!! Essa ai é que é fodaaaaa... Tentei de um monte de jeito e nem deu =/ Edited September 30, 2009 by Conde2 Share this post Link to post Share on other sites
Iseme 0 #8 Posted September 30, 2009 (edited) DHUASuhdHUAS. Que futuro. Uma função que fiz em 10 linhas, tu fazem em 1. xD. Pensei só com o mais difícil. Mas essa vai :x -- Só funciona com índices numéricos function table.insertC(t,i,v) if type(t) ~= "table" then return error("index a table value") end if not v then i,v=#t+1,i end if i > #t then t[#t+1] = v end if i < #t then e = {} for x=i, #t do e[x+1] = t[x] end for k,v in pairs(e) do t[k] = v end t[i] = v end if i ==#t then t[i+1] = t[i] t[i] = v end return i end //Iseme Edited January 23, 2011 by Mickfern Share this post Link to post Share on other sites
Conde2 0 #9 Posted October 1, 2009 @Tópico Essa aqui é uma função de OTServer bem tosca mais ta valendo fiz em 1min !! Mais tenho certeza que deve funcionar xD function isPlayer(cid) if (not isCreature(cid) and not isMonster(cid) and not isNpc(cid)) then return TRUE else return FALSE end end @Iseme Boa cara xD Eu tinha tentado fazer essa ai mais tinha que pensa muito e deixei pra lá... kkkkkkkkkk Share this post Link to post Share on other sites
Eventide 7 #10 Posted October 1, 2009 (edited) @conde2 Números pseudo-randomicos são feitos por algoritimos chatos pra xuxu, então o máximo q eu posso fazer as 9 e meia da noite pingando de sono é isso: rep_rand = math.random function math.random(...) rep_rand(...); print("Função feita por Eventide") end :D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D Edited January 23, 2011 by Eventide Share this post Link to post Share on other sites
Mock 32 #11 Posted October 1, 2009 (edited) function string.lenN(s) return assert(#s,'string exptected got nil') end pronto... http://1.bp.blogspot.com/_kRRxGcGWTes/SL6pENKoidI/AAAAAAAAAlk/LcwT1pLXJEg/s400/malandrometro.jpg uahhauuhau boa Edited January 23, 2011 by Mickfern Share this post Link to post Share on other sites
Conde2 0 #12 Posted October 1, 2009 @Evesys !!!! HASUDHAUSDHASUDHAUSDHUASHUADSHUASHDUAHDU Evesys assim não vale isso seria igual a função math.random verdadeira kkkk Mais você foi um gênio mano parabens nem pensei em usa ela HAHAHAHA O tópico ta bombando em xD @Tópico function string.reversee(str) local tab = {} local str = "" for a = 1, #str do table.insert(tab, string.sub(str, i, i)) str = str .. tab[i] return str end end Share this post Link to post Share on other sites
Mock 32 #13 Posted October 1, 2009 (edited) COISA PORRA NENHUMA! function table.getnN(tabela) assert(tabela) return #tabela end owned all Edited January 23, 2011 by Mickfern Share this post Link to post Share on other sites
Iseme 0 #14 Posted October 1, 2009 (edited) function math.floorC(n) return n - n % 1 end KK, me divirto. //Iseme Um string.reverse enfim perfeito :] (Eu acho kk) function string.reverseC(s) local t = {} local r = "" if type(s) ~= "string" then return false end for a = 1, #s do r = r..string.sub(s, -a, -a) end return r end function math.expC(x) -- Me empolguei denovo d = 100000000 return ((1+(1/d))^d)^x end function math.radC(n) return n*math.pi/180 end function math.degC(n) return n*(360/(math.pi*2)) end //Iseme Edited January 23, 2011 by Mickfern post duplo Share this post Link to post Share on other sites
Gpwjhlkdcf 21 #15 Posted October 1, 2009 (edited) Aqui vai o string.reverse mais curto: string.reverse: function string.reverse(s) for pos = 1, #s do rev = s:sub(pos, pos)..(rev or "") end return rev end string.upper: function string.upper(s) local ret for pos = 1, #s do local letter = s:sub(pos, pos) if letter:byte() >= 97 and letter:byte() <= 122 then ret = (ret or "")..string.char(letter:byte()-32) else ret = (ret or "")..letter end end return ret end string.lower: function string.lower(s) local ret for pos = 1, #s do local letter = s:sub(pos, pos) if letter:byte() >= 65 and letter:byte() <= 90 then ret = (ret or "")..string.char(letter:byte()+32) else ret = (ret or "")..letter end end return ret end Enjoy Bejo da raposinha Edited January 23, 2011 by Mickfern Share this post Link to post Share on other sites
Eventide 7 #16 Posted October 1, 2009 (edited) function string.gsub (src, search, rep) local search_size = #search if (search_size < 1) then return src.. rep end local it = 0 local spider = "" while (true) do if (it > #src) then break end for __it = it, search_size do spider = spider.. src[__it] end if (spider == search) then for __it = it, search_size do src[__it] = spider[__it] end end it = it + search_size end if (spider) then return spider end return false end nem testei.. =) Edited January 23, 2011 by Eventide Share this post Link to post Share on other sites
Magus 2 #17 Posted October 1, 2009 (edited) string.char string.char = function (...) return string.format(string.rep('%c', #arg), unpack(arg)) end string.len string.len = function (s) return #s end math.fmod math.fmod = function (x,y) return x % y end Edited January 23, 2011 by Mickfern Share this post Link to post Share on other sites
Mock 32 #18 Posted October 1, 2009 (edited) function dofile(file) local filea = assert(io.open(file,'r'),'cannot open '..file..': No such file or directory') local str = filea:read(-1) filea:close() local func = assert(loadstring(str)) assert(pcall(func)) end testay e funconay Edited January 23, 2011 by Mickfern Share this post Link to post Share on other sites
Conde2 0 #19 Posted October 1, 2009 (edited) @Evesys Que string.gsub ruim em mano kkkkkkk A minha ta bem mais foda xD E testei e funcionou eu ia manda pra SCOTW que tinha que recriar funções xD só que não deu tempo =/ Esse é o mais curto impossivel ser mais curto apenas se você usar a syntax sugar =D function string.gsubb(str, rem, repl) local var = "" local find = string.find(str, rem) var = string.sub(str, 1, find-1).. repl .. string.sub(str, find+#rem, #str) return (var) end O que você fez em mais de 10 linhas eu fiz em menos de 7 =D Edited October 1, 2009 by Conde2 Share this post Link to post Share on other sites
Eventide 7 #20 Posted October 1, 2009 é, mas você usou funções para recriar a função, tem que fazer lizinho, senão não tem graça... Share this post Link to post Share on other sites