How i can make to the player kill one monster and the act to kill stop one event? In the case, the event name is countDown. I already used storages, but don't make.
The function countDown:
and, my NPC, is:
The NPC works the way I want it (yes it's big, I'm not a scripter, rs) but the question of stopping the event I can not.
The function countDown:
function countDown(uid)
local self = Player(uid)
if self:getStorageValue(config.stgTempo) > 0 and self:getStorageValue(config.stgAux) == 0 then
self:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Tempo: " .. self:getStorageValue(config.stgTempo))
self:setStorageValue(config.stgTempo, (self:getStorageValue(config.stgTempo) - 1))
addEvent(countDown, 1000, self.uid)
else
if self:getStorageValue(config.stgConff) < 1 then
self:teleportTo(config.posSaida)
local vida = Player(uid):getMaxHealth()
self:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Seu tempo acabou.")
removerDemeter(CONFIG_BOSS.FROMPOS, CONFIG_BOSS.TOPOS)
self:addHealth(-vida)
end
end
end
and, my NPC, is:
The NPC works the way I want it (yes it's big, I'm not a scripter, rs) but the question of stopping the event I can not.
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
function onCreatureAppear(cid) npcHandlernCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandlernCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandlernCreatureSay(cid, type, msg) end
function onThink() npcHandlernThink() end
local CONFIG_BOSS =
{
FROMPOS = {x = 1220, y = 1277, z = 7},
TOPOS = {x = 1236, y = 1291, z = 7},
}
function removerDemeter()
local positionsCheck = {}
for i = CONFIG_BOSS.FROMPOS.x, CONFIG_BOSS.TOPOS.x do
positionsCheck[#positionsCheck+1] = {x=i, y = CONFIG_BOSS.FROMPOS.y, z = CONFIG_BOSS.FROMPOS.z, stackpos = 0}
for j = CONFIG_BOSS.FROMPOS.y+1, CONFIG_BOSS.TOPOS.y do
positionsCheck[#positionsCheck+1] = {x=i, y = j, z = CONFIG_BOSS.FROMPOS.z, stackpos = 0}
end
end
for j=1, #positionsCheck do
for i = 0, 255 do
positionsCheck[j].stackpos = i
local tile = getTileThingByPos(positionsCheck[j])
if isMonster(tile.uid) then
doRemoveCreature(tile.uid)
end
end
end
end
local fromToPos = {{x = 1220, y = 1277, z = 7},{x = 1236, y = 1291, z = 7}}
function sortPosition(pos)
local position =
{
x = math.random(pos[1].x, pos[2].x),
y = math.random(pos[1].y, pos[2].y),
z = 7
}
return position
end
local config =
{
pos =
{
[1] = Position(1168,1252,7),
[2] = Position(1172,1252,7),
--[3] = Position(1168,1254,7),
--[4] = Position(1172,1254,7),
--[5] = Position(1170,1256,7),
},
posEntrada = {{x = 1219, y = 1278, z = 7}, {x = 1237, y = 1287, z = 7}, {x = 1221, y = 1288, z = 7}, {x = 1236, y = 1274, z = 7}, {x = 1228, y = 1282, z = 7}},
stgTempo = 45780,
stgMission = 45781,
stgAux = 45782,
stgConff = 45889,
posSaida = Position(1168,1251,7),
segTempo = 30,
stg2 = 66633,
posBoss = Position(1228,1283,7)
}
local player = Player(cid)
function countDown(uid)
local self = Player(uid)
if self:getStorageValue(config.stgTempo) > 0 and self:getStorageValue(config.stgAux) == 0 then
self:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Tempo: " .. self:getStorageValue(config.stgTempo))
self:setStorageValue(config.stgTempo, (self:getStorageValue(config.stgTempo) - 1))
addEvent(countDown, 1000, self.uid)
else
if self:getStorageValue(config.stgConff) < 1 then
self:teleportTo(config.posSaida)
local vida = Player(uid):getMaxHealth()
self:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Seu tempo acabou.")
removerDemeter(CONFIG_BOSS.FROMPOS, CONFIG_BOSS.TOPOS)
self:addHealth(-vida)
end
end
end
function checaDESGRACA(uid)
local self = Player(uid)
if self:getStorageValue(config.stgConff) == 0 and self:getStorageValue(config.stgConff) >= 1 then
self:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Matou o boss.")
self:setStorageValue(config.stgConff, 1)
stopEvent(countDown)
end
addEvent(checaDESGRACA, 3 * 1000, self.uid)
end
local function creatureSayCallback(cid, type, msg)
if not npcHandler:isFocused(cid) then
return false
end
if msgcontains(msg, "desafio") and npcHandler.topic[cid] == 0 then
--if player:getStorageValue(LABIRINTO.STORAGE_MISSION) <= 0 then
npcHandler:say("Vejo que é bem corajoso! Para este desafio você tem 90 segundos para tentar passar pela criatura que guarda uma sala. Se dentro destes 90 segundos você e seus amigos não conseguirem destruir a criatura, vocês pagarão com à vida! Você que arriscar? Lembrando: além de você é necessário mais quatro jogadores!", cid)
npcHandler.topic[cid] = 1
--else
--npcHandler:say("Você já teve sua chance.", cid)
--npcHandler.topic[cid] = 0
--end
elseif msgcontains(msg, "sim") and npcHandler.topic[cid] == 1 then
local storePlayers, jogadores = {}
for i = 1, #config.pos do
local jogadores = Tile(config.pos):getTopCreature()
if not jogadores or not jogadores:isPlayer() then
npcHandler:say("Você precisa de 4 jogadores para tentarem concluir este desafio!", cid)
npcHandler.topic[cid] = 0
return true
end
storePlayers[#storePlayers + 1] = jogadores
end
local players
for i = 1, #storePlayers do
local players = storePlayers
local PlayerConf = players:getPlayer()
config.pos:sendMagicEffect(CONST_ME_POFF)
players:setDirection(DIRECTION_EAST)
players:teleportTo(sortPosition(fromToPos))
players:setStorageValue(config.stgMission, 1)
players:setStorageValue(config.stgTempo, config.segTempo)
players:setStorageValue(config.stgAux, 0)
players:setStorageValue(config.stgConff, 1)
addEvent(checaDESGRACA, 1000, PlayerConf.uid)
PlayerConf:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "O seu desafio começou! Você possuí "..PlayerConf:getStorageValue(config.stgTempo).." segundos para tentar concluir. Seja rápido!")
addEvent(countDown, 1000, PlayerConf.uid)
npcHandler.topic[cid] = 0
end
Game.createMonster("Demeter", config.posBoss)
--elseif msgcontains(msg, "reportar") and player:getStorageValue(LABIRINTO.STORAGE_MISSION) == 2 then
--npcHandler:say("Parabéns, você conseguiu, leve mais " .. math.ceil(LABIRINTO.PRIZE_FINISH / 1000) .. "k com você!", cid)
--creature:addMoney(LABIRINTO.PRIZE_FINISH)
--player:setStorageValue(LABIRINTO.STORAGE_MISSION, 3)
--npcHandler.topic[cid] = 0
end
return true
end
npcHandler:setCallback(CALLBACK_ONADDFOCUS, onAddFocus)
npcHandler:setCallback(CALLBACK_ONRELEASEFOCUS, onReleaseFocus)
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())