• 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 stopEvent TFS 0.4 is not working.

elnelson

Lunaria World Dev
Joined
Jun 20, 2009
Messages
579
Solutions
2
Reaction score
58
Location
México
Hey bois, im trying to stop this event with stopEvent(countDown), i want to remove a time counter from certain position when no players are around but, the event stop even if there are players on the area and the counter continues x.x
Lua:
local function countDown(number, pos, effect, msgonend, effectonend)
local n = number
for i = 1, number do
addEvent(doSendAnimatedText,i*1000, pos, n > 1 and n.."" or msgonend .."", n < 10 and TEXTCOLOR_RED or TEXTCOLOR_TEAL)
n = n -1
end
n = number
return true
end

(...) continue to next part

this is the script
Lua:
(...)
            local spec = getSpectators(pos, 15, 15)
            if spec ~= nil then
              for _, s in pairs(spec) do
                   if not isPlayer(s) then
                       doRemoveCreature(s)
                       stopEvent(countDown)
                       doPlayerSendCancel(cid,"Boss fight failed.")
  
                   end
              end
            end
            end, 5000)
(...)
 
Solution
Niiiiiiiiiiceee!! you're the best Xikini :D! ty very much.

im very interested to know where was my error, i know you already texted it above, but want to know what have you done here (if is not annoy for you)

Lua:
local function countDown(number, pos, effect, msgonend, effectonend)
    local count = 0 -- Why 0?, whats the function of give a constant of = 0, is it the same function as not constant¿?
    local spec = getSpectators({x = 693, y = 621, z = 11}, 13, 13)
    if spec ~= nil then
        for _, pid in pairs(spec) do
            if isPlayer(pid) then
                count = 1
                break
            end
        end
    end
    if count > 0 then -- you used it here, and as i see if the counter is > 0 then it will...
Basically in order to stop an ongoing event you need the eventId, you can store it in a table or variable.
For example:
Lua:
-- Variable that will store the eventId.
local eventId = nil
-- Triggering the event and storing the id.
eventId = addEvent(countDown, 1000, param, param, param, param, param)
-- Stopping the event
if eventId ~= nil then
stopEvent(eventId)
end

Missread the post you, try this:
Lua:
local spec = getSpectators(pos, 15, 15)
if spec ~= nil then
local players = 0

 for _, s in pairs(spec) do

    if isPlayer(s) then
       players = players + 1

       doRemoveCreature(s)
       if players > 0 then

        stopEvent(countDown)
       end 

      doPlayerSendCancel(cid,"Boss fight failed.")

    end

  end

end
end, 5000)
 
Last edited:
Basically in order to stop an ongoing event you need the eventId, you can store it in a table or variable.
For example:
Lua:
-- Variable that will store the eventId.
local eventId = nil
-- Triggering the event and storing the id.
eventId = addEvent(countDown, 1000, param, param, param, param, param)
-- Stopping the event
if eventId ~= nil then
stopEvent(eventId)
end

Missread the post you, try this

well, to be honest i dont understand you, i did exactly what u said but... it is not working.

this is what i've done:

Lua:
local eventId --added this on my locals (idk what is this tbh)
(...same script)--this is exactly the same, also idk if i must edit here...
local function countDown(number, pos, effect, msgonend, effectonend)
  local n = number
          for i = 1, number do
            addEvent(doSendAnimatedText,i*1000, pos, n > 1 and n.."" or msgonend .."", n < 10 and TEXTCOLOR_RED or TEXTCOLOR_TEAL)
            n = n -1
          end
      n = number
  return true
end
(...) added
function onUse(cid, item, frompos, item2, topos)
  eventId = addEvent(countDown, 1000, number, pos, effect, msgonend, effectonend)
  addEvent(eventId)


(...)

addEvent(function()
  local spec = getSpectators(heart, 50, 50)
                if spec ~= nil then
                     for _, s in pairs(spec) do
                         if not isPlayer(s) == true then
                             doRemoveCreature(s)
                             stopEvent(eventId)
                             print(2)
                         end
                    end  
                end
end, 3500)
 

Attachments

They are different scripts? I don't know if it's causing it as I don't have much experiencie with events, but try removing local from the event function.

From this:
Code:
local function countDown(number, pos, effect, msgonend, effectonend)

To this:
Code:
function countDown(number, pos, effect, msgonend, effectonend)
 
Oh boy. Where to start...

1) Okay, the error is because you are trying to use a loop without a number.
-- In your script you are passing "number", but never assigning a number to that argument before using the addEvent.

2) You are trying to stop the event without an eventID or a variable to call it from.

