renanzinhoou 1 Postado Julho 25, 2007 Share Postado Julho 25, 2007 Fazendo NPCS -Mudando Falas -Vender Runas -Vender Items -Comprar Items -**NPC DE BARCO** Nós vamos começar este Tutorial com um Script basico de NPC. Na maioria dos servers há um npc chamado Mad.Eu vou mostrar agora seu script e os vários jeitos de modifica-lo. Se você for até : data/npc/scripts/loot.lua vc terá isso : 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 ((string.find(msg, '(%a*)hi(%a*)')) and (focus == 0)) and getDistanceToCreature(cid) < 4 then selfSay('Hello ' .. creatureGetName(cid) .. '! I buy swords, clubs, axes, helmets, boots, legs, shields and armors.') focus = cid talk_start = os.clock() elseif string.find(msg, '(%a*)hi(%a*)') 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() if msgcontains(msg, 'royal helmet') then sell(cid,3330,1,20000) elseif msgcontains(msg, 'warrior helmet') then sell(cid,3307,1,3000) elseif msgcontains(msg, 'crusader helmet') then sell(cid,3329,1,3000) elseif msgcontains(msg, 'crown helmet') then sell(cid,3323,1,2000) elseif msgcontains(msg, 'devil helmet') then sell(cid,3294,1,2000) elseif msgcontains(msg, 'mystic turban') then sell(cid,3512,1,500) elseif msgcontains(msg, 'chain helmet') then sell(cid,3290,1,35) elseif msgcontains(msg, 'iron helmet') then sell(cid,3291,1,30) elseif msgcontains(msg, 'helmets') then selfSay('I buy royal (20k), warrior (3k), crusader (3k), crown (2k), devil (2k), chain (35gp) and iron helmets (30gp), also mystic turbans (500gp).') elseif msgcontains(msg, 'steel boots') and focus == cid then sell(cid,3492,1,20000) elseif msgcontains(msg, 'boh') or msgcontains(msg, 'boots of haste') and focus == cid then sell(cid,3017,1,4000) elseif msgcontains(msg, 'boots') then selfSay('I buy steel boots (20k) and boots of haste (4k).') elseif msgcontains(msg, 'magic plate armor') or msgcontains(msg, 'mpa') then sell(cid,3304,1,100000) elseif msgcontains(msg, 'dragon scale mail') or msgcontains(msg, 'dsm') then sell(cid,3324,1,30000) elseif msgcontains(msg, 'golden armor') then sell(cid,3298,1,10000) elseif msgcontains(msg, 'crown armor') then sell(cid,3319,1,5000) elseif msgcontains(msg, 'knight armor') then sell(cid,3308,1,3000) elseif msgcontains(msg, 'blue robe') then sell(cid,3505,1,3000) elseif msgcontains(msg, 'lady armor') then sell(cid,3332,1,1000) elseif msgcontains(msg, 'plate armor') then sell(cid,3295,1,300) elseif msgcontains(msg, 'brass armor') then sell(cid,3297,1,200) elseif msgcontains(msg, 'chain armor') then sell(cid,3296,1,100) elseif msgcontains(msg, 'armors') then selfSay('I buy golden (10k), crown (5k), knight (3k), lady (1k), plate (300gp), brass (200gp) and chain armors (100gp), also mpa (100k), dsm (30k) and blue robes (3k).') elseif msgcontains(msg, 'golden legs') then sell(cid,3302,1,80000) elseif msgcontains(msg, 'crown legs') then sell(cid,3320,1,5000) elseif msgcontains(msg, 'knight legs') then sell(cid,3309,1,3000) elseif msgcontains(msg, 'plate legs') then sell(cid,3495,1,500) elseif msgcontains(msg, 'brass legs') then sell(cid,3310,1,100) elseif msgcontains(msg, 'chain legs') then sell(cid,3310,1,50) elseif msgcontains(msg, 'legs') then selfSay('I buy golden (80k), crown (5k), knight (3k), plate (500gp), brass (100gp) and chain legs (50gp).') elseif msgcontains(msg, 'shield of the mastermind') or msgcontains(msg, 'mms') then sell(cid,3352,1,80000) elseif msgcontains(msg, 'demon shield') then sell(cid,3358,1,40000) elseif msgcontains(msg, 'vampire shield') then sell(cid,3372,1,4000) elseif msgcontains(msg, 'medusa shield') then sell(cid,3374,1,3500) elseif msgcontains(msg, 'amazon shield') then sell(cid,3375,1,3000) elseif msgcontains(msg, 'crown shield') then sell(cid,3357,1,2000) elseif msgcontains(msg, 'tower shield') then sell(cid,3366,1,2000) elseif msgcontains(msg, 'dragon shield') then sell(cid,3354,1,1500) elseif msgcontains(msg, 'guardian shield') then sell(cid,3353,1,1200) elseif msgcontains(msg, 'beholder shield') then sell(cid,3356,1,1000) elseif msgcontains(msg, 'dwarven shield') then sell(cid,3363,1,100) elseif msgcontains(msg, 'shields') then selfSay('I buy demon (40k), vampire (4k), medusa (3.5k), amazon (3k), crown (2k), tower (2k), dragon (1.5k), guardian (1.2k), beholder (1k), and dwarven shields (100gp), also mms (80k)') elseif msgcontains(msg, 'giant sword') then sell(cid,3219,1,10000) elseif msgcontains(msg, 'bright sword') then sell(cid,3233,1,6000) elseif msgcontains(msg, 'ice rapier') then sell(cid,3222,1,4000) elseif msgcontains(msg, 'fire sword') then sell(cid,3218,1,3000) elseif msgcontains(msg, 'serpent sword') then sell(cid,3235,1,1500) elseif msgcontains(msg, 'spike sword') then sell(cid,3209,1,800) elseif msgcontains(msg, 'two handed sword') then sell(cid,3203,1,400) elseif msgcontains(msg, 'sabre') then sell(cid,3211,1,25) elseif msgcontains(msg, 'sword') then sell(cid,3202,1,25) elseif msgcontains(msg, 'swords') then selfSay('I buy giant (10k), bright (6k), fire (3k) serpent (1.5k), spike (800gp) and two handed swords (400gp), also ice rapiers (4k), sabres (25gp) and swords (25gp).') elseif msgcontains(msg, 'dragon lance') then sell(cid,3240,1,10000) elseif msgcontains(msg, 'fire axe') then sell(cid,3258,1,10000) elseif msgcontains(msg, 'knight axe') then sell(cid,3256,1,2000) elseif msgcontains(msg, 'double axe') then sell(cid,3213,1,200) elseif msgcontains(msg, 'halberd') then sell(cid,3207,1,200) elseif msgcontains(msg, 'battle axe') then sell(cid,3204,1,100) elseif msgcontains(msg, 'hatchet') then sell(cid,3214,1,20) elseif msgcontains(msg, 'axes') then selfSay('I buy fire (10k), knight (2k), double (200gp) and battle axes (100gp), also dragon lances (10k), halberds (200gp) and hatchets (20gp).') elseif msgcontains(msg, 'war hammer') then sell(cid,3217,1,4000) elseif msgcontains(msg, 'skull staff') then sell(cid,3262,1,4000) elseif msgcontains(msg, 'dragon hammer') then sell(cid,3260,1,2000) elseif msgcontains(msg, 'clerical mace') then sell(cid,3249,1,200) elseif msgcontains(msg, 'battle hammer') then sell(cid,3243,1,60) elseif msgcontains(msg, 'mace') then sell(cid,3224,1,30) elseif msgcontains(msg, 'clubs') then selfSay('I buy war (4k), dragon (2k) and battle hammers (60gp), also skull staffs (4k) and clerical maces (200gp).') elseif msgcontains(msg, 'platinum amulet') then sell(cid,2993,1,2000) elseif msgcontains(msg, 'scarf') then sell(cid,3510,1,500) elseif msgcontains(msg, 'amulets') then selfSay('I buy platinum amulets (2k) and scarfs (500gp).') elseif string.find(msg, '(%a*)bye(%a*)') and getDistanceToCreature(cid) < 4 then selfSay('Good bye, ' .. creatureGetName(cid) .. '!') focus = 0 talk_start = 0 end end end function onCreatureChangeOutfit(creature) end function onThink() 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 endFirst of we will start with MUDANDO AS FALAS if ((string.find(msg, '(%a*)hi(%a*)')) and (focus == 0)) and getDistanceToCreature(cid) < 4 then selfSay('Hello ' .. creatureGetName(cid) .. Onde fala "hi" é oq o player terá q falar para o NPC responder.Eu sugiro nao mudar isto Onde diz : selfSay('Hello ' .. creatureGetName(cid) .. '! I buy swords, clubs, axes, helmets, boots, legs, shields and armors.') Depois de selfSay(' Você pode mudar oque vc deseja q o npc responda ao player.TENHA CERTEZA QUE VC NAO ESQUECEU DE COLOCAR ('depois de selfSay. Para acabar ..Sempre quando vc tem apostrofes ( ' ) na sua sentença vc sempre adiciona "\" depois disto. Exemplo: Hello, I'm a Npc Ficará assim: Hello, I\'m a Npc Agora como você ja aprendeu isso, nós iremos avançar um pouco. NPC COMPRANDO ITEMS Agora aqui um exemplo de como vender um item: elseif msgcontains(msg, 'crusader helmet') then sell(cid,3329,1,3000) Depois onde diz : (msg, '[ITEM HERE]') Vc põe oque o player tem q dizer para vender determinado item, como em cima, onde tem [iTEM HERE] vc poderia por Mpa, Crusader Helmet, Boh , etc... Onde diz : (cid,3329,1,3000) O 3229 é o ID do Item q vc vai vender . Mude isto para o item q vc deseja vender. O numero 1 eu aconselho nao mexer..Pois ira causar confusão na hora de vender ,por exemplo: O Player fala Sell Boh, e só tem 1 boh, o NPC quer 2, ou outro numero q vc colocar ai. E o numero 3000 é a quantidade de gold q o item custará, 3000=3k, 10000=10k e por ai vai.. Próximo tópico : VENDENDO RUNES Agora é um pouco mais dificil mexer com este script. Agora irei pegar outro npc, o Dark Rodo, em alguns servers pode variar para Malak. Em data/npcs/scripts/rune.lua obterá isso: talk_start = 0 target = 0 following = false 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 ((string.find(msg, '(%a*)hi(%a*)')) and (focus == 0)) and getDistanceToCreature(cid) < 4 then selfSay('Hello ' .. creatureGetName(cid) .. '! I sell hmms (40gps), uhs (40gps), gfbs (60gps), explosions (60gps), sds (90gps) and blank runes (5gps). You can also buy more runes, just say "10 uh" or "100 sd".') focus = cid talk_start = os.clock() elseif string.find(msg, '(%a*)hi(%a*)') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then selfSay('Sorry, ' .. creatureGetName(cid) .. '! I talk to you in a minute.') elseif msgcontains(msg, '100 hmm') and focus == cid then buy(cid,3136,100,800) talk_start = os.clock() elseif msgcontains(msg, '10 hmm') and focus == cid then buy(cid,3136,10,80) talk_start = os.clock() elseif msgcontains(msg, 'hmm') and focus == cid then buy(cid,3136,5,40) talk_start = os.clock() elseif msgcontains(msg, '100 uh') and focus == cid then buy(cid,3098,100,4000) talk_start = os.clock() elseif msgcontains(msg, '10 uh') and focus == cid then buy(cid,3098,10,400) talk_start = os.clock() elseif msgcontains(msg, 'uh') and focus == cid then buy(cid,3098,1,40) talk_start = os.clock() elseif msgcontains(msg, '100 gfb') and focus == cid then buy(cid,3129,100,2000) talk_start = os.clock() elseif msgcontains(msg, '10 gfb') and focus == cid then buy(cid,3129,10,200) talk_start = os.clock() elseif msgcontains(msg, 'gfb') and focus == cid then buy(cid,3129,3,60) talk_start = os.clock() elseif msgcontains(msg, '100 explosion') and focus == cid then buy(cid,3138,100,2000) talk_start = os.clock() elseif msgcontains(msg, '10 explosion') and focus == cid then buy(cid,3138,10,200) talk_start = os.clock() elseif msgcontains(msg, 'explosion') and focus == cid then buy(cid,3138,3,60) talk_start = os.clock() elseif msgcontains(msg, '100 sd') and focus == cid then buy(cid,3093,100,9000) talk_start = os.clock() elseif msgcontains(msg, '10 sd') and focus == cid then buy(cid,3093,10,900) talk_start = os.clock() elseif msgcontains(msg, 'sd') and focus == cid then buy(cid,3093,1,90) talk_start = os.clock() elseif msgcontains(msg, 'restoration') and focus == cid then buy(cid,3095,1,100) talk_start = os.clock() elseif msgcontains(msg, 'blank') and focus == cid then buy(cid,3085,1,5) talk_start = os.clock() elseif string.find(msg, '(%a*)bye(%a*)') and focus == cid and getDistanceToCreature(cid) < 4 then selfSay('Good bye, ' .. creatureGetName(cid) .. '!') focus = 0 talk_start = 0 end end function onCreatureChangeOutfit(creature) end function onThink() 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 Agora onde tem isso: elseif msgcontains(msg, 'hmm') and focus == cid then buy(cid,3136,5,40) talk_start = os.clock() Onde diz "hmm" é oq o player tem q dizer para compra uma hmm Agora onde diz : buy(cid,3136,5,40) O numero 3136 obviamente é o ID da HMM,o numero 5 é o numero de cargas por runa e o 40 é o preço q ira custar cada. Agora : elseif msgcontains(msg, '100 hmm') and focus == cid then buy(cid,3136,100,800) talk_start = os.clock() elseif msgcontains(msg, '10 hmm') and focus == cid then buy(cid,3136,10,80) talk_start = os.clock() Se o Player dizer 100 hmm , o NPC venderá uma runa com 100 cargas, como se pode ver no numero 100 >> buy(cid,3136,100,800) Se dizer 10, comprará uma runa de 10 cargas. e quantos mais ele quiser.. Agora avançamos mais um pouquinho Vendendo Items Se você quer um NPC pra vender items, é bem parecido com o de Runas.. Acompanhe: elseif msgcontains(msg, 'hmm') and focus == cid then buy(cid,3136,5,40) talk_start = os.clock() Eu irei mostrar tudo que vc tem q fazer para arruma-lo : 1. Mude : (msg, 'hmm') Para o ID do item buy(cid,3136,5,40) 2. O numero "5" que equivalia para o numero de cargas mude para a quantidade do item q será vendida, eu sugiro 1. 3. E por ultimo mude o numero "40" para quanto ira custar cada item. finalmente... NPC DO BARCO !!!! No padrão o NPC do boat é o Fargum... mas É so procurar os scripts do barcom em data/npc/scripts/boat.lua.. Esse é o script q vc verá : focus = 0talk_start = 0 target = 0 following = false 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 if isPremium(cid) then selfSay('Hello ' .. creatureGetName(cid) .. '! I can take you to the The City (20gp) or Dragon Land (50gp). Where do you want to go?') focus = cid talk_start = os.clock() else selfSay('Sorry, only premium players can travel by boat.') focus = 0 talk_start = 0 end 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() if msgcontains(msg, 'dragon land') then if pay(cid,50) then selfSay('Let\'s go!') selfSay('/send ' .. creatureGetName(cid) .. ', 122 119 7') focus = 0 talk_start = 0 else selfSay('Sorry, you don\'t have enough money.') end elseif msgcontains(msg, 'city') then if pay(cid,20) then selfSay('Let\'s go!') selfSay('/send ' .. creatureGetName(cid) .. ', 171 65 7') focus = 0 talk_start = 0 else selfSay('Sorry, you don\'t have enough money.') end elseif msgcontains(msg, 'bye') and getDistanceToCreature(cid) < 4 then selfSay('Good bye, ' .. creatureGetName(cid) .. '!') focus = 0 talk_start = 0 end end end function onCreatureChangeOutfit(creature) end function onThink() 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 _______________________________________ if msgcontains(msg, 'dragon land') then if pay(cid,50) then selfSay('Let\'s go!') selfSay('/send ' .. creatureGetName(cid) .. ', 122 119 7') focus = 0 talk_start = 0 else selfSay('Sorry, you don\'t have enough money.') end Aki é onde vai para diferentes cidades.. Como mandar o player para diferentes cidades ? Onde diz: selfSay('/send ' .. creatureGetName(cid) .. ', 122 119 7') Mude as coordenadas (122 119 7) pras cordenadas de onde vc ker q o npc mande o player e PRONTO ! Fácil não? Como mudar oque o NPC diz ? Aki nada muuuuito importante, mas vc pode mudar selfSay('Let\'s go!') Mude onde esta escrito (Let\'s go! ) para oque vc ker q ele diga. Como mudar o preço das passagens ? if pay(cid,50) then É só mudar o numero 50 para o preço da nova passagem. Espero ter ajudado eu sei q fico meio grandinho , mais eu kis faze completo, eu nunca escrevo aki mais vo começa a escreve de agora em diante =)) Obrigado pela atençao e postem suas opiniões por favor =) Credits: Saporaf (OTFANS) --> Fez o tutorial. Renanzinhoou --> Traduzi 100% do tutorial para o XTIBIA e adicionei scripts que faltavam e algumas perguntas úteis. Thanks CYA Link para o comentário Compartilhar em outros sites More sharing options...
Lordfire 309 Postado Agosto 3, 2007 Share Postado Agosto 3, 2007 Incrível! Ao menos tem um usuário consciente que bota os créditos! Nossa, muito bom Ensinou muito sobre NPCs Embora existam tutoriais sobre o mesmo assunto na seção de Desenvolvimenti Link para o comentário Compartilhar em outros sites More sharing options...
Jvchequer 63 Postado Agosto 6, 2007 Share Postado Agosto 6, 2007 Movido para a seção Correta. Atenciosamente, JV Chequer Link para o comentário Compartilhar em outros sites More sharing options...
Dekooo 0 Postado Agosto 10, 2007 Share Postado Agosto 10, 2007 Muito bom o seu tuto...vou estar adcionando pra minha lista Link para o comentário Compartilhar em outros sites More sharing options...
Zerocold 0 Postado Agosto 10, 2007 Share Postado Agosto 10, 2007 Gostei muito disto...isso eh facil...MAS e para qem nao sabe??!??! Parabens gostei Link para o comentário Compartilhar em outros sites More sharing options...
Ricard 0 Postado Agosto 10, 2007 Share Postado Agosto 10, 2007 parabéns pelo tuto... gostei bastante!! NO MORE Link para o comentário Compartilhar em outros sites More sharing options...
JP_OT 0 Postado Agosto 19, 2007 Share Postado Agosto 19, 2007 ow o npc de barco ta com akele bug de tem que fala em 1 milesimo pra ele funciona e telporta se nao nao como almenta o tempo de fala??? Link para o comentário Compartilhar em outros sites More sharing options...
h3online 1 Postado Outubro 28, 2008 Share Postado Outubro 28, 2008 Npc de barco to com algum errinho na infertace pq eu falo hi hi hi hi hi e ele n responde ai eu olho no ot fala q ta bom bug na infertafe say n sei oq vo copiar o erro pra k attempt to call global 'isPremium' <a nil value> Tb posso estar enganado mais acho q n é nem erro no npc e sim no global q deve tar faltando algum comando que aki no npc tenha hehe. Brigado pela atenção. Link para o comentário Compartilhar em outros sites More sharing options...
lolzot 0 Postado Maio 8, 2009 Share Postado Maio 8, 2009 ow o npc de barco ta com akele bug de tem que fala em 1 milesimo pra ele funciona e telporta se nao nao como almenta o tempo de fala??? TIPOW KRA O Q VC PODE FAZER EH PEGAR UM NPC QUE JA EXISTE E IR NO SCRIPT DELE A TIPOW SUBSTITUIR AS FALAS E AS AÇÕES QUE O NPC IRÁ EXECUTAR ^^ Link para o comentário Compartilhar em outros sites More sharing options...
Triibal 0 Postado Maio 8, 2009 Share Postado Maio 8, 2009 Parabéns, tutorial muito bom! Deve ter tirado dúvidas de muitos "Noobs" xD Abraços Link para o comentário Compartilhar em outros sites More sharing options...
Posts Recomendados