Modificandu Seus Npcs

meleca
Por meleca
em Tutoriais de Scripting

meleca

avatar
Campones
Campones

INFOS

Grupo: CamponesRegistrado: 22/10/05Posts: 18

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!

~~mlc~~

1 vez Tibiano , Sempre Tibiano.

~~Viva as Diferenças , Fod@-Se a Igualdade~~

untitled1xj2.jpg

userbar010xo.gif

hacker7mj.gif

meutrabalho025yw.png

Rafix

Banido
avatar
Barão
Barão

INFOS

Grupo: BarãoRegistrado: 30/08/05Posts: 231Char no Tibia: retired

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

Usuário Banido.

Motivo: Atitude Ofensivas

meleca

avatar
Campones
Campones

INFOS

Grupo: CamponesRegistrado: 22/10/05Posts: 18

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:

~~mlc~~

1 vez Tibiano , Sempre Tibiano.

~~Viva as Diferenças , Fod@-Se a Igualdade~~

untitled1xj2.jpg

userbar010xo.gif

hacker7mj.gif

meutrabalho025yw.png

x9kill

Frésco ♪
avatar
Cavaleiro
Cavaleiro

INFOS

Grupo: CavaleiroRegistrado: 22/09/05Posts: 178Char no Tibia: Tibia sux.
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

do you wanna a suruba ?

-

vtc3wedzwocumnphw0if.jpg


brigads
arcazy
signmg5.jpg
-
flyw
test2vk7.png

p/ os mikows

gi8ng2hzulbxb0yagvue.jpg
-
le7qv4iz311k1ugg95.jpg

Yuki Girl

Membro
avatar
Campones
Campones

INFOS

Grupo: CamponesRegistrado: 03/11/05Posts: 7
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.

Yuki Girl @ EX-Equipe XTibia / EX-Coordenadora. Sou a EX-coordenadora, okay? o_o

 

Sim! Eu voltei à ativa ao forum! ^^

 

Assinatura e SIGN nova em construção.

 

Sou uma pessoa que não aceita ver ou ouvir erros gramaticais, ortográficos, entre outros em Português u_u

 

A vida tem o sabor que a gente escolhe.

A vida tem a cor que a gente pinta.

A vida tem o tempo que nos ensina.

A vida tem o amor que a gente se apaixona.

A vida tem a sorte que é de repente.

 

By Yuki Girl

 

Meu jogo favorito? Ha! Nem se fala! Simplesmente Zelda ;)

 

user posted image

 

Eu adotei um plushie! Adote um você tambêm.

Chakau

Banido
avatar
Banidos
Banidos

INFOS

Grupo: BanidosRegistrado: 09/11/06Posts: 278

Muito bom kra

ajudou bastante

obrigado

[Usuário banido, Ofensas/Xingamentos a Equipe]
Addict

Tyler

avatar
Campones
Campones

INFOS

Grupo: CamponesRegistrado: 03/02/07Posts: 80
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 ! ^^



é meu fan ? te ajudei ? foi totalmente com a minha cara ? ta aew a fan bar ^^!



Fan de




UhUl LePaRkOuR

christen

Simplesmente EU
avatar
Artesão
Artesão

INFOS

Grupo: ArtesãoRegistrado: 16/07/07Posts: 120

EH BOM PARA QUEM N SABE

------------------------------------------------------------------------------------------------------------------------

 

2ev67tw.gif

Click no banner para saber sobre o andamento do servidor!

thayam

avatar
Cavaleiro
Cavaleiro

INFOS

Grupo: CavaleiroRegistrado: 02/11/05Posts: 179Char no Tibia: Dehby Dias, Hacked

Bouaa kra

certinhu, funfa em todas as versões eu acredito

flws ae