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

Stop Event Help

darcioantonio

www.adventurerpg.com.br
Joined
Jul 30, 2013
Messages
165
Solutions
1
Reaction score
4
Location
Brasil
Twitch
darcio_
YouTube
UCEXCOEw_dYchojHNz
I have tis script tfs 0.4otx
Lua:
function onUse(cid, item, frompos, item2, topos)
    timeBoss(cid)
end

function timeBoss(cid)
    addEvent(function()
            teleportPlayersToSaida(getPlayersInArea(config.nortEsquerdaSalaBoss, config.sulDireitaSalaBoss))
    end, 10 * 1000)
end

How can I stop it using this script here in separate motion files
Lua:
function onStepIn(cid, item, frompos, item2, topos)

    doTeleportThing(cid, {x = 1139, y = 1809, z = 6})
end

I've tried everything and I can't stop it
 
Try this:
Lua:
TeleportPlayersToSaidaEventId= 0

function onUse(cid, item, frompos, item2, topos)
    TelportPlayersToSaidaEventId = addEvent(teleportPlayersToSaida, 10*1000, getPlayersInArea(config.nortEsquerdaSalaBoss, config.sulDireitaSalaBoss))
end

Lua:
function onStepIn(cid, item, frompos, item2, topos)
    stopEvent(TeleportPlayersToSaidaEventId)
end
 
Maybe you can use some sort of global table to keep track, I used to have this problem before and I solved it using global storage value:

Lua:
function onUse(cid, item, frompos, item2, topos)
    timeBoss()
end

function timeBoss()  
    setGlobalStorageValue(5000, addEvent(teleportPlayersToSaida, 10 * 1000, getPlayersInArea(config.nortEsquerdaSalaBoss, config.sulDireitaSalaBoss)))
end

-- idk what this function does
function teleportPlayersToSaida(someTable)
    if getGlobalStorageValue(5000) == -1 then
        return
    end
   
    -- Do what it is supposed to do
end


function onStepIn(cid, item, frompos, item2, topos)
    setGlobalStorageValue(5000, -1)
    doTeleportThing(cid, {x = 1139, y = 1809, z = 6})
end
 
Maybe you can use some sort of global table to keep track, I used to have this problem before and I solved it using global storage value:

Lua:
function onUse(cid, item, frompos, item2, topos)
    timeBoss()
end

function timeBoss()
    setGlobalStorageValue(5000, addEvent(teleportPlayersToSaida, 10 * 1000, getPlayersInArea(config.nortEsquerdaSalaBoss, config.sulDireitaSalaBoss)))
end

-- idk what this function does
function teleportPlayersToSaida(someTable)
    if getGlobalStorageValue(5000) == -1 then
        return
    end
 
    -- Do what it is supposed to do
end


function onStepIn(cid, item, frompos, item2, topos)
    setGlobalStorageValue(5000, -1)
    doTeleportThing(cid, {x = 1139, y = 1809, z = 6})
end
Neither of the 2 ways worked

Just needed a few more tweeks. You guys were almost there.
Probably need to reset the storage on serverStartUp as well.