3) Even if you changed the stopEvent to work properly with the function you've created, the function itself is creating a ton of addEvents that all don't have an eventID attached to them.
-- (which ironically is where your error currently is, but doesn't relate to the actual problem.) "for i = 1, number do"
-- in order to fix this, you'd have to have each of these addEvents attached with an eventID of some sort that you can call in the future.
-- this way if something "in the future" happens, you'd be able to stop the timer.

4) In the main script, you are looping through all of the spectators and attempting to stop the event multiple times.
-- You aren't seeing error's for this, because of how stopEvent is scripted in source, but you're basically wasting extra resources trying to stop an event that would have been stopped on the first pass.

------
On a side note, all of the above is null and void, because none of this solves your original problem, because we don't know what the script is supposed to be doing in the first place.

Please tell us what you want the full script to do so we can guide you to a proper solution.
 
Oh boy. Where to start...

1) Okay, the error is because you are trying to use a loop without a number.
-- In your script you are passing "number", but never assigning a number to that argument before using the addEvent.

2) You are trying to stop the event without an eventID or a variable to call it from.

3) Even if you changed the stopEvent to work properly with the function you've created, the function itself is creating a ton of addEvents that all don't have an eventID attached to them.
-- (which ironically is where your error currently is, but doesn't relate to the actual problem.) "for i = 1, number do"
-- in order to fix this, you'd have to have each of these addEvents attached with an eventID of some sort that you can call in the future.
-- this way if something "in the future" happens, you'd be able to stop the timer.

4) In the main script, you are looping through all of the spectators and attempting to stop the event multiple times.
-- You aren't seeing error's for this, because of how stopEvent is scripted in source, but you're basically wasting extra resources trying to stop an event that would have been stopped on the first pass.

------
On a side note, all of the above is null and void, because none of this solves your original problem, because we don't know what the script is supposed to be doing in the first place.

Please tell us what you want the full script to do so we can guide you to a proper solution.

ok! i think im getting this.
the script is a raid, when activated,
1-.if there are >= 1 players (each 15 seconds, really buggy as u see) then
2-. spawnMonsters
3-.a countdown will start as animatedtextmsg (i need to stop this if all player dies in the battle area and resetRoom)
4-if the countdown gets to 0 resetRoom (remove all creatures, lever activable, remove block stones)

basically i need to execute resetRoom, stop checkPlayers and stop countDown if there are < 1 players

this is the crapcode at the moment
Lua:
local eventCheckPlayers = {}
local block = {x = 683, y = 617, z = 11, stackpos = 2}
local block2 = {x = 691, y = 611, z = 11,  stackpos = 2}
local heart = {x = 688, y = 621, z = 11, stackpos = 2}
local monsterpos = {x = 690, y = 625, z = 11}  --teleport position
local monsterpos1 = {x = 693, y = 616, z = 11}  --teleport position
local monsterpos2 = {x = 698, y = 617, z = 11} --teleport position
local monsterpos3 = {x = 686, y = 616, z = 11} --teleport position
local monsterpos4 = {x = 693, y = 621, z = 11}  --teleport position
local exhausted_seconds = 1 *8*1000
local exhausted_storagevalue = 1259
local area = {
        fromPos = {x = 683, y = 605, z = 11},
        toPos = {x = 706, y = 628, z = 11}
        }
local function spawnMonsters()
           addEvent(function()
           doCreateMonster("Diabolic Imp", monsterpos)
           doSendMagicEffect(monsterpos, 36)
           end, exhausted_seconds*.01)
           addEvent(function()
           doCreateMonster("Diabolic Imp", monsterpos1)
           doSendMagicEffect(monsterpos1, 36)
           end, exhausted_seconds*.02)
           addEvent(function()
           doCreateMonster("Diabolic Imp", monsterpos2)
           doSendMagicEffect(monsterpos2, 36)
           end, exhausted_seconds*.03)
           addEvent(function()
           doCreateMonster("Minishabaal", monsterpos3)
           doSendMagicEffect(monsterpos3, 36)
           doCreateMonster("Diabolic Imp", monsterpos2)
           doSendMagicEffect(monsterpos2, 36)
           doCreateMonster("Diabolic Imp", monsterpos1)
           doSendMagicEffect(monsterpos1, 36)
           end, exhausted_seconds*.08)
           addEvent(function()
           doSendMagicEffect(monsterpos4, 36)
           -- doRemoveItem(getTileItemById(monsterpos4,8635).uid,1)
           doTransformItem(getTileItemById(monsterpos4,8635).uid,3655)
           --doTransformItem(getThingFromPos(monsterpos4).uid, 3614)
           end, exhausted_seconds*.049)
           addEvent(function()
           doSendMagicEffect(monsterpos4, 6)
           doCreateMonster("Orshabaal", monsterpos4)
           end, exhausted_seconds*.05)
