Parece ser bem interessante, mas esse é um código do Oneshot, portanto, seria interessante pedir a permissão dele antes de postar.
Fora isso, ideia bacana.
info
Grupo: Infante
Registrado: 13/10/08
Posts: 1.6k
Reputação: +420
Char no Tibia: Demonbholder

Parece ser bem interessante, mas esse é um código do Oneshot, portanto, seria interessante pedir a permissão dele antes de postar.
Fora isso, ideia bacana.
info
Grupo: Campones
Registrado: 18/06/12
Posts: 36
Reputação: +5
Char no Tibia: Akira
Fala Galera! Tudo Beleza?
Venho trazer a você O NPC QUIZ!
Esse NPC vai fazer perguntas ao jogador que devera responder-las corretamente, caso erre, duas criaturas configuráveis iriam aparecer.
INSTALAÇÃO E CONFIGURAÇÃO:
data/npc/scripts
--[[
NPC de Perguntas e Respostas
Criado por Bruno Lopes / Lpz
© 2011 #####
]]--
local focuses = {}
local talk_start = 0
local topic = {}
local var = 0
local quiz = {
[1] = {"What is the ring of mana?", "energy ring"},
[2] = {"Who sells addons?", "raphael"}
}
local monster = {"Orc", 2}
local prize = {
question = 100,
all = 10000
}
function onCreatureSay(cid, type, msg)
local msg = msg:lower() or ""
if getNpcDistanceTo(cid) > 3 then
return false
end
if doMessageCheck(msg, {"hi", "hello"}) and not(isFocused(cid, focuses)) then
selfSay("Hello, ".. getCreatureName(cid) ..". Can you answer my questions? heh...", cid)
addFocus(cid, focuses)
selfFocus(cid)
topic[cid] = 100
talk_start = os.clock()
elseif doMessageCheck(msg, {"hi", "hello"}) and #focuses ~= 0 then
selfSay("Sorry, ".. getCreatureName(cid) ..". I am talking with another person, wait!", cid)
end
if doMessageCheck(msg, {"bye", "farewell", "goodbye"}) and isFocused(cid, focuses) then
selfSay("Bye-bye, hehe!", cid)
removeFocus(cid, focuses)
end
if topic[cid] == 100 then
if doMessageCheck(msg, "yes") then
selfSay("To start my challenge, just say {ready}. I will ask you some questions.", cid)
topic[cid] = 1
elseif doMessageCheck(msg, "no") then
selfSay("Huh? Why are you here then?", cid)
removeFocus(cid, focuses)
topic[cid] = 0
end
elseif topic[cid] == 1 then
if var == 0 then
if doMessageCheck(msg, "ready") then
var = 1
selfSay(quiz[var][1], cid)
end
elseif var >= 1 then
if var <= #quiz then
if doMessageCheck(msg, quiz[var][2]) then
selfSay("CORRECT!", cid)
doPlayerAddMoney(cid, prize.question)
var = var+1
if var > #quiz then
selfSay("CONGRATULATIONS! YOU HAVE FINISHED ALL QUESTIONS!", cid)
doPlayerAddMoney(cid, prize.all)
else
selfSay(quiz[var][1], cid)
end
else
selfSay("YOU HAVE WRONG MY QUESTION! GUARDS, COME HERE!", cid)
var = 0
topic[cid] = 0
removeFocus(cid, focuses)
for i = 1, monster[2] do
doCreateMonster(monster[1], getNpcPos())
end
end
end
end
end
return true
end
function onThink()
for _, cid in ipairs(focuses) do
if isPlayer(cid) and isFocused(cid, focuses) then
if os.clock() > (talk_start + 180) then
talk_start = 0
selfSay("Hmph!")
closeShopWindow(cid)
removeFocus(cid, focuses)
elseif getNpcDistanceTo(cid) > 3 then
talk_start = 0
selfSay("How Rude!")
closeShopWindow(cid)
removeFocus(cid, focuses)
end
end
end
lookAtFocus(focuses)
end
Leia:
Bom eu peguei o arquivo.lua que você iria associar a algum npc de seu servidor, deixo o arquivo .xml por sua conta.
Como é um NPC que faz perguntas, você pode configurar o seu NPC do jeito que você quiser, com as perguntas que você quiser.
Veja como proceder:
local quiz = {
[1] = {"What is the ring of mana?", "energy ring"},
[2] = {"Who sells addons?", "raphael"}
}
Para adicionar novas perguntas, basta você colocar uma vírgula na última linha e criar uma nova linha conforme o modelo:
local quiz = {
[1] = {"What is the ring of mana?", "energy ring"},
[2] = {"Who sells addons?", "raphael"},
[3] = {"PERGUNTA", "RESPOSTA"},
[4] = {"PERGUNTA", "RESPOSTA"}
}
Há também algumas outras configurações básicas para você fazer, as criaturas que irão aparecer caso o jogador erre a pergunta e a quantidade. Também você pode configurar a quantidade de dinheiro que o jogador ganha quando acerta uma pergunta e a quantidade de dinheiro do prêmio final.
local monster = {"Orc", 2}
local prize = {
question = 100,
all = 10000
}
OBSERVAÇÃO:
Para evitar quaisquer erros no script, substitua o conteúdo de npc.lua em data/npc/lib por este que estou passando abaixo:
function selfSayChannel(cid, message)
return selfSay(message, cid, false)
end
function selfMoveToThing(id)
errors(false)
local thing = getThing(id)
errors(true)
if(thing.uid == 0) then
return
end
local t = getThingPosition(id)
selfMoveTo(t.x, t.y, t.z)
return
end
function selfMoveTo(x, y, z)
local position = {x = 0, y = 0, z = 0}
if(type(x) ~= "table") then
position = Position(x, y, z)
else
position = x
end
if(isValidPosition(position)) then
doSteerCreature(getNpcId(), position)
end
end
function selfMove(direction, flags)
local flags = flags or 0
doMoveCreature(getNpcId(), direction, flags)
end
function selfTurn(direction)
doCreatureSetLookDirection(getNpcId(), direction)
end
function getNpcDistanceTo(id)
errors(false)
local thing = getThing(id)
errors(true)
if(thing.uid == 0) then
return nil
end
local c = getCreaturePosition(id)
if(not isValidPosition©) then
return nil
end
local s = getCreaturePosition(getNpcId())
if(not isValidPosition(s) or s.z ~= c.z) then
return nil
end
return math.max(math.abs(s.x - c.x), math.abs(s.y - c.y))
end
function doMessageCheck(message, keyword)
if(type(keyword) == "table") then
return table.isStrIn(message, keyword)
end
local a, b = message:lower(), keyword:lower()
if(keyword == message) then
return true
end
return message:find(keyword) and not message:find('(%w+)' .. keyword)
end
function doNpcSellItem(cid, itemid, amount, subType, ignoreCap, inBackpacks, backpack)
local amount, subType, ignoreCap, item = amount or 1, subType or 1, ignoreCap and true or false, 0
if(isItemStackable(itemid)) then
if(isItemRune(itemid)) then
amount = amount * subType
end
local count = amount
repeat
item = doCreateItemEx(itemid, math.min(100, count))
if(doPlayerAddItemEx(cid, item, ignoreCap) ~= RETURNVALUE_NOERROR) then
return 0, 0
end
count = count - math.min(100, count)
until count == 0
return amount, 0
end
local a = 0
if(inBackpacks) then
local container, b = doCreateItemEx(backpack, 1), 1
for i = 1, amount do
item = doAddContainerItem(container, itemid, subType)
if(itemid == ITEM_PARCEL) then
doAddContainerItem(item, ITEM_LABEL)
end
if(isInArray({(getContainerCapById(backpack) * b), amount}, i)) then
if(doPlayerAddItemEx(cid, container, ignoreCap) ~= RETURNVALUE_NOERROR) then
b = b - 1
break
end
a = i
if(amount > i) then
container = doCreateItemEx(backpack, 1)
b = b + 1
end
end
end
return a, b
end
for i = 1, amount do
item = doCreateItemEx(itemid, subType)
if(itemid == ITEM_PARCEL) then
doAddContainerItem(item, ITEM_LABEL)
end
if(doPlayerAddItemEx(cid, item, ignoreCap) ~= RETURNVALUE_NOERROR) then
break
end
a = i
end
return a, 0
end
function doRemoveItemIdFromPosition(id, n, position)
local thing = getThingFromPos({x = position.x, y = position.y, z = position.z, stackpos = 1})
if(thing.itemid ~= id) then
return false
end
doRemoveItem(thing.uid, n)
return true
end
function getNpcName()
return getCreatureName(getNpcId())
end
function getNpcPos()
return getThingPosition(getNpcId())
end
function selfGetPosition()
local t = getThingPosition(getNpcId())
return t.x, t.y, t.z
end
function isFocused(cid, t)
for i, v in pairs(t) do
if(v == cid) then
return true
end
end
return false
end
function addFocus(focus, t)
if(not isFocused(focus, t)) then
table.insert(t, focus)
end
end
function setFocus(t)
for i, v in pairs(t) do
if(isPlayer(v)) then
doNpcSetCreatureFocus(v)
return
end
end
doNpcSetCreatureFocus(0)
end
function removeFocus(cid, t)
for i, v in pairs(t) do
if(v == cid) then
table.remove(t, i)
selfFocus(0)
break
end
end
end
function doCreatureSayWithDelay(cid,text,type,delay,e)
if delay<=0 then
doCreatureSay(cid,text,type)
else
local func=function(pars)
doCreatureSay(pars.cid,pars.text,pars.type)
pars.e.done=TRUE
end
e.done=FALSE
e.event=addEvent(func,delay,{cid=cid, text=text, type=type, e=e})
end
end
function cancelNPCTalk(events)
local ret = 1
for aux = 1,table.getn(events) do
if events[aux].done==FALSE then
stopEvent(events[aux].event)
else
ret = ret+1
end
end
events = nil
return(ret)
end
function doNpcTalk(msgs,interval,pcid)
local e={}
local ret={}
interval = interval or 10000
for aux = 1, #msgs do
e[aux]={}
doCreatureSayWithDelay(getNpcCid(),msgs[aux],TALKTYPE_PRIVATE_NP,(aux-1)*interval,e[aux],pcid)
table.insert(ret,e[aux])
end
return ret
end
msgcontains = doMessageCheck
checkMsg = doMessageCheck
moveToPosition = selfMoveTo
moveToCreature = selfMoveToThing
selfMoveToCreature = selfMoveToThing
selfMoveToPosition = selfMoveTo
isPlayerPremiumCallback = isPremium
doPosRemoveItem = doRemoveItemIdFromPosition
doRemoveItemIdFromPos = doRemoveItemIdFromPosition
doNpcBuyItem = doPlayerRemoveItem
doNpcSetCreatureFocus = selfFocus
getNpcCid = getNpcId
lookAtFocus = setFocus
getDistanceTo = getNpcDistanceTo
getDistanceToCreature = getNpcDistanceTo
getNpcDistanceToCreature = getNpcDistanceTo