Lua:
local function timeBoss()
    setGlobalStorageValue(5000, -1) -- reset storage when function is successfully called
    teleportPlayersToSaida(getPlayersInArea(config.nortEsquerdaSalaBoss, config.sulDireitaSalaBoss)
end

function onUse(cid, item, frompos, item2, topos)
    -- check for active event, and cancel
    if getGlobalStorageValue(5000) ~= -1 then
        stopEvent(getGlobalStorageValue(5000))
        setGlobalStorageValue(5000, -1)
    end
 
    local event = addEvent(timeBoss, 10 * 1000) -- create event
    setGlobalStorageValue(5000, event) -- store event
    return true
end
Lua:
function onStepIn(cid, item, frompos, item2, topos)
    -- check for active event, and cancel
    if getGlobalStorageValue(5000) ~= -1 then
        stopEvent(getGlobalStorageValue(5000))
        setGlobalStorageValue(5000, -1)
    end
 
    doTeleportThing(cid, {x = 1139, y = 1809, z = 6})
    return true
end
 
Nothing can't be shared among interfaces-environments in TFS 0.x
In other words; if you create an event inside the actions interface, you can only stop that event within an action script.

Global storages are allocated on memory, you don't need to restart them unless you save them onto database.
 
Nothing can't be shared among interfaces-environments in TFS 0.x
In other words; if you create an event inside the actions interface, you can only stop that event within an action script.

Global storages are allocated on memory, you don't need to restart them unless you save them onto database.
dangit lmao

Alright, I say we try this.

It's not perfect.. as there is 1 millisecond between the called events.. but.. best I can come up with.

Lua:
local storageKey = 5000

local function timeBoss()
    setGlobalStorageValue(storageKey, -1) -- reset storage when function is successfully called
    teleportPlayersToSaida(getPlayersInArea(config.nortEsquerdaSalaBoss, config.sulDireitaSalaBoss)
end

local function timedStopEvent(eventId)
    local storageValue = getGlobalStorageValue(storageKey)
    if storageValue ~= -1 and storageValue ~= eventId then
        stopEvent(storageValue)
        setGlobalStorageValue(storageKey, -1)
    end
end

function onUse(cid, item, frompos, item2, topos)   
    local eventTimer = 10 * 1000
    local event = addEvent(timeBoss, eventTimer) -- create event
    addEvent(timedStopEvent, eventTimer - 1, event)
    setGlobalStorageValue(storageKey, event) -- store event
    return true
end
Lua:
local storageKey = 5000

function onStepIn(cid, item, frompos, item2, topos)
    setGlobalStorageValue(storageKey, -1)
    doTeleportThing(cid, {x = 1139, y = 1809, z = 6})
    return true
end
 
Last edited:
I think we could use the ids only, the event will keep running but as long as the id doesn't match nothing should happen.

Lua:
local ARENA_UNACTIVE = 0
local ARENA_ACTIVE = 1

local gEvent = 50000
local gState = 50001
Lua:
local function timeBoss(eventId)

    local globalEventId = getStorage(gEvent)
    if globalEventId ~= eventId then
        return
    end

    doSetStorage(gState, ARENA_UNACTIVE)
    doSetStorage(gEvent, -1) -- reset storage when function is successfully called

    teleportPlayersToSaida(getPlayersInArea(config.nortEsquerdaSalaBoss, config.sulDireitaSalaBoss))
end

function onUse(cid, item, frompos, item2, topos)

    local arenaState = getStorage(gState)
    if arenaState == ARENA_ACTIVE then
        return doPlayerSendCancel(cid, "Sorry, not possible.")
    end

    local eventTimer = 10 * 1000
    local eventId = math.random(1000000)
    addEvent(timeBoss, eventTimer, eventId) -- create event

    doSetStorage(gState, ARENA_ACTIVE)
    setGlobalStorageValue(gEvent, eventId) -- store event

    return true
end
Lua:
function onStepIn(cid, item, frompos, item2, topos)

    doSetStorage(gState, ARENA_UNACTIVE)
    doSetStorage(gEvent, -1)

    return doTeleportThing(cid, ...)
end
 
I think we could use the ids only, the event will keep running but as long as the id doesn't match nothing should happen.

Lua:
local ARENA_UNACTIVE = 0
local ARENA_ACTIVE = 1

local gEvent = 50000
local gState = 50001
Lua:
local function timeBoss(eventId)

    local globalEventId = getStorage(gEvent)
    if globalEventId ~= eventId then
        return
    end

    doSetStorage(gState, ARENA_UNACTIVE)
    doSetStorage(gEvent, -1) -- reset storage when function is successfully called

    teleportPlayersToSaida(getPlayersInArea(config.nortEsquerdaSalaBoss, config.sulDireitaSalaBoss))
end

function onUse(cid, item, frompos, item2, topos)

    local arenaState = getStorage(gState)
    if arenaState == ARENA_ACTIVE then
        return doPlayerSendCancel(cid, "Sorry, not possible.")
    end

    local eventTimer = 10 * 1000
    local eventId = math.random(1000000)
    addEvent(timeBoss, eventTimer, eventId) -- create event

    doSetStorage(gState, ARENA_ACTIVE)
    setGlobalStorageValue(gEvent, eventId) -- store event

    return true
end
Lua:
function onStepIn(cid, item, frompos, item2, topos)

    doSetStorage(gState, ARENA_UNACTIVE)
    doSetStorage(gEvent, -1)

    return doTeleportThing(cid, ...)
end

Ahhhhh I'm so stupid. xD

I remember doing this as well.. cuz I couldn't stand trying to use stopEvent. xD
 
Back
Top