end  
local function removeCreatures()
  local spec = getSpectators(heart, 50, 50)
  if spec ~= nil then
       for _, s in pairs(spec) do
           if isMonster(s) then
               doRemoveCreature(s)
               stopEvent(doThatShit)
               print(2)
           end
       end
   end
end
local function resetRoom()
  removeCreatures()
  addEvent(function()
    doRemoveItem(getTileItemById(block,1355).uid,1)
    doTransformItem(getTileItemById(heart,3699).uid,3700)
    doRemoveItem(getTileItemById(block2,1355).uid,1)
    doTransformItem(getTileItemById(monsterpos4,3655).uid,8635)
  end, exhausted_seconds+500)
  addEvent(function()
      doItemSetAttribute(getTileItemById(heart,3700).uid, "uid", 9050)
      doItemSetAttribute(getTileItemById(heart,3700).uid, "aid", 9050)
  end, exhausted_seconds+1000)
end
local function checkPlayers(cid)
  if not isPlayer(cid) then
          return true
  end
  for i = 1, 1 do
    for _, pid in ipairs(getPlayersOnline()) do
          local xpos = getPlayerPosition(pid)
          if isInRange(heart, area.fromPos, area.toPos) then
            print(1)
            -- return 1
            else
              resetRoom()
              stopEvent(timeOver)
              stopEvent(countDown, 1000, heart)
              local eventCheckPlayers = addEvent(checkPlayers, 1000, cid)
              stopEvent(eventCheckPlayers, 1000, cid)
            print(2)
          end
      end
      -- continue(1000, 5, cid)
      return true
  end
end
local function doThatShit(cid, n)
    if(n > 1) then
        addEvent(checkPlayers, 1000, cid, n - 1)
    end
return 0
end
local function timeOver()
  local spec = getSpectators(heart, 50, 50)
      if spec ~= nil then
           for _, s in pairs(spec) do
               if isMonster(s) then
                   doRemoveCreature(s)              
            
           end
      end
                doBroadcastMessage("Orshabaal has succesfully defended the Abyss.", 22)
                resetRoom()
                stopEvent(doThatShit)
                end
end
local function countDown(number, pos, effect, msgonend, effectonend)
  local n = number
          for i = 1, number do
            addEvent(doSendAnimatedText,i*1000, pos, n > 1 and n.."" or msgonend .."", n < 10 and TEXTCOLOR_RED or TEXTCOLOR_TEAL)
            --addEvent(doSendMagicEffect,i* 1000, pos, n > 1 and effect or effectonend )
            n = n -1
          end
      n = number
  return true
end
function onUse(cid, item, frompos, item2, topos)
 
  countDown(exhausted_seconds/1000, heart, 5, "Time over...", 2)
  doTeleportPlayersFromArea({x = 609, y = 510, z = 11}, {x = 684, y = 626, z = 11}, {x = 685, y = 618, z = 11}, true)
  doTeleportPlayersFromArea({x = 667, y = 564, z = 11}, {x = 707, y = 606, z = 11}, {x = 685, y = 618, z = 11}, true)
    if item.itemid == 3700 then
      if isPlayer(cid) then
           doRemoveItem(item.uid)
           addEvent(doCreateItem,100,3699, 1, heart)
           doCreateItem(1355, 1, block)
           doCreateItem(1355, 1, block2)
           doSendMagicEffect(heart, 36) --start
           spawnMonsters()
           addEvent(timeOver, exhausted_seconds)
           setPlayerStorageValue(cid, exhausted_storagevalue, os.time() + exhausted_seconds)
           doCreatureSay(cid, 'You just challenged Orshabaal!', TALKTYPE_ORANGE_1)
    else
      doCreatureSay(cid, 'You have succesfully completed this challenge, please wait the dwarf repair the engine!', TALKTYPE_ORANGE_1)
    end
end
addEvent(checkPlayers, 1000, cid)
return true
end
 
bump pls? i still can not make stop the event :s
I've looked through the code, and attempted to complete everything on your list.
If I didn't understand why a function was required, I left it alone.
I green texted any code that seemed redundant or no longer necessary.

The broadcast message currently only triggers if the timer reaches zero.
If all players die or leave the area, the room will reset, with no broadcast.

