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!