• 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!

addEvent() Cancel If

anotapreta

New Member
Joined
Mar 12, 2010
Messages
104
Reaction score
0
How to cancel a addEvent () even before it happens.
Records the event:

Lua:
local perder = addEvent(teleportPlayer, 2*60*1000,cid)
if a = b then
event happens
evento acontece
else
event cancels
evento cancela
end

stopEvent(perder) not work for this!!
i need cancelEvent(perder) function:D
 
Last edited:
stopEvent(EventName): funciona para o evento não acontecer de novo, só que eu não quero que ele não aconteça nenhuma vez
stopEvent(EventName): works for the event will not happen again, but I do not want it does not happen any time
Lua:
local perder = addEvent(teleportPlayer, 2*60*1000,cid)
if a = b then
event happens
evento acontece
else
stopEvent(perder) -- not good, because event work one time and only after stop
cancelEvent(perder) -- i need this
event cancels
evento cancela
end
 
I know how to have the event happen and I know how to stop. The problem is what I say happens after a while, and I do a check if a == b then happens if a ~= b = cancel the addEvent without happening once. That is, when I want to cancel this with addEvent already waiting to happen. A cancelEvent function that I need. Giving a stopEvent it will happen once and then it will stop, but I do not want to happen.


If the player takes too long to play, I want him to lose and teleportation.

original
Lua:
CurrentSteps = {}
CurrentSequence = {}

PuzzleGeniusConfig = {
                centerPlayerPos = {x=988,y=985,z=7},
                effectsid = {
                                [9562] = {1, 0},
                                [9563] = {0, 1},
                                [9564] = {-1, 0},
                                [9565] = {0, -1}
                },

                appearInterval = 1,
                disapear = 0.6,
                backPos = {x=987,y=982,z=7},

                rewardPos = {x=995,y=988,z=6},
                roundTimes = 100,

}
CurrentSequence = {}

PuzzleGenius = {}