Lua:
--local eventCheckPlayers = {}
local block = {x = 683, y = 617, z = 11, stackpos = 2}
local block2 = {x = 691, y = 611, z = 11,  stackpos = 2}
local heart = {x = 688, y = 621, z = 11, stackpos = 2}
local monsterpos = {x = 690, y = 625, z = 11}  --teleport position
local monsterpos1 = {x = 693, y = 616, z = 11}  --teleport position
local monsterpos2 = {x = 698, y = 617, z = 11} --teleport position
local monsterpos3 = {x = 686, y = 616, z = 11} --teleport position
local monsterpos4 = {x = 693, y = 621, z = 11}  --teleport position
local exhausted_seconds = 1 *8*1000
local exhausted_storagevalue = 1259


-- THIS IS WHERE PLAYERS WILL TELEPORT IF THE TIME RUNS OUT
local fail_position = {x = 11111111111, y = 11111111111111, z = 11111111111}
-- THIS IS WHERE PLAYERS WILL TELEPORT IF THE TIME RUNS OUT


--local area = {
--    fromPos = {x = 683, y = 605, z = 11},
--    toPos = {x = 706, y = 628, z = 11}
--}

local function spawnMonsters()
    addEvent(function()
        doCreateMonster("Diabolic Imp", monsterpos)
        doSendMagicEffect(monsterpos, 36)
    end, exhausted_seconds*.01)
    addEvent(function()
        doCreateMonster("Diabolic Imp", monsterpos1)
        doSendMagicEffect(monsterpos1, 36)
    end, exhausted_seconds*.02)
    addEvent(function()
        doCreateMonster("Diabolic Imp", monsterpos2)
        doSendMagicEffect(monsterpos2, 36)
    end, exhausted_seconds*.03)
    addEvent(function()
        doCreateMonster("Minishabaal", monsterpos3)
        doSendMagicEffect(monsterpos3, 36)
        doCreateMonster("Diabolic Imp", monsterpos2)
        doSendMagicEffect(monsterpos2, 36)
        doCreateMonster("Diabolic Imp", monsterpos1)
        doSendMagicEffect(monsterpos1, 36)
    end, exhausted_seconds*.08)
    addEvent(function()
        doSendMagicEffect(monsterpos4, 36)
        -- doRemoveItem(getTileItemById(monsterpos4,8635).uid,1)
        doTransformItem(getTileItemById(monsterpos4,8635).uid,3655)
        --doTransformItem(getThingFromPos(monsterpos4).uid, 3614)
    end, exhausted_seconds*.049)
    addEvent(function()
        doSendMagicEffect(monsterpos4, 6)
        doCreateMonster("Orshabaal", monsterpos4)
    end, exhausted_seconds*.05)
end

local function removeCreatures()
    local spec = getSpectators(heart, 50, 50)
    if spec ~= nil then
        for _, s in pairs(spec) do
            if isMonster(s) then
                doRemoveCreature(s)
                --stopEvent(doThatShit)
                print(2)
            end
            if isPlayer(s) then
                doTeleportThing(s, fail_position)
            end
        end
    end
end

local function resetRoom()
    removeCreatures()
    doRemoveItem(getTileItemById(block,1355).uid,1)
    doTransformItem(getTileItemById(heart,3699).uid,3700)
    doRemoveItem(getTileItemById(block2,1355).uid,1)
    doTransformItem(getTileItemById(monsterpos4,3655).uid,8635)
    addEvent(function()
        doItemSetAttribute(getTileItemById(heart,3700).uid, "uid", 9050)
        doItemSetAttribute(getTileItemById(heart,3700).uid, "aid", 9050)
    end, 100)
end

--local function checkPlayers(cid)
--    if not isPlayer(cid) then
--        return true
--    end
--    for i = 1, 1 do
--        for _, pid in ipairs(getPlayersOnline()) do
--            local xpos = getPlayerPosition(pid)
--            if isInRange(heart, area.fromPos, area.toPos) then
--                print(1)
--                -- return 1
--            else
--                resetRoom()
--                stopEvent(timeOver)
--                stopEvent(countDown, 1000, heart)
--                local eventCheckPlayers = addEvent(checkPlayers, 1000, cid)
--                stopEvent(eventCheckPlayers, 1000, cid)
--                print(2)
--            end
--        end
--        -- continue(1000, 5, cid)
--        return true
--    end
--end

--local function doThatShit(cid, n)
--    if(n > 1) then
--        addEvent(checkPlayers, 1000, cid, n - 1)
--    end
--    return 0
--end
--local function timeOver()
--    local spec = getSpectators(heart, 50, 50)
--    if spec ~= nil then
--        for _, s in pairs(spec) do
--            if isMonster(s) then
--                doRemoveCreature(s)
--            end
--        end
--        doBroadcastMessage("Orshabaal has succesfully defended the Abyss.", 22)
--        resetRoom()
--        stopEvent(doThatShit)
--    end
--end

