ME

Modificandu Seus Npcs

Por meleca, 02 de nov. de 2005 em Tutoriais de Scripting

script
9
2.7k
melecaM
02 de novembro de 2005 às 14:40

Aew, quando eu tava jogando em OT pela primeira vez eu sempre dizia pros NPCs: hi / sd ... mas naum pra comprar e sim pra ver o preço... mas acabava comprando... Bom, dei um jeito pra eles falarem alguma coisa do tipo: "vc quer comprar uma sd por 10gp?" ou melhor ainda: "vc quer uma sd de 1, 10, 50 ou 100 cargas?"...

Ah, eu uso yurots 7.5, intaum naum sei se vai funfar pra otro ot...

vo pegar como exemplo o vendedor de runas padrão do yurots que eu baxei...

esse código ta dentro de data/npc/scripts no arquivo runes.lua:

 

-- Respawn position set--ox = 44--oy = 5--oz = 6focus = 0talk_start = 0target = 0following = falseattacking = falsefunction onThingMove(creature, thing, oldpos, oldstackpos)endfunction onCreatureAppear(creature)endfunction onCreatureDisappear(cid, pos) if focus == cid then        selfSay('Good bye then.')        focus = 0        talk_start = 0 endendfunction onCreatureTurn(creature)endfunction msgcontains(txt, str) return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)'))endfunction onCreatureSay(cid, type, msg) msg = string.lower(msg) if ((string.find(msg, '(%a*)hi(%a*)')) and (focus == 0)) and getDistanceToCreature(cid) < 3 then  selfSay('Hello ' .. creatureGetName(cid) .. '! I sell hmms (40gps), uhs (10gps), gfbs (10gps), explosions (60gps), sds (10gps) 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) < 3 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,500)  talk_start = os.clock() elseif msgcontains(msg, '10 hmm') and focus == cid then  buy(cid,3136,10,50)  talk_start = os.clock() elseif msgcontains(msg, 'hmm') and focus == cid then  buy(cid,3136,5,5)  talk_start = os.clock()elseif msgcontains(msg, '100 uh') and focus == cid then  buy(cid,3098,100,600)  talk_start = os.clock()elseif msgcontains(msg, '10 uh') and focus == cid then  buy(cid,3098,10,60)  talk_start = os.clock() elseif msgcontains(msg, 'uh') and focus == cid then  buy(cid,3098,1,6)  talk_start = os.clock() elseif msgcontains(msg, '100 gfb') and focus == cid then  buy(cid,3129,100,600)  talk_start = os.clock()elseif msgcontains(msg, '10 gfb') and focus == cid then  buy(cid,3129,10,60)  talk_start = os.clock() elseif msgcontains(msg, 'gfb') and focus == cid then  buy(cid,3129,3,6)  talk_start = os.clock()elseif msgcontains(msg, '100 explosion') and focus == cid then  buy(cid,3138,100,900)  talk_start = os.clock()elseif msgcontains(msg, '10 explosion') and focus == cid then  buy(cid,3138,10,90)  talk_start = os.clock() elseif msgcontains(msg, 'explosion') and focus == cid then  buy(cid,3138,3,9)  talk_start = os.clock()elseif msgcontains(msg, '100 sd') and focus == cid then  buy(cid,3093,100,1000)  talk_start = os.clock()elseif msgcontains(msg, '10 sd') and focus == cid then  buy(cid,3093,10,100)  talk_start = os.clock() elseif msgcontains(msg, 'sd') and focus == cid then  buy(cid,3093,1,10)  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) < 3 then  selfSay('Good bye, ' .. creatureGetName(cid) .. '!')  focus = 0  talk_start = 0 endendfunction onCreatureChangeOutfit(creature)endfunction onThink() if (os.clock() - talk_start) > 30 then  if focus > 0 then   selfSay('Next Please...')  end   focus = 0 endend

 

Vamos começar:

nós vamos precisar de um artifício, uma espécie de contador. Todo lugar que tiver um 'focus = 0', adicione na linha de baixo um 'contador = 0', por exemplo:

 

focus = 0contador = 0talk_start = 0target = 0following = falseattacking = false

 

agora faça o seguinte:

substitua isto tudo:

 

elseif msgcontains(msg, '100 hmm') and focus == cid then  buy(cid,3136,100,500)  talk_start = os.clock() elseif msgcontains(msg, '10 hmm') and focus == cid then  buy(cid,3136,10,50)  talk_start = os.clock() elseif msgcontains(msg, 'hmm') and focus == cid then  buy(cid,3136,5,5)  talk_start = os.clock()

 

por:

 

