Ir para conteúdo
Entre para seguir isso  
Convidado Oponomo

Como criar 1 NPC que ensina magias

Recommended Posts

Convidado Oponomo   
Convidado Oponomo

Pequena introdução: Eu estava precisando MUITO de um NPC que ensina magia para os players pois TODOS os OTs 7.92 que eu baixava não viam com ele, nem tinha um tutorial de como montar um nem achei nenhum na seção download para baixar, então para aqueles que precisarem assim como eu precisei, ai vai como monta-los ^^

 

Obs: Não botarei nenhum download completo do NPC já feito ou o code completo pois eu não dou o peixe, prefiro ENSINAR a pescar ;)

 

Começando 1 npc da maneira padrão:

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)

  	local msg = string.lower(msg)
Depois disso vem os "hi's":
if ((string.find(msg, '(%a*)hi(%a*)')) and (focus == 0)) and getDistanceToCreature(cid) < 4 then

  	if getPlayerVocation(cid) == 2 then

    selfSay('Hello ' .. creatureGetName(cid) .. '! What spell do you want to learn?')

    focus = cid

    talk_start = os.clock()

  	else

    selfSay('Sorry, I sell spells for druids.')

  end
Neste caso estou usando um NPC que apenas conversa com players da vocação DRUIDA. Como? Simples: If getPlayerVocation(cid) == 2 then

Isto em script está querendo dizer: "Se o jogador tiver a vocação 2(druida) então..."

Os próximos comandos estão nas 3 linhas abaixo: selfsay, focus e talk_start que significam respectivamente: A fala do NPC, a pessoa com quem o NPC esta falando e... sinceramente não sei :P

 

"else" Significa em ingles "senão" ou seja, senão acontecer aquelas condições depois do "if" = "se"(em portugues), acontecerá os seguintes comandos.. Neste caso só tem 1 que é o "selfsay", onde fará o npc dizer o que está dentro dos apóstrofos que estão dentro dos parenteses, ou seja: "Sorry, I sell spells for druids." E já que não ocorreu a ação "focus=cid" o player não está com a atenção do NPC.

 

"end" serve para fechar a ação. CASO QUEIRA QUE O NPC FALE COM QUALQUER VOCAÇÃO, SUBSTITUA ESSE CODE POR:

if ((string.find(msg, '(%a*)hi(%a*)')) and (focus == 0)) and getDistanceToCreature(cid) < 4 then

    selfSay('Hello ' .. creatureGetName(cid) .. '! What spell do you want to learn?')

    focus = cid

    talk_start = os.clock()

Logo após coloque:
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()
Simplesmente copie isso abaixo do código anterior. Ele fará com que o NPC diga:"Sorry, (Player)! I talk to you in a minute."

 

Agora vamos as magias, aqui está o exemplo da magia "light healing":

 	if msgcontains(msg, 'light healing') and focus == cid then 

  	if pay(cid,170) then

    	learnSpell(cid,'exura')

  	else selfSay('Sorry, you don\'t have enough money.') 

  	talk_start = os.clock() 

  	end
1- "light healing" é o que o personagem precisa dizer para comprar a magia.

2- "if pay(cid,170)..." significa que ele terá que pagar 170 gold coins por ela.

3- "learnSpell(cid,'exura')" Fará com que o player aprenda a magia "exura".

 

else = caso não aconteça a condição "pagar 170 gold coins", ao invez de acontecer 1, 2 e 3 acima, acontecerá...

 

1- O NPC dirá: "Sorry, you don't have enough money."

Deve-se ter o "end" ao final.

Pronto! Ele ensina a magia light healing ;) ... Se quiser fazer com que o NPC fale com todos MAS apenas ensine a magia para uma certa vocação, substitua o codigo anterior por:":

 	if msgcontains(msg, 'light healing') and focus == cid then 

                                  if getPlayerVocation(cid) == 2 then

  	if pay(cid,170) then

    	learnSpell(cid,'exura')

  	else selfSay('Sorry, you don\'t have enough money.') 

  	talk_start = os.clock() 

  	end

                                    else

                                    selfSay('Sorry, I sell spells for druids.')

                                          end
Neste caso apenas o druida aprenderá a magia. Para acrescentar mais magias copie outro código como o do "light healing" logo abaixo dele e mude os escritos óbvios...

Exemplo: troque o "light healing" por "light", o "exura" por "utevo lux" e o "pay(cid,170)" por "pay(cid,70)" para pagar 70 gold ao invez de 170.

Lembre-se de nas próximas magias botar o comando "ELSE" antes do código, senão não funcionará o NPC.if msgcontains(msg, 'light healing') and focus == cid then

if pay(cid,170) then

learnSpell(cid,'exura')

else selfSay('Sorry, you don\'t have enough money.')