function randomIndexFromTable(tab)
                local tb = {}
                for i,x in pairs(tab) do
                                table.insert(tb, i)
                end
                return tb[math.random(1, #tb)]
end

function tileEffect(tileid, pos, int)
local tile = getThingFromPos({x=pos.x, y=pos.y, z=pos.z, stackpos=0})
doItemSetAttribute(tile.uid, "aid", 6661)
        local a = doCreateItem(tileid, pos)
        addEvent(function() local tile = getThingFromPos({x=pos.x, y=pos.y, z=pos.z, stackpos=1}).uid doRemoveItem(tile, 1) end, int*1000)
end

function PuzzleGenius:ExecuteSequence(cid)
                if #CurrentSequence >= PuzzleGeniusConfig.roundTimes then
                                doTeleportThing(cid, PuzzleGeniusConfig.rewardPos)
                                doPlayerSetNoMove(cid, false)
                                CurrentSteps = {}
                                CurrentSequence = {}
                                return true
                end
                table.insert(CurrentSequence, randomIndexFromTable(PuzzleGeniusConfig.effectsid))
                for i,x in ipairs(CurrentSequence) do
                                addEvent(tileEffect, PuzzleGeniusConfig.appearInterval*i*1000, x, {x=PuzzleGeniusConfig.centerPlayerPos.x+PuzzleGeniusConfig.effectsid[x][1], y=PuzzleGeniusConfig.centerPlayerPos.y+PuzzleGeniusConfig.effectsid[x][2], z=PuzzleGeniusConfig.centerPlayerPos.z},PuzzleGeniusConfig.disapear)
                end
                addEvent(doPlayerSetNoMove, (PuzzleGeniusConfig.appearInterval*#CurrentSequence+PuzzleGeniusConfig.disapear)*1000, cid, false)
end

function PuzzleGenius:Check(cid, currentSteps)
                if currentSteps[#currentSteps] == CurrentSequence[#currentSteps] then
                                return true
                end
                return false
end

function onStepIn(cid, item, pos, fromPos)
        if pos.x == PuzzleGeniusConfig.centerPlayerPos.x and pos.y == PuzzleGeniusConfig.centerPlayerPos.y then
                 if #CurrentSequence < 1 then
                         doPlayerSetNoMove(cid, true)
                         return PuzzleGenius:ExecuteSequence(cid)
                 else
                         return false
                 end
        end

        local coordinates = {pos.x-fromPos.x, pos.y-fromPos.y}
        for i,x in pairs(PuzzleGeniusConfig.effectsid) do
                if x[1] == coordinates[1] and x[2] == coordinates[2] then
                        table.insert(CurrentSteps, i)
                        if PuzzleGenius:Check(cid, CurrentSteps) then
                                doCreateItem(i, {x=PuzzleGeniusConfig.centerPlayerPos.x+coordinates[1], y=PuzzleGeniusConfig.centerPlayerPos.y+coordinates[2], z=PuzzleGeniusConfig.centerPlayerPos.z})
                        end
                end
        end
        if PuzzleGenius:Check(cid, CurrentSteps) then
                doTeleportThing(cid, fromPos, true)
                if #CurrentSteps == #CurrentSequence then
                        doPlayerSetNoMove(cid, true)
                        CurrentSteps = {}
                        addEvent(function() PuzzleGenius:ExecuteSequence(cid) end, 500)
                end
        else
                doTeleportThing(cid, PuzzleGeniusConfig.backPos)
                CurrentSteps = {}
                CurrentSequence = {}
        end
        return TRUE
end

function onStepOut(cid, item, pos, fromPos)
        local tile = getThingFromPos({x=pos.x, y=pos.y, z=pos.z, stackpos=1})
        for i,x in pairs(PuzzleGeniusConfig.effectsid) do
                if i == tile.itemid then
                        addEvent(function() local tilee = getThingFromPos({x=pos.x, y=pos.y, z=pos.z, stackpos=1}).uid doRemoveItem(tilee, 1) end, 100)
                        break
                end
        end
        return TRUE
end


This is mine but the player teleporting all time! if win or if lose
Lua:
CurrentSteps = {}
CurrentSequence = {}

Config = {
                centerPlayerPos = {x=10096,y=10121,z=7},
                teleportpos = {x=10096, y=10124, z=7, stackpos=1}, -- tel pos
                effectsid = {
                                [9562] = {1, 0},
                                [9563] = {0, 1},
                                [9564] = {-1, 0},
                                [9565] = {0, -1}
                },

                appearInterval = 1,
                disapear = 0.6,
                losetime = 1, -- <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< -- here TIME FOR LOSE (player, play fast or lose)
                rewardPos = {x=10098,y=10119,z=7},

                backPos = {x=10094,y=10119,z=7},
                roundTimes = 8,

}
CurrentSequence = {}

PuzzleGenius = {}


function randomIndexFromTable(tab)
                local tb = {}
                for i,x in pairs(tab) do
                                table.insert(tb, i)
                end
                return tb[math.random(1, #tb)]
end


function teleportPlayer(cid, item, pos, fromPos)
doTeleportThing(cid, Config.backPos)
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Genius System: You lose! Need be fast!")
doCreateTeleport(1387, Config.centerPlayerPos, Config.teleportpos)
stopEvent(remove)
stopEvent(perder)
                CurrentSteps = {}
                CurrentSequence = {}
end
function doRemoveTel(teleportpos)
doRemoveItem(getThingFromPos(Config.teleportpos).uid, 1)
stopEvent(remove)
stopEvent(perder)
end



function tileEffect(tileid, pos, int)
local tile = getThingFromPos({x=pos.x, y=pos.y, z=pos.z, stackpos=0})
doItemSetAttribute(tile.uid, "aid", 6661)
        local a = doCreateItem(tileid, pos)
        addEvent(function() local tile = getThingFromPos({x=pos.x, y=pos.y, z=pos.z, stackpos=1}).uid doRemoveItem(tile, 1) end, int*1000)
end



function PuzzleGenius:ExecuteSequence(cid)

                if #CurrentSequence >= Config.roundTimes then
                                doTeleportThing(cid, Config.rewardPos)
                                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Genius System: You Win!")
doCreateTeleport(1387, Config.centerPlayerPos, Config.teleportpos)
stopEvent(remove)
stopEvent(perder)
                                doPlayerSetNoMove(cid, false)
                                CurrentSteps = {}
                                CurrentSequence = {}

                                return true
                end
                table.insert(CurrentSequence, randomIndexFromTable(Config.effectsid))
                for i,x in ipairs(CurrentSequence) do
                                addEvent(tileEffect, Config.appearInterval*i*1000, x, {x=Config.centerPlayerPos.x+Config.effectsid[x][1], y=Config.centerPlayerPos.y+Config.effectsid[x][2], z=Config.centerPlayerPos.z},Config.disapear)
                end
                addEvent(doPlayerSetNoMove, (Config.appearInterval*#CurrentSequence+Config.disapear)*1000, cid, false)
end

function PuzzleGenius:Check(cid, currentSteps)
                if currentSteps[#currentSteps] == CurrentSequence[#currentSteps] then
                                return true
                end
                return false
end


function onStepIn(cid, item, pos, fromPos)
        if pos.x == Config.centerPlayerPos.x and pos.y == Config.centerPlayerPos.y then
                 if #CurrentSequence < 1 then

stopEvent(remove)
stopEvent(perder)
local remove = addEvent(doRemoveTel, 1, Config.teleportpos)
local perder = addEvent(teleportPlayer, Config.losetime*60*1000,cid)




                         doPlayerSetNoMove(cid, true)
                         return PuzzleGenius:ExecuteSequence(cid)
                 else
                         return false
                 end
        end

        local coordinates = {pos.x-fromPos.x, pos.y-fromPos.y}
        for i,x in pairs(Config.effectsid) do
                if x[1] == coordinates[1] and x[2] == coordinates[2] then
                        table.insert(CurrentSteps, i)
                        if PuzzleGenius:Check(cid, CurrentSteps) then
                                doCreateItem(i, {x=Config.centerPlayerPos.x+coordinates[1], y=Config.centerPlayerPos.y+coordinates[2], z=Config.centerPlayerPos.z})
                        end
                end
        end
        if PuzzleGenius:Check(cid, CurrentSteps) then
                doTeleportThing(cid, fromPos, true)
                if #CurrentSteps == #CurrentSequence then
                        doPlayerSetNoMove(cid, true)
                        CurrentSteps = {}
                        addEvent(function() PuzzleGenius:ExecuteSequence(cid) end, 500)

                end
        else
                doTeleportThing(cid, Config.backPos)
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Genius System: You lose!")
doCreateTeleport(1387, Config.centerPlayerPos, Config.teleportpos)
stopEvent(remove)
stopEvent(perder)
                CurrentSteps = {}
                CurrentSequence = {}

        end
        return TRUE
end



function onStepOut(cid, item, pos, fromPos)
        local tile = getThingFromPos({x=pos.x, y=pos.y, z=pos.z, stackpos=1})
        for i,x in pairs(Config.effectsid) do
                if i == tile.itemid then
                        addEvent(function() local tilee = getThingFromPos({x=pos.x, y=pos.y, z=pos.z, stackpos=1}).uid doRemoveItem(tilee, 1) end, 100)
                        break
                end
        end
        return TRUE
end
 
Last edited:
Back
Top