elseif msgcontains(msg, 'hmm') and focus == cid then  selfSay('1, 10, 50 ou 100 cargas?')  contador = 1  talk_start = os.clock()elseif msgcontains(msg, '100') and focus == cid and contador == 1 then  buy(cid,3136,100,500)  talk_start = os.clock()elseif msgcontains(msg, '50') and focus == cid and contador == 1 then  buy(cid,3136,50,250)  talk_start = os.clock()elseif msgcontains(msg, '10') and focus == cid and contador == 1 then  buy(cid,3136,10,50)  talk_start = os.clock()elseif msgcontains(msg, '1') and focus == cid and contador == 1 then  buy(cid,3136,1,5)  talk_start = os.clock()

 

Faça o mesmo para todas as outras runas, mas mudando o numero do contador, por exemplo, para SD vc poe contador = 2, para UH, cotador = 3, etc.:

Jah no caso da Blank runevc faz o seguinte, o codigo original eh esse:

 

elseif msgcontains(msg, 'blank') and focus == cid then  buy(cid,3085,1,5)  talk_start = os.clock()

 

substitua tudo por:

 

elseif msgcontains(msg, 'blank') and focus == cid then                               sefSay('Vc quer comprar 1 blank rune por 10gp?')                               contador = 6 elseif msgcontains(msg, 'sim') and focus == cid and contador == 6 then  buy(cid,3085,1,5)  talk_start = os.clock()

 

Bom, eh isso, pra quem naum ta nem ai pra minha explikação e soh quer o código final de um vendedor de HMM, UH, GFB, XPL, SD e Blank. ai vai:

 

-- Respawn position set--ox = 44--oy = 5--oz = 6focus = 0contador = 0talk_start = 0target = 0following = falseattacking = falsefunction onThingMove(creature, thing, oldpos, oldstackpos)endfunction onCreatureAppear(creature)endfunction onCreatureDisappear(cid, pos) if focus == cid then        selfSay('Good bye then.')        focus = 0        contador = 0        talk_start = 0 endendfunction onCreatureTurn(creature)endfunction msgcontains(txt, str) return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)'))endfunction onCreatureSay(cid, type, msg) msg = string.lower(msg) if ((string.find(msg, '(%a*)hi(%a*)')) and (focus == 0)) and getDistanceToCreature(cid) < 3 then  selfSay('Hello ' .. creatureGetName(cid) .. '! I sell hmms (5gps), uhs (10gps), gfbs (10gps), explosions (10gps), sds (10gps) 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) < 3 then  selfSay('Sorry, ' .. creatureGetName(cid) .. '! I talk to you in a minute.')elseif msgcontains(msg, 'hmm') and focus == cid then                               selfSay('1x, 10x, 50x ou 100x?')                               contador = 1  talk_start = os.clock()elseif msgcontains(msg, '100') and focus == cid and contador == 1 then  buy(cid,3136,100,500)  talk_start = os.clock()               elseif msgcontains(msg, '50') and focus == cid and contador == 1 then                               buy(cid,3136,50,250)  talk_start = os.clock() elseif msgcontains(msg, '10') and focus == cid and contador == 1 then  buy(cid,3136,10,50)  talk_start = os.clock() elseif msgcontains(msg, '1') and focus == cid and contador == 1 then  buy(cid,3136,5,5)  talk_start = os.clock()elseif msgcontains(msg, 'uh') and focus == cid then                               selfSay('1x, 10x, 50x ou 100x?')                               contador = 2  talk_start = os.clock()elseif msgcontains(msg, '100') and focus == cid and contador == 2 then  buy(cid,3098,100,600)  talk_start = os.clock()elseif msgcontains(msg, '50') and focus == cid and contador == 2 then  buy(cid,3098,50,300)  talk_start = os.clock()elseif msgcontains(msg, '10') and focus == cid and contador == 2 then  buy(cid,3098,10,60)  talk_start = os.clock() elseif msgcontains(msg, '1') and focus == cid and contador == 2 then  buy(cid,3098,1,6)  talk_start = os.clock()elseif msgcontains(msg, 'gfb') and focus == cid then                               selfSay('1x, 10x, 50x ou 100x?')                               contador = 3  talk_start = os.clock() elseif msgcontains(msg, '100') and focus == cid and contador == 3 then  buy(cid,3129,100,600)  talk_start = os.clock()elseif msgcontains(msg, '50') and focus == cid and contador == 3 then  buy(cid,3129,50,300)  talk_start = os.clock()elseif msgcontains(msg, '10') and focus == cid and contador == 3 then  buy(cid,3129,10,60)  talk_start = os.clock() elseif msgcontains(msg, '1') and focus == cid and contador == 3 then  buy(cid,3129,3,6)  talk_start = os.clock()elseif msgcontains(msg, 'explosion') and focus == cid then                               selfSay('1x, 10x, 50x ou 100x?')                               contador = 4  talk_start = os.clock()elseif msgcontains(msg, '100') and focus == cid and contador == 4 then  buy(cid,3138,100,900)  talk_start = os.clock()elseif msgcontains(msg, '50') and focus == cid and contador == 4 then  buy(cid,3138,50,450)  talk_start = os.clock()elseif msgcontains(msg, '10') and focus == cid and contador == 4 then  buy(cid,3138,10,90)  talk_start = os.clock() elseif msgcontains(msg, '1') and focus == cid and contador == 4 then  buy(cid,3138,3,9)  talk_start = os.clock()elseif msgcontains(msg, 'sd') and focus == cid then                               selfSay('1x, 10x, 50x ou 100x?')                               contador = 5  talk_start = os.clock()elseif msgcontains(msg, '100') and focus == cid and contador == 5 then  buy(cid,3093,100,1000)  talk_start = os.clock()elseif msgcontains(msg, '50') and focus == cid and contador == 5 then  buy(cid,3093,50,500)  talk_start = os.clock()elseif msgcontains(msg, '10') and focus == cid and contador == 5 then  buy(cid,3093,10,100)  talk_start = os.clock() elseif msgcontains(msg, '1') and focus == cid and contadori == 5 then  buy(cid,3093,1,10)  talk_start = os.clock() elseif msgcontains(msg, 'blank') and focus == cid then                               sefSay('Vc quer comprar 1 blank rune por 10gp?')                               contador = 6 elseif msgcontains(msg, 'sim') and focus == cid and contador == 6 then  buy(cid,3085,1,5)  talk_start = os.clock() elseif string.find(msg, '(%a*)bye(%a*)') and focus == cid and getDistanceToCreature(cid) < 3 then  selfSay('Good bye, ' .. creatureGetName(cid) .. '!')  focus = 0                               contador = 0  talk_start = 0 endendfunction onCreatureChangeOutfit(creature)endfunction onThink() if (os.clock() - talk_start) > 30 then  if focus > 0 then   selfSay('Next Please...')  end   focus = 0                                               contador = 0 endend

 