talk_start = os.clock()

end

Atenção: A vocação "druid" não é a mesma que "Elder druid"

 

Para escolher quais vocações vão conversar com o npc ou aprender as magias restritas, troque os números 2 ou 6 para outro...1 = Sorcerer

2 = Druid

3 = Paladin

4 = Knight

5 = Master sorcerer

6 = Elder druid

7 = Royal paladin

8 = Elite knight

Depois de colocar todas as magias que quiser, bote o codigo:

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 focus > 0 then 

 x, y, z = creatureGetPosition(focus)

 myx, myy, myz = selfGetPosition()

 if ((myy-y==0) and (myx-x<=0 and myx-x>=-4)) then

       selfTurn(0)

 end 

 if ((myy-y==0) and (myx-x>=0 and myx-x<=4)) then

       selfTurn(2)

 end

       if ((myx-x==0) and (myy-y<=0 and myy-y>=-4)) then

       selfTurn(1)

 end

 if ((myx-x==0) and (myy-y>=0 and myy-y<=4)) then

       selfTurn(3)

 end

 if ((myy-y==-2) and (myx-x>=-1 and myx-x<=1)) then

       selfTurn(1)

 end

 if ((myy-y==2) and (myx-x>=-1 and myx-x<=1)) then

        selfTurn(3)

 end

 if ((myx-x==2) and (myy-y>=-1 and myy-y<=1)) then

        selfTurn(2)

 end

 if ((myx-x==-2) and (myy-y>=-1 and myy-y<=1)) then

        selfTurn(0)

 end

 if ((myy-y==-3) and (myx-x>=-2 and myx-x<=2)) then

        selfTurn(1)

 end

 if ((myy-y==3) and (myx-x>=-2 and myx-x<=2)) then

        selfTurn(3)

 end

 if ((myx-x==3) and (myy-y>=-2 and myy-y<=2)) then

        selfTurn(2)

 end

 if ((myx-x==-3) and (myy-y>=-2 and myy-y<=2)) then

        selfTurn(0)

 end

 if ((myy-y==-4) and (myx-x>=-3 and myx-x<=3)) then

        selfTurn(1)

 end

 if ((myy-y==4) and (myx-x>=-3 and myx-x<=3)) then

        selfTurn(3)

 end

 if ((myx-x==4) and (myy-y>=-3 and myy-y<=3)) then

        selfTurn(2)

 end

 if ((myx-x==-4) and (myy-y>=-3 and myy-y<=3)) then

        selfTurn(0)

 end

end



 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

Este npc tem 2 erros:

1- Se voce já sabe a magia e pede novamente, voce vai pegar o dinheiro do custo dela e ele vai dizer que voce já a conhece.

2- Ele fica de lado em relação ao player.

 

Se quiser com que o NPC fique parado sem mudar de direção substitua o ultimo código por:

 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

Se souber como consertar qualquer um desses 2 erros, por favor me avise!

Abração![/code]

Compartilhar este post


Link para o post
Compartilhar em outros sites
ZehbOi    0
ZehbOi

Aprovado.. :)

Compartilhar este post


Link para o post
Compartilhar em outros sites
jacs    0
jacs

mano gostei mesmo m ajudo muito tnks

Compartilhar este post


Link para o post
Compartilhar em outros sites
Trimera    0
Trimera

kkk nunca tinha visto um npc q ensinava magia vo cloka lah no Ot meu xD

Compartilhar este post


Link para o post
Compartilhar em outros sites
Artzenho    0
Artzenho

pod cre maniho me ajudo muuuiittooooo,fiz ake e deu tudo certo até d+ ^^

 

vlw ai;P

Compartilhar este post


Link para o post
Compartilhar em outros sites
Addicted    1
Addicted

@Artzenho

Você reviveu um tópico, o que não é permetido.

Leia as Regras antes de fazer algo que não tenha certeza :)

 

RcD~

Compartilhar este post


Link para o post
Compartilhar em outros sites
GM_Elnight    0
GM_Elnight

muito bom,valeu

Compartilhar este post


Link para o post
Compartilhar em outros sites
leandro_70    0
leandro_70

Muito bom,vo coloka no meu OT

primofanuf0.gif

Doe OT$

Compartilhar este post


Link para o post
Compartilhar em outros sites
murin1995    0
murin1995

Onde tenho que colocar todos os escripts???

Compartilhar este post


Link para o post
Compartilhar em outros sites
BadBR    0
BadBR

Nossa achei na hora certa precisava muito para o NsO!

Compartilhar este post


Link para o post
Compartilhar em outros sites
Visitante
Este tópico está impedido de receber novos posts.
Entre para seguir isso  

  • Quem Está Navegando   0 membros estão online

    Nenhum usuário registrado visualizando esta página.

×