--local function countDown(number, pos, effect, msgonend, effectonend)
--    local n = number
--    for i = 1, number do
--        addEvent(doSendAnimatedText,i*1000, pos, n > 1 and n.."" or msgonend .."", n < 10 and TEXTCOLOR_RED or TEXTCOLOR_TEAL)
--        --addEvent(doSendMagicEffect,i* 1000, pos, n > 1 and effect or effectonend )
--        n = n -1
--    end
--    n = number
--    return true
--end

-- THIS FUNCTION CHECKS IF THE TIME HAS RUN OUT & IF THERE ARE PLAYERS STILL IN THE ARENA
-- IF NO PLAYERS IN AREA, OR TIME RUNS OUT, resetRoom() will happen.
local function countDown(number, pos, effect, msgonend, effectonend)
    local count = 0
    local spec = getSpectators(heart, 50, 50)
    if spec ~= nil then
        for _, pid in pairs(spec) do
            if isPlayer(pid) then
                count = 1
                break
            end
        end
    end
    if count > 0 then
        doSendAnimatedText(pos, number > 1 and "" .. number .. "" or msgonend, number < 10 and TEXTCOLOR_RED or TEXTCOLOR_TEAL)
        doSendMagicEffect(pos, number > 1 and effect or effectonend )
        if number > 0 then
            addEvent(countDown, 1000, number - 1, pos, effect, msgonend, effectonend)
        end
    end
    if number == 0 or count == 0 then
        if number == 0 then
            doBroadcastMessage("Orshabaal has successfully defended the Abyss.", 22)
        end
        resetRoom()
    end
end

function onUse(cid, item, frompos, item2, topos)
    countDown(exhausted_seconds/1000, heart, 5, "Time over...", 2)
    doTeleportPlayersFromArea({x = 609, y = 510, z = 11}, {x = 684, y = 626, z = 11}, {x = 685, y = 618, z = 11}, true)
    doTeleportPlayersFromArea({x = 667, y = 564, z = 11}, {x = 707, y = 606, z = 11}, {x = 685, y = 618, z = 11}, true)
    if item.itemid == 3700 then
        if isPlayer(cid) then
            doRemoveItem(item.uid)
            addEvent(doCreateItem,100,3699, 1, heart)
            doCreateItem(1355, 1, block)
            doCreateItem(1355, 1, block2)
            doSendMagicEffect(heart, 36) --start
            spawnMonsters()
            --addEvent(timeOver, exhausted_seconds)
            setPlayerStorageValue(cid, exhausted_storagevalue, os.time() + exhausted_seconds)
            doCreatureSay(cid, 'You just challenged Orshabaal!', TALKTYPE_ORANGE_1)
        else
            doCreatureSay(cid, 'You have succesfully completed this challenge, please wait the dwarf repair the engine!', TALKTYPE_ORANGE_1)
        end
    end
    --addEvent(checkPlayers, 1000, cid)
    return true
end
 
Last edited:
I've looked through the code, and attempted to complete everything on your list.
If I didn't understand why a function was required, I left it alone.
I green texted any code that seemed redundant or no longer necessary.

The broadcast message currently only triggers if the timer reaches zero.
If all players die or leave the area, the room will reset, with no broadcast.

Lua:
--local eventCheckPlayers = {}
local block = {x = 683, y = 617, z = 11, stackpos = 2}
local block2 = {x = 691, y = 611, z = 11,  stackpos = 2}
local heart = {x = 688, y = 621, z = 11, stackpos = 2}
local monsterpos = {x = 690, y = 625, z = 11}  --teleport position
local monsterpos1 = {x = 693, y = 616, z = 11}  --teleport position
local monsterpos2 = {x = 698, y = 617, z = 11} --teleport position
local monsterpos3 = {x = 686, y = 616, z = 11} --teleport position
local monsterpos4 = {x = 693, y = 621, z = 11}  --teleport position
local exhausted_seconds = 1 *8*1000
local exhausted_storagevalue = 1259


-- THIS IS WHERE PLAYERS WILL TELEPORT IF THE TIME RUNS OUT
local fail_position = {x = 11111111111, y = 11111111111111, z = 11111111111}
-- THIS IS WHERE PLAYERS WILL TELEPORT IF THE TIME RUNS OUT


--local area = {
--    fromPos = {x = 683, y = 605, z = 11},
--    toPos = {x = 706, y = 628, z = 11}
--}