ufa, eh isso... tomara que eu tenha ajudado alguém... :grin:

Se 1 cara postar aki dizendo que eu ajudei jah vo fikar feliz...

Eh isso ai... qq dúvida posta que eu ajudo!

RafixR
03 de novembro de 2005 às 15:11

Boa, meleca, mas isso naum vai precisar muito, pq se o cara ta com pressa, vai ter que dizer por exemplo:

sd

yes

e ficar repitindo enquanto podia soh dizer "sd", olha quando vc falar hi, o npc diz i sell hmms(40gp), uh(40gp)... e tudo o que ele vende, entao eh soh olhar por la e ja sabera preço.

Portanto, isso ajudou, à muitos que querem confirmação, e que saum tranquilos, foi um ótimo tutorial, parabéns...

Flws

Atenciosamente,

Rafix

melecaM
05 de novembro de 2005 às 10:16

vlw rafix pelo comment , to ai pra colquer coisa xD

ai glr comentem plxx ...... :ohmy:

Daki alguns dias vou estar postandu u meu ot nus downloads

MeLeCa Team !!

melecaserv.servegame.com :laughing:

2 semanas depois...
x9killX
15 de novembro de 2005 às 12:44
Eu gosto de comentar!!

 

 

 

Flooder?????

*¨¨Meleca

muito legal o code que você criou, é interessante ter um NPC deste tipo em um server survival ou parecido.

Isto só não serve para algum servidor PVP.

Parabens!!

Abraços,

x9kill

Editado Novembro 15 por x9kill

Yuki GirlY
15 de novembro de 2005 às 12:44
Eu gosto de comentar!!

 

 

 

1° Obrigada usuário x9kill pela sua notificação do usuário rafix.

2° Evite o flood ok rafix? Não irei te alertar,mais cuidado.

3° Pela notificação enviada pelo usuário x9kill você está algumas vezes floodando, então vou agora prestar atenção em seus tópicos e posts.

Obrigada x9kill.

Obrigada,

Yuki Girl, Equipe XTibia.

1 ano depois...
ChakauC
23 de fevereiro de 2007 às 17:50

Muito bom kra

ajudou bastante

obrigado

TylerT
24 de fevereiro de 2007 às 10:13
Muito bom kra

ajudou bastante

obrigado

 

Nussa meu reviveu o topico llaaaaaaaa de do fundo do bau ..

 

@topic

 

Um bom npc , Util e nao muito complicado de se faser ! ^^

7 meses depois...
christenC
10 de setembro de 2007 às 12:02

EH BOM PARA QUEM N SABE

thayamT
10 de setembro de 2007 às 12:39

Bouaa kra

certinhu, funfa em todas as versões eu acredito

flws ae