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

Solved Why stopEvent not working here

LuisPro

World War <3
Joined
May 10, 2009
Messages
425
Solutions
1
Reaction score
53
My training script to learn about addEvent/stopEvent:

Code:
-- Annihilator by Shawak v2.1
-- Modified by Nottinghster

        -- CONFIG --
       
        local playersOnly = "yes"
        local questLevel = 100

        local room = {     -- arena
        fromX = 112,
        fromY = 83,
        fromZ = 7,
        --------------
        toX = 116,
        toY = 87,
        toZ = 7,
        }

        local monster_pos = {
        [1] = {pos = {77, 100, 12}, monster = "Demon"},
        [2] = {pos = {79, 100, 12}, monster = "Demon"},
        [3] = {pos = {78, 104, 12}, monster = "Demon"},
        [4] = {pos = {80, 104, 12}, monster = "Demon"},
        [5] = {pos = {81, 102, 12}, monster = "Demon"},
        [6] = {pos = {82, 102, 12}, monster = "Demon"}
        }

        local players_pos = {
        {x = 111, y =85, z = 7, stackpos = 253},
        {x = 117, y =85, z = 7, stackpos = 253},
        --{x = 82, y =114, z = 12, stackpos = 253},
        --{x = 83, y =114, z = 12, stackpos = 253}
        }

        local new_player_pos = {
        {x = 113, y = 85, z = 7},
        {x = 115, y = 85, z = 7},
        --{x = 79, y = 102, z = 12},
        --{x = 80, y = 102, z = 12}
        }

        ------------------------------------------------------
        --- CONFIG END ---------------------------------------
        ------------------------------------------------------

local t = {
a = {x=112, y=83, z=7}, -- top left corner
b = {x=116, y=87, z=7}, -- bottom right corner
c = {x=120, y=90, z=6} -- where to teleport
}

function tp()
    for x = room.fromX, room.toX do
        for y = room.fromY, room.toY do
            for z = room.fromZ, room.toZ do
                local pos = {x=x, y=y, z=z,stackpos = 253}
                local players = getThingfromPos(pos)
                if players.uid > 0 then
                    doTeleportThing(players.uid, t.c)
                end
            end
        end
    end
    return true
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local all_ready, monsters, player, level = 0, 0, {}, 0
    if item.uid == 7001 then
        if item.itemid == 1946 then
                for i = 1, #players_pos do
                        table.insert(player, 0)
                end
                for i = 1, #players_pos do
                        player[i] = getThingfromPos(players_pos[i])
                        if player[i].itemid > 0 then
                                if string.lower(playersOnly) == "yes" then
                                        if isPlayer(player[i].uid) == true then
                                                all_ready = all_ready+1
                                        else
                                                monsters = monsters+1
                                        end
                                else
                                        all_ready = all_ready+1
                                end
                        end
                end
                if all_ready == #players_pos then
                        for i = 1, #players_pos do
                                player[i] = getThingfromPos(players_pos[i])
                                if isPlayer(player[i].uid) == true then
                                        if getPlayerLevel(player[i].uid) >= questLevel then
                                                level = level+1
                                        end
                                else
                                        level = level+1
                                end
                        end
                        if level == #players_pos then
                                if string.lower(playersOnly) == "yes" and monsters == 0 or string.lower(playersOnly) == "no" then
                                        --for _, area in pairs(monster_pos) do
                                        --                doSummonCreature(area.monster,{x=area.pos[1],y=area.pos[2],z=area.pos[3]})
                                        --end
                                        for i = 1, #players_pos do
                                            doSendMagicEffect(players_pos[i], CONST_ME_POFF)
                                            doTeleportThing(player[i].uid, new_player_pos[i])
                                            doSendMagicEffect(new_player_pos[i], CONST_ME_ENERGYAREA)
                                            doTransformItem(item.uid,1945)
                                            --addEvent(tp, 15000)
                                            local event = addEvent(tp, 15000)
                                        end
                                else
                                        doPlayerSendTextMessage(cid,19,"Only players can enter.")
                                end
                        else
                                doPlayerSendTextMessage(cid,19,"All Players have to be level "..questLevel.." to do this quest.")
                        end
                else
                        doPlayerSendCancel(cid,"You need players.")
                end
        elseif item.itemid == 1945 then
                local player_room = 0
                for x = room.fromX, room.toX do
                        for y = room.fromY, room.toY do
                                for z = room.fromZ, room.toZ do
                                        local pos = {x=x, y=y, z=z,stackpos = 253}
                                        local thing = getThingfromPos(pos)
                                        if thing.itemid > 0 then
                                                if isPlayer(thing.uid) == true then
                                                        player_room = player_room+1
                                                end
                                        end
                                end
                        end
                end
                if player_room >= 1 then
                        doPlayerSendTextMessage(cid,19,"Wait for your turn.")         
                elseif player_room == 0 then
                        for x = room.fromX, room.toX do
                                for y = room.fromY, room.toY do
                                        for z = room.fromZ, room.toZ do
                                                local pos = {x=x, y=y, z=z,stackpos = 253}
                                                local thing = getThingfromPos(pos)
                                                if thing.itemid > 0 then
                                                        doRemoveCreature(thing.uid)
                                                end
                                        end
                                end
                        end
                        doTransformItem(item.uid,1946)
                        stopEvent(event)
                end
        end
    end   
        return true
end
 
event = nil on the very last lines.
Because the only place you are giving event a value. You are giving it a local value.
 
if i change
local event = addEvent(tp, 15000)
to
event = addEvent(tp, 15000)
also stopEvent not working
 
local Event = {}
Event[1] = addEvent(tp, 15000)
stopEvent(Event[1])
local add on the bottom of other locals
Event[1] = addEvent(tp, 15000) change for local event = addEvent(tp, 15000)
and stopEvent(Event[1]) for stopEvent(event)
yes? i do that and still the same
 
if i change
local event = addEvent(tp, 15000)
to
event = addEvent(tp, 15000)
also stopEvent not working
it doesn't work like that. because you looping trough the event.
so you constantly changing the event value.

i might fail here but if i'm correct, addEvent() function registrates an unique action as a number. (1,2,3,4, etc)
and you stop them by giving the registration number. example stopEvent(4)

What you are doing is this:
for i = 1, 2 do event = addEvent() end

meaning that event = 1 at first
and then event = 2

if you run addEvent anywhere else in your server. then the next value would be 3.

so stopping the event(2) would not stop the event(1)

if you understood what I was getting at xD

In other words. You are not stopping as many events as you are making.
 
it doesn't work like that. because you looping trough the event.
so you constantly changing the event value.

i might fail here but if i'm correct, addEvent() function registrates an unique action as a number. (1,2,3,4, etc)
and you stop them by giving the registration number. example stopEvent(4)

What you are doing is this:
for i = 1, 2 do event = addEvent() end

meaning that event = 1 at first
and then event = 2

if you run addEvent anywhere else in your server. then the next value would be 3.

so stopping the event(2) would not stop the event(1)

if you understood what I was getting at xD

In other words. You are not stopping as many events as you are making.

yeah i get it, i loop event with the same eventid
hmmmmm
stopEvent(event)
stopEvent(event)
are not do the job xd hmmm

oh! let put add event out of loop !
hmm looks like it works!
let me test it :)
 
Back
Top