Started to create a npc and now tried it out, somehow when i answer correct (aka 22) the npc won't stop the addEvent, I printed the stopEvent and it said failed, but why?
TFS 1.4+
TFS 1.4+
LUA:
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
function greet(cid, type, msg)
local player = Player(cid)
local qStorage = 89001
local answerWrongStorage = 89002
if (not npcHandler:isFocused(cid)) then return false end
if Game.getStorageValue(qStorage) == nil then
Game.setStorageValue(qStorage, 0)
end
if Game.getStorageValue(answerWrongStorage) == nil then
Game.setStorageValue(answerWrongStorage, 0)
end
firstEvent = {}
local function firstSpawn(player)
npcHandler:say("Suprise it was! Tell me {ready} when you killed the monsters, so we can continue.",cid)
Game.setStorageValue(qStorage, 2)
Game.createMonster("werebadger", {x = 1511, y = 1122, z = 7})
Game.createMonster("werebadger", {x = 1509, y = 1125, z = 7})
return true
end
if msgcontains(msg, "ready") and Game.getStorageValue(qStorage) < 1 then
npcHandler:say("I will ask you 5 questions, you have 10 seconds to answer each question. If you don't answer or answer faulty.. you're up for a suprise!",cid)
addEvent(function()
Game.setStorageValue(answerWrongStorage, 1)
npcHandler:say("First question! 3 + 19 = ",cid)
Game.setStorageValue(qStorage, 1)
end, 6000)
firstEvent[player:getId()] = addEvent(firstSpawn, 16000, player:getId())
end
if msgcontains(msg, "22") and Game.getStorageValue(qStorage) == 1 then --succeeded question 1
stopEvent(firstEvent[player:getId()])
firstEvent[player:getId()] = nil
npcHandler:say("Well done, maybe a bit too easy right?!",cid)
addEvent(function()
npcHandler:say("Second question! Whats the full name of the daily quest npc?",cid)
Game.setStorageValue(answerWrongStorage, 1)
Game.setStorageValue(qStorage, 2)
end, 3500)
local secondEvent = addEvent(function()
npcHandler:say("Suprise here we gooo! Tell me {ready} when you killed the monsters, so we can continue.",cid)
Game.setStorageValue(qStorage, 3)
Game.createMonster("werebadger", {x = 1511, y = 1122, z = 7})
Game.createMonster("werebadger", {x = 1509, y = 1125, z = 7})
Game.createMonster("werebadger", {x = 1511, y = 1127, z = 7})
Game.createMonster("werebadger", {x = 1515, y = 1126, z = 7})
end, 13500)
elseif not msgcontains(msg, "22") and Game.getStorageValue(qStorage) == 1 and Game.getStorageValue(answerWrongStorage) == 1 then
stopEvent(firstEvent)
npcHandler:say("Suprise it was! Tell me {ready} when you killed the monsters, so we can continue.",cid)
Game.setStorageValue(qStorage, 2)
Game.createMonster("werebadger", {x = 1511, y = 1122, z = 7})
Game.createMonster("werebadger", {x = 1509, y = 1125, z = 7})
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, greet)
npcHandler:addModule(FocusModule:new())