test
local config = {
monsters = {
-- ["Name"] = {amount = quantidade}
["Demon"] = {amount = 30},
["Hydra"] = {amount = 10},
},
storage = 54661, -- Não mexer se não souber editar
money = 100 -- Dinheiro
}
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end
local function releasePlayer(cid)
if not Player(cid) then
return
end
npcHandler:releaseFocus(cid)
npcHandler:resetNpc(cid)
end
local function creatureSayCallback(cid, type, msg)
if not npcHandler:isFocused(cid) then
return false
end
local player = Player(cid)
if msgcontains(msg, "mission") then
if player:getStorageValue(config.storage) < 1 then
selfSay("A missão para promovido custa " .. config.money .. " você aceita fazer ?", cid)
npcHandler.topic[cid] = 1
elseif player:getStorageValue(config.storage) == (2 + #config.monsters) then
selfSay("Você já cumpriu a missão peça pra ser {promovido}.", cid)
npcHandler.topic[cid] = 2
elseif player:getStorageValue(config.storage) == (3 + #config.monsters) then
selfSay("Voce já terminou as missões, pode ir em embora!", cid)
releasePlayer(cid)
end
elseif msgcontains(msg, "yes") and npcHandler.topic[cid] == 1 then
if player:removeMoney(config.money) then
local text = ""
for monsters, v in pairs(config.monsters) do
text = text .. ", "
text = text .. v.amount .. " {" .. monsters .. "}"
end
npcHandler:say("A missão é matar esses monstros para mim" .. text .. ".", cid)
for i, _ in pairs(config.monsters) do
player:setStorageValue(i, 0)
end
player:setStorageValue(config.storage, 1)
else
selfSay("Você não tem money suficiente!", cid)
end
npcHandler.topic[cid] = 0
elseif msgcontains(msg, "no") and npcHandler.topic[cid] == 2 then
selfSay("Até logo!", cid)
npcHandler.topic[cid] = 0
end
if msgcontains(msg, "lista") and player:getStorageValue(config.storage) < (#config.monsters + 3) then
local text, n = "", 0
for monsters, v in pairs(config.monsters) do
local sto = player:getStorageValue(monsters)
if sto < v.amount then
n = n + 1
text = text .. ", "
text = text .. (tostring(sto) < tostring(1) and v.amount or (tostring(v.amount) - tostring(sto))) .. " {" .. monsters .. "}"
end
end
elseif msgcontains(msg, "promovido") and npcHandler.topic[cid] == 2 then
selfSay("Aqui está sua promoção jovem soldado!!", cid)
player:setVocation(player:getVocation() + 4)
player:setStorageValue(config.storage, (#config.monsters + 3))
for monsters, _ in pairs(config.monsters) do
player:setStorageValue(monsters, -1)
end
npcHandler.topic[cid] = 0
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())