Neverday 0 #1 Posted December 8, 2009 (edited) Olaá Galera OTNet ! Estou aqui para mostrar como fazer um npc... muito simples. Mão na Massa ! Primeiro vá em data/npc e copie qualquer arquivo, cole e renomeie com o nome do seu npc... o meu se chamará Joao... ai eu renomeio como Joao >.< Abra o arquivo e exclua todo o conteudo e cole isso : <?xml version="1.0"?> <npc name="Joao" script="data/npc/scripts/joao.lua" access="3" lookdir="2" autowalk="25"> <mana now="800" max="800"/> <health now="200" max="200"/> <look type="128" head="57" body="32" legs="49" feet="114"/> </npc> Explicação: O Verde será o nome do seu NPC. O Vermelho Será a localização do seu NPC. Por Ultimo e menos importante, o Outfit do NPC. Nosso NPC já esta criado agora é so colocar os scripts ! vamos lá ?! Vá em Data/Npc/Scripts, copiei qualquer arquivo, cole e renomeie Joao (joao é um exemplo como ja disse anteriormente) abra, apague tudo e cole isso: -- Walking -- max_x = 1 -- change the max x here. Means the NPC wont walk more to east or west as the number which is set here. max_y = 1 --change the max y here. Means the NPC wont walk more to north or south as the number which is set here. current_x = 0 --do nothing change here current_y = 0 --do nothing change here max_x = max_x - 1 --do nothing change here max_y = max_y - 1 --do nothing change here -- End Walking-- local focus = 0 local talk_start = 0 local target = 0 local following = false local attacking = false function onThingMove(creature, thing, oldpos, oldstackpos) end function onCreatureAppear(creature) end function onCreatureDisappear(cid, pos) if focus == cid then selfSay('Good bye then.') focus = 0 talk_start = 0 end end function onCreatureTurn(creature) end function msgcontains(txt, str) return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)')) end function onCreatureSay(cid, type, msg) msg = string.lower(msg) if (msgcontains(msg, 'hi') and (focus == 0)) and getDistanceToCreature(cid) < 4 then selfSay('Hello ' .. creatureGetName(cid) .. '! I'm selling the VIP Set. My offers are: Divine Armor (14kk), Divine Legs (13kk), Divine Helmet (13kk), Eagle Shield (15kk), Supreme Boots (12kk), Divine Axe (5kk), Divine Sword (5kk), Divine Star (5kk) and Divine Club (5kk).') focus = cid talk_start = os.clock() elseif msgcontains(msg, 'hi') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then selfSay('Sorry, ' .. creatureGetName(cid) .. '! I talk to you in a minute.') elseif focus == cid then talk_start = os.clock() [red]if msgcontains(msg, 'supreme boots') then buy(cid,5462,getCount(msg),12000000) elseif msgcontains(msg, 'divine armor') then buy(cid,2503,getCount(msg),14000000) elseif msgcontains(msg, 'divine legs') then buy(cid,2504,getCount(msg),13000000) elseif msgcontains(msg, 'divine helmet') then buy(cid,2342,getCount(msg),13000000) elseif msgcontains(msg, 'eagle shield') then buy(cid,2538,getCount(msg),15000000) elseif msgcontains(msg, 'divine axe') then buy(cid,2538,getCount(msg),5000000) elseif msgcontains(msg, 'Divine Star') then buy(cid,2538,getCount(msg),5000000) elseif msgcontains(msg, 'divine club') then buy(cid,2538,getCount(msg),5000000) elseif msgcontains(msg, 'divine star') then buy(cid,2538,getCount(msg),5000000) elseif msgcontains(msg, 'bye') and focus == cid and getDistanceToCreature(cid) < 4 then selfSay('Good bye, ' .. creatureGetName(cid) .. '!') focus = 0 talk_start = 0 end end end function onCreatureChangeOutfit(creature) end function onThink() -- Walking -- if focus == 0 and max_x >= 0 and max_y >= 0 then cx, cy, cz = selfGetPosition() randmove = math.random(1,20) if randmove == 4 and current_x <= max_x then nx = cx + 1 current_x = current_x + 1 elseif randmove == 8 and current_x >= (max_x - (max_x * 2)) then nx = cx - 1 current_x = current_x - 1 elseif randmove == 12 and current_y <= max_y then ny = cy + 1 current_y = current_y + 1 elseif randmove == 16 and current_y >= (max_y - (max_y * 2)) then ny = cy - 1 current_y = current_y - 1 elseif randmove <= 20 then nx = cx ny = cy end moveToPosition(nx, ny, cz) end -- End Walking -- if (os.clock() - talk_start) > 30 then if focus > 0 then selfSay('Next Please...') end focus = 0 end if focus ~= 0 then if getDistanceToCreature(focus) > 5 then selfSay('Good bye then.') focus = 0 end end end Explicando: é oq o npc vai falar apos voce falar hi para ele o id dos itens (voce pode colocar dinheiro ao inves dos ID's e colocar os ID's no lugar do dinheiro pro npc poder comprar :fist:) o preço dos itens espero ter ajudado amigos ! Comentem plis ! Edited December 13, 2009 by Skyen Hasus Share this post Link to post
Gpwjhlkdcf 21 #2 Posted December 13, 2009 (edited) OBS: Adicionei os códigos entre QUOTE e CODE. Quero ressaltar que não há um padrão para criar um NPC. O seu código contém vários pontos inúteis, totalmente desnecessários. Enfim, este é um esqueleto pronto não muito recomendado para usar, mas para quem ainda está aprendendo pode ter utilidade. Movido. Edited December 13, 2009 by Skyen Hasus Share this post Link to post
kilergui 0 #3 Posted December 13, 2009 bom mas axo que qualquer um que tenha noçao de xml conseguiria editar sem um tuto Share this post Link to post
Welkin Guide 0 #4 Posted December 18, 2009 Está meio simples. Acho que poderia fazer algo mais complexo para os iniciantes já aprenderem e não ter que fazer tudo de novo. Share this post Link to post
Dank 0 #6 Posted December 26, 2009 Achei interessante, pois não entendo nada de script .. e estou tentando aprender '-' o "esqueleto" como o Skyen disse me ajudou bastente, pois aí dá para começar a ter uma noção de formatação e talz ! vlw, bom trabalho Share this post Link to post
Marley_ 0 #7 Posted January 1, 2010 nao curti vc so ensinou como fazer npc de compra/venda, isso eu ja sabia mas msm assim vai ajudar alguns Share this post Link to post
Wanderman 0 #8 Posted January 22, 2010 uma dúvida: caso eu fizesse um npc que "vende" um outfit especial (outfit de uma criatura) em troca de um item e gold, o que eu teria que fazer pra que eu possa vender esse outfit e deixar disponivel pra aquela account? vender itens eh facil, pois cada um possui um ID e tudo mais... mas com outfit nao sei como funciona... obs: jah fucei nos tutoriais a respeito disso, procurei na pasta do OT algum npc que tivesse função similar, mas nao achei nada... se tiverem links de tutoriais sobre isso, eu agradeço.... Share this post Link to post
lucasayrton 0 #9 Posted January 30, 2010 axo q editar npc n eh dificil, eu mesmo consigo editar os npc q vendem, compram mudar o preço e talz axo q isso todos podem fazer ^^ Share this post Link to post
eduwx2 0 #10 Posted February 5, 2010 sei nao ta meio estranho algumas lines mais vlw pelo post algumas pessoas nem sabe abrir ot o0 vlw Share this post Link to post