Ir para conteúdo
Entre para seguir isso  
Conde2

Tópico das Funções !!

Recommended Posts

Conde2    0
Conde2

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

Editado por Conde2

Compartilhar este post


Link para o post
Compartilhar em outros sites
Iseme    0
Iseme

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

Editado por Mickfern

Compartilhar este post


Link para o post
Compartilhar em outros sites
Mock    32
Mock

Otimo topico conde2 :D

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

Editado por Mickfern

Compartilhar este post


Link para o post
Compartilhar em outros sites
Dark Billie    0
Dark Billie

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é? ._."

Editado por Mickfern

Compartilhar este post


Link para o post
Compartilhar em outros sites
Iseme    0
Iseme

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

Editado por Mickfern

Compartilhar este post


Link para o post
Compartilhar em outros sites
Eventide    7
Eventide

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.. =)~

Editado por Eventide

Compartilhar este post


Link para o post
Compartilhar em outros sites
Conde2    0
Conde2

@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 =/

Editado por Conde2

Compartilhar este post


Link para o post
Compartilhar em outros sites
Iseme    0
Iseme

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

Editado por Mickfern

Compartilhar este post


Link para o post
Compartilhar em outros sites
Conde2    0
Conde2

@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

Compartilhar este post


Link para o post
Compartilhar em outros sites
Eventide    7
Eventide

@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:D

 

malandrometro.jpg

Editado por Eventide

Compartilhar este post


Link para o post
Compartilhar em outros sites
Mock    32
Mock

function string.lenN(s)
  return assert(#s,'string exptected got nil')
end

pronto...

uahhauuhau boa :D

Editado por Mickfern

Compartilhar este post


Link para o post
Compartilhar em outros sites
Conde2    0
Conde2

@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

Compartilhar este post


Link para o post
Compartilhar em outros sites
Mock    32
Mock

COISA PORRA NENHUMA!

function table.getnN(tabela)
  assert(tabela)
  return #tabela
end

owned all

Editado por Mickfern

Compartilhar este post


Link para o post
Compartilhar em outros sites
Iseme    0
Iseme

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

Editado por Mickfern
post duplo

Compartilhar este post


Link para o post
Compartilhar em outros sites
Gpwjhlkdcf    21
Gpwjhlkdcf

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

Editado por Mickfern

Compartilhar este post


Link para o post
Compartilhar em outros sites
Eventide    7
Eventide

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.. =)

Editado por Eventide

Compartilhar este post


Link para o post
Compartilhar em outros sites
Magus    2
Magus

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

:D

Editado por Mickfern

Compartilhar este post


Link para o post
Compartilhar em outros sites
Mock    32
Mock

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 :D

Editado por Mickfern

Compartilhar este post


Link para o post
Compartilhar em outros sites
Conde2    0
Conde2

@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

Editado por Conde2

Compartilhar este post


Link para o post
Compartilhar em outros sites
Eventide    7
Eventide

é, mas você usou funções para recriar a função, tem que fazer lizinho, senão não tem graça... :(

Compartilhar este post


Link para o post
Compartilhar em outros sites
Visitante
Este tópico está impedido de receber novos posts.
Entre para seguir isso  

  • Quem Está Navegando   0 membros estão online

    Nenhum usuário registrado visualizando esta página.

×