local function spawnMonsters()
    addEvent(function()
        doCreateMonster("Diabolic Imp", monsterpos)
        doSendMagicEffect(monsterpos, 36)
    end, exhausted_seconds*.01)
    addEvent(function()
        doCreateMonster("Diabolic Imp", monsterpos1)
        doSendMagicEffect(monsterpos1, 36)
    end, exhausted_seconds*.02)
    addEvent(function()
        doCreateMonster("Diabolic Imp", monsterpos2)
        doSendMagicEffect(monsterpos2, 36)
    end, exhausted_seconds*.03)
    addEvent(function()
        doCreateMonster("Minishabaal", monsterpos3)
        doSendMagicEffect(monsterpos3, 36)
        doCreateMonster("Diabolic Imp", monsterpos2)
        doSendMagicEffect(monsterpos2, 36)
        doCreateMonster("Diabolic Imp", monsterpos1)
        doSendMagicEffect(monsterpos1, 36)
    end, exhausted_seconds*.08)
    addEvent(function()
        doSendMagicEffect(monsterpos4, 36)
        -- doRemoveItem(getTileItemById(monsterpos4,8635).uid,1)
        doTransformItem(getTileItemById(monsterpos4,8635).uid,3655)
        --doTransformItem(getThingFromPos(monsterpos4).uid, 3614)
    end, exhausted_seconds*.049)
    addEvent(function()
        doSendMagicEffect(monsterpos4, 6)
        doCreateMonster("Orshabaal", monsterpos4)
    end, exhausted_seconds*.05)
end

local function removeCreatures()
    local spec = getSpectators(heart, 50, 50)
    if spec ~= nil then
        for _, s in pairs(spec) do
            if isMonster(s) then
                doRemoveCreature(s)
                --stopEvent(doThatShit)
                print(2)
            end
            if isPlayer(s) then
                doTeleportThing(s, fail_position)
            end
        end
    end
end

local function resetRoom()
    removeCreatures()
    doRemoveItem(getTileItemById(block,1355).uid,1)
    doTransformItem(getTileItemById(heart,3699).uid,3700)
    doRemoveItem(getTileItemById(block2,1355).uid,1)
    doTransformItem(getTileItemById(monsterpos4,3655).uid,8635)
    addEvent(function()
        doItemSetAttribute(getTileItemById(heart,3700).uid, "uid", 9050)
        doItemSetAttribute(getTileItemById(heart,3700).uid, "aid", 9050)
    end, 100)
end

--local function checkPlayers(cid)
--    if not isPlayer(cid) then
--        return true
--    end
--    for i = 1, 1 do
--        for _, pid in ipairs(getPlayersOnline()) do
--            local xpos = getPlayerPosition(pid)
--            if isInRange(heart, area.fromPos, area.toPos) then
--                print(1)
--                -- return 1
--            else
--                resetRoom()
--                stopEvent(timeOver)
--                stopEvent(countDown, 1000, heart)
--                local eventCheckPlayers = addEvent(checkPlayers, 1000, cid)
--                stopEvent(eventCheckPlayers, 1000, cid)
--                print(2)
--            end
--        end
--        -- continue(1000, 5, cid)
--        return true
--    end
--end

--local function doThatShit(cid, n)
--    if(n > 1) then
--        addEvent(checkPlayers, 1000, cid, n - 1)
--    end
--    return 0
--end
--local function timeOver()
--    local spec = getSpectators(heart, 50, 50)
--    if spec ~= nil then
--        for _, s in pairs(spec) do
--            if isMonster(s) then
--                doRemoveCreature(s)
--            end
--        end
--        doBroadcastMessage("Orshabaal has succesfully defended the Abyss.", 22)
--        resetRoom()
--        stopEvent(doThatShit)
--    end
--end

--local function countDown(number, pos, effect, msgonend, effectonend)
--    local n = number
--    for i = 1, number do
--        addEvent(doSendAnimatedText,i*1000, pos, n > 1 and n.."" or msgonend .."", n < 10 and TEXTCOLOR_RED or TEXTCOLOR_TEAL)
--        --addEvent(doSendMagicEffect,i* 1000, pos, n > 1 and effect or effectonend )
--        n = n -1
--    end
--    n = number
--    return true
--end

