amoxicilina
Member
- Joined
- Jun 25, 2010
- Messages
- 72
- Reaction score
- 10
Could someone convert this npc to canary?
I even tried but it gave me a lot of error and I decided to resort to the community, but I'll keep trying in case I sonsiga before the solution here I post it here
I even tried but it gave me a lot of error and I decided to resort to the community, but I'll keep trying in case I sonsiga before the solution here I post it here
XML:
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 creatureSayCallback(cid, type, msg)
if not npcHandler:isFocused(cid) then return false end
local player = Player(cid)
local msg = msg:lower()
------------------------------------------------------------------
if npcHandler.topic[cid] == 0 and (msgcontains(msg, "task") or msgcontains(msg, 'mission') or msgcontains(msg, 'tasks')) then
if getPlayerStorageValue(cid, Storage.TheShatteredIsles.TheErrand) <= 0 then
return npcHandler:say("Come back when you finish Raphael's tasks.", cid)
end
if player:getTask() then
local task = player:getTask()
if player:getStorageValue(task.storage) == task.amount then
player:taskReward(task.pointsTask, task.items, task.exp, task.storage, task_current)
player:getPosition():sendMagicEffect(67)
player:getPosition():sendMagicEffect(9)
npcHandler:say(" * Reward *\n[*] Experience[*]: "..task.exp..".\n[*] Task points [*]: "..task.pointsTask..".\n[*] Item [*]: "..getItemsFromTable(task.items)..".", cid) -- problema
npcHandler:releaseFocus(cid)
end
elseif player:getDailyTask() then
local task = player:getDailyTask()
if player:getStorageValue(task.storage) == task.amount then
player:taskReward(task.pointsTask, task.items, task.exp, task.storage, task_daily_current)
player:setStorageValue(task_daily_time, 1 * 60 * 60 * 24 + os.time())
npcHandler:say(" * Reward Daily*\n[*]Experience[*]: "..task.exp..".\n[*] task points [*]: "..task.pointsTask..".\n[*] Item[*]:"..getItemsFromTable(task.items)..".",cid) -- problema
player:getPosition():sendMagicEffect(50)
player:getPosition():sendMagicEffect(28)
npcHandler:releaseFocus(cid)
end
end
npcHandler:say("Very well, would you like to make a {task} or {daily} task? or would you like to {quit} a task you are doing?", cid)
npcHandler.topic[cid] = 1
------------------------------------------------------------------
elseif npcHandler.topic[cid] == 1 and msgcontains(msg, "task") then
if player:getStorageValue(task_delay) < os.time() then
if player:getStorageValue(task_current) <= 0 then
local text = "You can choose between tasks:"
for _, task in pairs(task_monsters) do
text = text .." {"..task.name.."},"
end
npcHandler:say(text.." tell me which one do you want to do?", cid)
npcHandler.topic[cid] = 2
else
npcHandler:say("You are already doing a task. You can only do one at a time. Say {!task} to view information about your current task. Or use {quit} to cancel the task.", cid)
npcHandler.topic[cid] = 0
end
else
npcHandler:say("You abandoned the previous task. Wait until the 2 hours of punishment is over. Time:", cid)
end
elseif npcHandler.topic[cid] == 2 then
for task_number, task in pairs(task_monsters) do
if msg == task.name then
npcHandler:say("Okay, now you're doing the homework {"..task.name:gsub("^%l", string.upper).."}, you need to kill "..task.amount .." their. Good luck!", cid)
player:setStorageValue(task_current, task_number)
player:setStorageValue(task.storage, 0)
npcHandler:releaseFocus(cid)
else
-- npcHandler:say("Sorry, we don't have this task.", cid)
end
end
------------------------------------------------------------------
elseif msgcontains(msg, "daily") then
if player:getStorageValue(task_daily_time) < os.time() then
if player:getStorageValue(task_delay) < os.time() then
if player:getStorageValue(task_daily_current) <= 0 then
local text = "You can choose between daily tasks:"
for _, task in pairs(task_daily) do
text = text .." {"..task.name.."},"
end
npcHandler:say(text.."tell me which one do you want to do?", cid)
npcHandler.topic[cid] = 3
else
npcHandler:say("You are already doing a daily task. You can only do one a day. Say {!Task} to view information about your current task. Or use {quit} to cancel the daily task.", cid)
end
else
npcHandler:say("I'm not allowed to assign tasks because you abandoned the previous task. Wait until the 2 hours of punishment is over.", cid)
end
else
npcHandler:say("You have completed today's daily task. Expect to spend 24 hours to do it again.", cid)
end
elseif npcHandler.topic[cid] == 3 then
for task_number, task in pairs(task_daily) do
if msg == task.name then
npcHandler:say("Okay, now you're doing the daily chore of {"..task.name:gsub("^%l", string.upper).."}, you need to kill "..task.amount.."their. Good luck! ",cid)
player:setStorageValue(task_daily_current, task_number)
player:setStorageValue(task.storage, 0)
npcHandler:releaseFocus(cid)
else
npcHandler:say("Sorry we don't have this daily task.", cid)
end
end
------------------------------------------------------------------
elseif msgcontains(msg, "quit") then
if npcHandler.topic[cid] == 0 then
npcHandler:say("What kind of task do you want to finish, {task} or{daily}?", cid)
npcHandler.topic[cid] = 4
end
elseif npcHandler.topic[cid] == 4 and msgcontains(msg, "task") then
if player:getTask() then
npcHandler:say("Unhappy with this situation, I had faith that you would bring me this mission done, but I was wrong. As a punishment, he had been unable to perform any task for 2 hours.", cid)
player:setStorageValue(task_delay, os.time() + task_time * 60 * 60)
player:setStorageValue(player:getTask().storage, 0)
player:setStorageValue(task_current, 0)
npcHandler:releaseFocus(cid)
else
npcHandler:say("You are not performing any task to be able to abandon it.", cid)
end
elseif npcHandler.topic[cid] == 4 and msgcontains(msg, "daily") then
if player:getDailyTask() then
npcHandler:say("Unfortunate for this situation, I had faith that you would bring me this mission done, but I was wrong. As punishment will be 2 hours without being able to perform any task.", cid)
player:setStorageValue(task_delay, os.time() + task_time * 60 * 60)
player:setStorageValue(player:getDailyTask().storage, 0)
player:setStorageValue(task_daily_current, 0)
npcHandler:releaseFocus(cid)
else
npcHandler:say("You are not doing any daily task to be able to abandon it.", cid)
end
end
end
npcHandler:setMessage(MESSAGE_GREET, "hi |PLAYERNAME|.")
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)npcHandler:setMessage(MESSAGE_FAREWELL, 'Happy hunting, old man!')
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())