• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

StopEvent

Abutre

New Member
Joined
Jun 5, 2017
Messages
15
Reaction score
0
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:
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) 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 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())
 
addEvent function returns a number, which is its event id, you need to catch that event id in a variable, and then you can call stopEvent(event_id)
 
addEvent function returns a number, which is its event id, you need to catch that event id in a variable, and then you can call stopEvent(event_id)
There is something very strange, they kill the boss, even with shared, and only tells one of them, but the event of the other for too. Do you have any idea what that is?
 
There is something very strange, they kill the boss, even with shared, and only tells one of them, but the event of the other for too. Do you have any idea what that is?
please format your thread, this code inside quotes are horrible to read
stopEvent(countDown) -- this doesnt work, it expects event id, you're using a function, if you read my previous answer i told what you should do.
 
Like stated above, you need to assign it to a variable, so stopEvent knows which event it is stopping.
Here's a few examples.
yours
LUA:
addEvent(countDown, 1000, self.uid)
stopEvent(countDown)
with variable
LUA:
local countDown_event = addEvent(countDown, 1000, self.uid)
stopEvent(countDown_event)
with variable + global index
LUA:
 countDown_global_table = {}
local countDown_global_table[cid] = addEvent(countDown, 1000, self.uid)
stopEvent(countDown_global_table[cid])
I'm not a scripter either, but people tell me that using cid in this manner is dangerous in 1.0+
I use it like this in 0.3.7.. soo idk what changed to make it dangerous, but just figured I'd warn you.
 
Back
Top