Olá,
Este code que eu vou liberar agora, facilitar a qualquer um (até quem não sabe mexer com NPC) a fazer um npc de entertrenimento que faz perguntas.
Primeiro mostrarei o NPC que eu fiz com perguntas sobre o tibiaking:
------NPC QUIZ BY COLEX------
focus = 0
talk_start = 0
target = 0
following = false
attacking = false
q = 1
w = 0
certas = 0
erradas = 0
question = {}
question[1] = {p="Quem é o atual administrador do tibiaking sem ser o Gustavo?", r="don"}
question[2] = {p="Quem é o coordenador registrado em julho de 2005?", r="caidera"}
question[3] = {p="Como se chama o mascote do tibiaking?", r="x-boy"}
question[4] = {p="Quem foi o primeiro colaborador de Actions do tibiaking", r="colex"}
question[5] = {p="Quem foi o vencedor do 1º tibiaking Scripting Championship?", r="xxxhiagoxxx"}
question[6] = {p="A regra número 3 da seção geral na parte OTServer fala sobre...", r="flood"}
question[7] = {p="Qual o nome da rádio oficial do tibiaking?", r="jovemix"}
question[8] = {p="Qual o nome da 1ª equipe a ter seu lugar no Incentivos tibiaking?", r="spol team"}
question[9] = {p="Qual o username do antigo moderador atual apoio, cujo sua primeira letra é igual a primeira letra do nome do site?", r="x9kill"}
question[10] = {p="Quem é o co-fundador da Spol Team?", r="bizugo"}
question[11] = {p="Quem deu a idéia para o projecto X-OTS?", r="jvchequer"}
question[12] = {p="Quem postou o code para NPCs venderem Bps de items?", r="frerety"}
function onThingMove(creature, thing, oldpos, oldstackpos)
end
function onCreatureAppear(creature)
end
function onCreatureDisappear(cid, pos)
if focus == cid then
selfSay('Good bye then.')
selfLook(cid)
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) < 6 then
selfSay('Olá, Eu sou um NPC de entertrenimento feito por Colex, para eu começar as perguntas digite: continuar.')
focus = cid
talk_start = os.clock()
end
if msgcontains(msg, 'hi') and (focus ~= cid) and getDistanceToCreature(cid) < 6 then
selfSay('Sorry, ' .. creatureGetName(cid) .. '! I talk to you in a minute.')
end
if (focus == cid) and getDistanceToCreature(cid) < 6 then
if (w == 1) then
if msgcontains(msg, question[q].r) then
selfSay('Certa resposta, diz Continuar para passar-mos a próxima pergunta!')
talk_start = os.clock()
q = q+1
certas = certas + 1
w = 0
else
selfSay('Resposta errada, diz Continuar para passar-mos a próxima pergunta!')
talk_start = os.clock()
q = q+1
w = 0
erradas = erradas + 1
end
else
if msgcontains(msg, 'continuar') then
if question[q] then
selfSay(question[q].p)
talk_start = os.clock()
w = 1
else
selfSay('Esta foi a última pergunta, voce teve ' .. certas .. ' respostas certas e ' .. erradas .. ' respostas erradas.')
focus = 0
talk_start = 0
q = 1
w = 0
certas = 0
erradas = 0
end
end
end
if msgcontains(msg, 'bye') or msgcontains(msg, 'xau') then
selfSay('Adeus, ' .. creatureGetName(cid) .. '!')
focus = 0
talk_start = 0
q = 1
w = 0
certas = 0
erradas = 0
end
end
end
function onCreatureChangeOutfit(creature)
end
function onThink()
if (os.clock() - talk_start) > 120 then
if focus > 0 then
selfSay('Próxima...')
q = 1
w = 0
certas = 0
erradas = 0
end
focus = 0
end
if focus ~= 0 then
if getDistanceToCreature(focus) > 5 then
selfSay('Adeus então.')
q = 1
w = 0
certas = 0
erradas = 0
end
end
end
------------------------------------------------------------------
<span style='font-size:12pt;line-height:100%'>Tutorial - Fazendo seu NPC de perguntas facilmente</span>
Este é um code de NPC Quiz virgem (sem perguntas) feito por mim:
------NPC QUIZ BY COLEX------
focus = 0
talk_start = 0
target = 0
following = false
attacking = false
q = 1
w = 0
certas = 0
erradas = 0
question = {}
function onThingMove(creature, thing, oldpos, oldstackpos)
end
function onCreatureAppear(creature)
end
function onCreatureDisappear(cid, pos)
if focus == cid then
selfSay('Good bye then.')
selfLook(cid)
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) < 6 then
selfSay('Olá, Eu sou um NPC de entertrenimento feito por Colex, para eu começar as perguntas digite: continuar.')
focus = cid
talk_start = os.clock()
end
if msgcontains(msg, 'hi') and (focus ~= cid) and getDistanceToCreature(cid) < 6 then
selfSay('Sorry, ' .. creatureGetName(cid) .. '! I talk to you in a minute.')
end
if (focus == cid) and getDistanceToCreature(cid) < 6 then
if (w == 1) then
if msgcontains(msg, question[q].r) then
selfSay('Certa resposta, diz Continuar para passar-mos a próxima pergunta!')
talk_start = os.clock()
q = q+1
certas = certas + 1
w = 0
else
selfSay('Resposta errada, diz Continuar para passar-mos a próxima pergunta!')
talk_start = os.clock()
q = q+1
w = 0
erradas = erradas + 1
end
else
if msgcontains(msg, 'continuar') then
if question[q] then
selfSay(question[q].p)
talk_start = os.clock()
w = 1
else
selfSay('Esta foi a última pergunta, voce teve ' .. certas .. ' respostas certas e ' .. erradas .. ' respostas erradas.')
focus = 0
talk_start = 0
q = 1
w = 0
certas = 0
erradas = 0
end
end
end
if msgcontains(msg, 'bye') or msgcontains(msg, 'xau') then
selfSay('Adeus, ' .. creatureGetName(cid) .. '!')
focus = 0
talk_start = 0
q = 1
w = 0
certas = 0
erradas = 0
end
end
end
function onCreatureChangeOutfit(creature)
end
function onThink()
if (os.clock() - talk_start) > 120 then
if focus > 0 then
selfSay('Próxima...')
q = 1
w = 0
certas = 0
erradas = 0
end
focus = 0
end
if focus ~= 0 then
if getDistanceToCreature(focus) > 5 then
selfSay('Adeus então.')
q = 1
w = 0
certas = 0
erradas = 0
end
end
end
para voce adicionar perguntas é mais facil que comer pão.
a seguir ao:
question = {}
voce vai adicionando o seguinte:
question[Nº DA PERGUNTA] = {p="PERGUNTA", r="RESPOSTA"}
é só isso, podia ser mais facil? com esse code que eu fiz, voce só terá que escrever aquilo que o script faz o resto e voce pode adicionar quantas perguntas quiser.
um exemplo de uma pergunta adicionada, neste exemplo a pergunta é a pergunta numero 5:
question[5] = {p="Quem fez este code?", r="colex"}
O code foi projetado para facilitar a criação desse tipo de NPC até a quem tem experiencia 0 com NPC's
Espero que aproveitem bem!
Alguma dúvida? sinta-se livre para perguntar!
100% by Colex
Atenciosamente,
Colex