-- THIS FUNCTION CHECKS IF THE TIME HAS RUN OUT & IF THERE ARE PLAYERS STILL IN THE ARENA
-- IF NO PLAYERS IN AREA, OR TIME RUNS OUT, resetRoom() will happen.
local function countDown(number, pos, effect, msgonend, effectonend)
    local count = 0
    local spec = getSpectators(heart, 50, 50)
    if spec ~= nil then
        for _, pid in pairs(spec) do
            if isPlayer(pid) then
                count = 1
                break
            end
        end
    end
    if count > 0 then
        doSendAnimatedText(pos, number > 1 and "" .. number .. "" or msgonend, number < 10 and TEXTCOLOR_RED or TEXTCOLOR_TEAL)
        doSendMagicEffect(pos, number > 1 and effect or effectonend )
        if number > 0 then
            addEvent(countDown, 1000, number - 1, pos, effect, msgonend, effectonend)
        end
    end
    if number == 0 or count == 0 then
        if count == 0 then
            doBroadcastMessage("Orshabaal has successfully defended the Abyss.", 22)
        end
        resetRoom()
    end
end

function onUse(cid, item, frompos, item2, topos)
    countDown(exhausted_seconds/1000, heart, 5, "Time over...", 2)
    doTeleportPlayersFromArea({x = 609, y = 510, z = 11}, {x = 684, y = 626, z = 11}, {x = 685, y = 618, z = 11}, true)
    doTeleportPlayersFromArea({x = 667, y = 564, z = 11}, {x = 707, y = 606, z = 11}, {x = 685, y = 618, z = 11}, true)
    if item.itemid == 3700 then
        if isPlayer(cid) then
            doRemoveItem(item.uid)
            addEvent(doCreateItem,100,3699, 1, heart)
            doCreateItem(1355, 1, block)
            doCreateItem(1355, 1, block2)
            doSendMagicEffect(heart, 36) --start
            spawnMonsters()
            --addEvent(timeOver, exhausted_seconds)
            setPlayerStorageValue(cid, exhausted_storagevalue, os.time() + exhausted_seconds)
            doCreatureSay(cid, 'You just challenged Orshabaal!', TALKTYPE_ORANGE_1)
        else
            doCreatureSay(cid, 'You have succesfully completed this challenge, please wait the dwarf repair the engine!', TALKTYPE_ORANGE_1)
        end
    end
    --addEvent(checkPlayers, 1000, cid)
    return true
end
Niiiiiiiiiiceee!! you're the best Xikini :D! ty very much.

im very interested to know where was my error, i know you already texted it above, but want to know what have you done here (if is not annoy for you)

Lua:
local function countDown(number, pos, effect, msgonend, effectonend)
    local count = 0 -- Why 0?, whats the function of give a constant of = 0, is it the same function as not constant¿?
    local spec = getSpectators({x = 693, y = 621, z = 11}, 13, 13)
    if spec ~= nil then
        for _, pid in pairs(spec) do
            if isPlayer(pid) then
                count = 1
                break
            end
        end
    end
    if count > 0 then -- you used it here, and as i see if the counter is > 0 then it will still counting  or players¿?
        doSendAnimatedText(pos, number > 1 and "" .. number .. "" or msgonend, number < 10 and TEXTCOLOR_RED or TEXTCOLOR_TEAL)
        doSendMagicEffect(pos, number > 1 and effect or effectonend )
        if number > 0 then --this is where im confused, idk what kind of magic u used 
            addEvent(countDown, 1000, number - 1, pos, effect, msgonend, effectonend)
        end
    end
    if number == 0 or count == 0 then
        if count == 0 then -- if no players then bc this and
            doBroadcastMessage("Orshabaal has successfully defended the Abyss.", 22)
        end
        resetRoom() -- why is this not inside the ^ line, why separated?
    end
end

Sorry for the questions im not a programmer,just a hobbist but i want to learn tho i've read some tutorials but there are some things i still can not comprehend.

Have a nice day =)
 
Would love to know some things too, he's indeed a really good programmer.
I know it's really off topic, but if you can explain only two things I will be happy.
Code:
addEvent(function()
Why does it look like it's missing a ')' and works? lol

Code:
for _, pid in pairs(spec) do
What is pid in pairs? ._.
 
Niiiiiiiiiiceee!! you're the best Xikini :D! ty very much.

im very interested to know where was my error, i know you already texted it above, but want to know what have you done here (if is not annoy for you)

Lua:
local function countDown(number, pos, effect, msgonend, effectonend)
    local count = 0 -- Why 0?, whats the function of give a constant of = 0, is it the same function as not constant¿?
    local spec = getSpectators({x = 693, y = 621, z = 11}, 13, 13)
    if spec ~= nil then
        for _, pid in pairs(spec) do
            if isPlayer(pid) then
                count = 1
                break
            end
        end
    end
    if count > 0 then -- you used it here, and as i see if the counter is > 0 then it will still counting  or players¿?
        doSendAnimatedText(pos, number > 1 and "" .. number .. "" or msgonend, number < 10 and TEXTCOLOR_RED or TEXTCOLOR_TEAL)
        doSendMagicEffect(pos, number > 1 and effect or effectonend )
        if number > 0 then --this is where im confused, idk what kind of magic u used
            addEvent(countDown, 1000, number - 1, pos, effect, msgonend, effectonend)
        end
    end
    if number == 0 or count == 0 then
        if count == 0 then -- if no players then bc this and
            doBroadcastMessage("Orshabaal has successfully defended the Abyss.", 22)
        end
        resetRoom() -- why is this not inside the ^ line, why separated?
    end
end

Sorry for the questions im not a programmer,just a hobbist but i want to learn tho i've read some tutorials but there are some things i still can not comprehend.

Have a nice day =)
I edited the above code very slightly. Was a small mistake.
Please recopy.

-----

Lua:
local function countDown(number, pos, effect, msgonend, effectonend)
    local count = 0 -- We are setting this to zero, because at this point in the script, we aren't sure if there are any players in the area.
 
    -- this part is grabbing all creatures in the area
    local spec = getSpectators(heart, 50, 50)
    if spec ~= nil then -- here we check if any player/monster/npc is in the area
        for _, pid in pairs(spec) do -- we start looping through all creatures found
            if isPlayer(pid) then
                count = 1 -- if we find a player, we change the count value to 1, because only 1 player is required for the event to continue
                break -- break stops the loop we started
            end
        end
    end
 
    -- if a player was found, we send the effect & text
    if count > 0 then
        doSendAnimatedText(pos, number > 1 and number or msgonend, n < 10 and TEXTCOLOR_RED or TEXTCOLOR_TEAL)
        doSendMagicEffect(pos, number > 1 and effect or effectonend )
     
        -- number == timer
        if number > 0 then
            -- if there is more then 1 second left of timer we re-check everything again in 1 second. (the 1000 = 1000 milliseconds -> which is 1 second)
            addEvent(countDown, 1000, number - 1, pos, effect, msgonend, effectonend)
        end
    end
 
    -- if the timer has run out OR if there are no players in the area..
    if number == 0 or count == 0 then
     
        -- if timer ended, broadcast message
        if number == 0 then
            doBroadcastMessage("Orshabaal has successfully defended the Abyss.", 22)
        end
     
        -- we put this outside of the if statement from above, because we want the room to reset no matter which event triggered the reset (lack of players or timer finished)
        resetRoom()
    end
end
 
Last edited:
Solution
Would love to know some things too, he's indeed a really good programmer.
I know it's really off topic, but if you can explain only two things I will be happy.
Code:
addEvent(function()
Why does it look like it's missing a ')' and works? lol

Code:
for _, pid in pairs(spec) do
What is pid in pairs? ._.

mmm, pairs is way I'm grabbing the creatures found from getSpectators.
pid is the variable I'm temporary assigning to each creature found.
You could change pid to aaa, bbb, ccc.. doesn't matter.
I use pid because
cid = creatureID
pid = playerID


These are both the same thing, just formatted differently.
We are creating a function without naming it, and placing it inside the addEvent.
Lua:
addEvent(function() doCreateMonster("Diabolic Imp", monsterpos) doSendMagicEffect(monsterpos, 36) end, exhausted_seconds * .01)

addEvent(function()
    doCreateMonster("Diabolic Imp", monsterpos)
    doSendMagicEffect(monsterpos, 36)
end, exhausted_seconds*.01)
 
Nice...
mmm, pairs is way I'm grabbing the creatures found from getSpectators.

something out of context too, but in pairs(getSpec) takes all players inside the area, and if there is a parameter inside of the function then it will repeat the action 'n' number of players??
 
Nice...


something out of context too, but in pairs(getSpec) takes all players inside the area, and if there is a parameter inside of the function then it will repeat the action 'n' number of players??
Right.
So getSpectators would grab all Creatures inside the area.

which (invisibly) looks something like this..
Lua:
local spec = {23546745634, 23546745635, 23546745636, 23546745637}
All of those numbers are creatureID's which are in the area.
They can npc's / monster / or players

So using the lua function "pairs" iterates over all elements in a table. (which we created when using getSpectators previously.)
So in the above example, there is currently 4 elements in the table, so it will attempt to loop 4 times, reassigning "pid" to one of those numbers, each time it loops.

In the code I submitted, I 'break' (end the loop) whenever I find the first player, so that we don't need to loop through ALL of the creatures found, since we are only trying to confirm if there is players still in the area.
I use and update the variable 'count', so we can use the information found in the loop, further in the code. (if no players were found, 'count' would still be zero.)

-- Hope that makes sense. xP
 
Back
Top