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

Lua custom annihilator with time

marcosb

New Member
Joined
Jul 29, 2012
Messages
13
Solutions
1
Reaction score
1
could someone help me with this script?

I would like to add a timeout, for the player to perform the quest, for example: 1 minute
thx.

Code:
local config = {
        daily = "no", -- allow only one team to enter per day? (like in global Tibia)
        level = 100,
        storage = 30016,
        room = {
                {x = 206, y = 377, z = 6},
                {x = 210, y = 384, z = 6}
        },
        stand = {
                {x = 50, y = 258, z = 7},
    {x = 50, y = 259, z = 7},
    {x = 50, y = 260, z = 7},
    {x = 50, y = 261, z = 7}
        },
        destination = {
                {x = 208, y = 380, z = 6},
    {x = 208, y = 381, z = 6},
    {x = 208, y = 382, z = 6},
    {x = 208, y = 383, z = 6}
        },
        wall = {
                {x = 208, y = 377, z = 6}
        },
        rocks = {
                {x = 208, y = 378, z = 6},
                {x = 208, y = 379, z = 6},
                {x = 208, y = 380, z = 6},
                {x = 208, y = 381, z = 6},
                {x = 208, y = 382, z = 6},
                {x = 208, y = 383, z = 6},
                {x = 206, y = 379, z = 6},
                {x = 206, y = 381, z = 6},
                {x = 206, y = 383, z = 6},
                {x = 210, y = 380, z = 6},
    {x = 210, y = 382, z = 6},
    {x = 210, y = 384, z = 6}
   
        },
        demons = {
                {x = 208, y = 377, z = 6},
                {x = 208, y = 378, z = 6},
    {x = 208, y = 379, z = 6},
                {x = 206, y = 379, z = 6},
                {x = 206, y = 381, z = 6},
                {x = 206, y = 383, z = 6},
                {x = 210, y = 380, z = 6},
    {x = 210, y = 382, z = 6},
    {x = 210, y = 384, z = 6}
        }
}
local function areaCheck(area)
        local monsters, players = {}, {}
        for x = config.room[1].x, config.room[2].x do
                for y = config.room[1].y, config.room[2].y do
                        local t = getThingFromPos({x=x, y=y, z=config.room[1].z, stackpos=253})
                        if t.uid > 0 then
                                if isPlayer(t.uid) then
                                        table.insert(players, t.uid)
                                elseif isMonster(t.uid) then
                                        table.insert(monsters, t.uid)
                                end
                        end
                end
        end
        return monsters, players
end
config.daily = getBooleanFromString(config.daily)
function onUse(cid, item, fromPosition, itemEx, toPosition)
        if(item.itemid == 1945) then
                if(config.daily) then
                        return doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
                else
                        local monsters, players = areaCheck(config.room)
                        if #players > 0 then
                                return doPlayerSendCancel(cid, "There are players inside, please be patient.")
                        elseif #monsters > 0 then
                                for _, k in pairs(monsters) do
                                        doRemoveThing(k)
                                end
                        end
                        for _, v in ipairs(config.rocks) do
                                doCreateItem(8640, 1, v)
                        end
                        local closed, open = getTileItemById(config.wall[1], 5108), getTileItemById(config.wall[1], 5109)
                        if(closed.uid > 0) then
                                doTransformItem(closed.uid, 8636)
                        elseif(open.uid > 0) then
                                doTransformItem(open.uid, 8636)
                        end
                        doTransformItem(item.uid, item.itemid + 1)
                end
                return true
        end
        if(item.itemid ~= 1946) then
                return true
        end
        local players = {}
        for _, position in ipairs(config.stand) do
                local pid = getTopCreature(position).uid
                if(pid == 0 or not isPlayer(pid)) then
                        return doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
                elseif(getCreatureStorage(pid, config.storage) > 0) then
                        return doPlayerSendCancel(cid, "Someone has already completed this quest.")
                elseif(getPlayerLevel(pid) < config.level) then
                        return doPlayerSendCancel(cid, "Someone is below level 100.")
                end
                table.insert(players, pid)
        end
        local stones = {}
        for _, v in ipairs(config.rocks) do
                local st = getTileItemById(v, 8640)
                table.insert(stones, st)
        end
        for _, st in ipairs(stones) do
                doRemoveItem(st.uid, 1)
        end
        local wall = getTileItemById(config.wall[1], 8636)
        if(wall.uid > 0) then
                doTransformItem(wall.uid, 424)
        end
        for _, pos in ipairs(config.demons) do
                doCreateMonster("Hydra Abomination", pos, false, false) --TFS 0.3.6 -> [ doCreateMonster("Demon", pos) ]
                doSendMagicEffect(pos, CONST_ME_ENERGYAREA)
        end
        for i, pid in ipairs(players) do
                doSendMagicEffect(config.stand[i], CONST_ME_POFF)
                doTeleportThing(pid, config.destination[i], false)
                doSendMagicEffect(config.destination[i], CONST_ME_TELEPORT)
        end
        doTransformItem(item.uid, item.itemid - 1)
        return true
end
 
Code:
local current_time = os.time()
local time_to_start = current_time+60 --60 seconds in future
local storage_time = getPlayerStorageValue(cid, 19521)

--if time has passed
 if(current_time>storage_time)then --does not include time
  setPlayerStorageValue(cid, 19521, time_to_start)
  --Execute Code Here
  else
  --time has not passed
 end
 
how would it fit? such as adding a location for the player to be teleported when time runs out. thank you very much
 
As a quick fix, try using this code instead:
Code:
local config = {
        daily = "no", -- allow only one team to enter per day? (like in global Tibia)
        level = 100,
        storage = 30016,
        room = {
                {x = 206, y = 377, z = 6},
                {x = 210, y = 384, z = 6}
        },
        stand = {
                {x = 50, y = 258, z = 7},
    {x = 50, y = 259, z = 7},
    {x = 50, y = 260, z = 7},
    {x = 50, y = 261, z = 7}
        },
        destination = {
                {x = 208, y = 380, z = 6},
    {x = 208, y = 381, z = 6},
    {x = 208, y = 382, z = 6},
    {x = 208, y = 383, z = 6}
        },
        wall = {
                {x = 208, y = 377, z = 6}
        },
        rocks = {
                {x = 208, y = 378, z = 6},
                {x = 208, y = 379, z = 6},
                {x = 208, y = 380, z = 6},
                {x = 208, y = 381, z = 6},
                {x = 208, y = 382, z = 6},
                {x = 208, y = 383, z = 6},
                {x = 206, y = 379, z = 6},
                {x = 206, y = 381, z = 6},
                {x = 206, y = 383, z = 6},
                {x = 210, y = 380, z = 6},
    {x = 210, y = 382, z = 6},
    {x = 210, y = 384, z = 6}
  
        },
        demons = {
                {x = 208, y = 377, z = 6},
                {x = 208, y = 378, z = 6},
    {x = 208, y = 379, z = 6},
                {x = 206, y = 379, z = 6},
                {x = 206, y = 381, z = 6},
                {x = 206, y = 383, z = 6},
                {x = 210, y = 380, z = 6},
    {x = 210, y = 382, z = 6},
    {x = 210, y = 384, z = 6}
        }
}

Time = 1 * 60 * 1000 -- in milliseconds (this means 1 minute)

local function areaCheck(area)
        local monsters, players = {}, {}
        for x = config.room[1].x, config.room[2].x do
                for y = config.room[1].y, config.room[2].y do
                        local t = getThingFromPos({x=x, y=y, z=config.room[1].z, stackpos=253})
                        if t.uid > 0 then
                                if isPlayer(t.uid) then
                                        table.insert(players, t.uid)
                                elseif isMonster(t.uid) then
                                        table.insert(monsters, t.uid)
                                end
                        end
                end
        end
        return monsters, players
end
config.daily = getBooleanFromString(config.daily)
function onUse(cid, item, fromPosition, itemEx, toPosition)
        if(item.itemid == 1945) then
                if(config.daily) then
                        return doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
                else
                        local monsters, players = areaCheck(config.room)
                        if #players > 0 then
                                return doPlayerSendCancel(cid, "There are players inside, please be patient.")
                        elseif #monsters > 0 then
                                for _, k in pairs(monsters) do
                                        doRemoveThing(k)
                                end
                        end
                        for _, v in ipairs(config.rocks) do
                                doCreateItem(8640, 1, v)
                        end
                        local closed, open = getTileItemById(config.wall[1], 5108), getTileItemById(config.wall[1], 5109)
                        if(closed.uid > 0) then
                                doTransformItem(closed.uid, 8636)
                        elseif(open.uid > 0) then
                                doTransformItem(open.uid, 8636)
                        end
                        doTransformItem(item.uid, item.itemid + 1)
                end
                return true
        end
        if(item.itemid ~= 1946) then
                return true
        end
        local players = {}
        for _, position in ipairs(config.stand) do
                local pid = getTopCreature(position).uid
                if(pid == 0 or not isPlayer(pid)) then
                        return doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
                elseif(getCreatureStorage(pid, config.storage) > 0) then
                        return doPlayerSendCancel(cid, "Someone has already completed this quest.")
                elseif(getPlayerLevel(pid) < config.level) then
                        return doPlayerSendCancel(cid, "Someone is below level 100.")
                end
                table.insert(players, pid)
        end
        local stones = {}
        for _, v in ipairs(config.rocks) do
                local st = getTileItemById(v, 8640)
                table.insert(stones, st)
        end
        for _, st in ipairs(stones) do
                doRemoveItem(st.uid, 1)
        end
        local wall = getTileItemById(config.wall[1], 8636)
        if(wall.uid > 0) then
                doTransformItem(wall.uid, 424)
        end
        for _, pos in ipairs(config.demons) do
                doCreateMonster("Hydra Abomination", pos, false, false) --TFS 0.3.6 -> [ doCreateMonster("Demon", pos) ]
                doSendMagicEffect(pos, CONST_ME_ENERGYAREA)
        end
        for i, pid in ipairs(players) do
                doSendMagicEffect(config.stand, CONST_ME_POFF)
                doTeleportThing(pid, config.destination, false)
                doSendMagicEffect(config.destination, CONST_ME_TELEPORT)
        end
        doTransformItem(item.uid, item.itemid - 1)

        function TimeOut(param)
            for i, pid in ipairs(players) do
                doSendMagicEffect(config.destination, CONST_ME_POFF)
                doTeleportThing(pid, config.stand, false)
                doSendMagicEffect(config.stand, CONST_ME_TELEPORT)
            end
            return true
        end

        addEvent(TimeOut, Time, 0)
      
        return true
end
 
Thanks for the help, but it did not work. I pull the lever, and nothing happens, no mistake in the distro
 
tfs 0.4.

in fact, I was looking for the script in a simple arena, for this to happen, it is necessary for the script to have a countdown as soon as it finishes, the player to a certain location
 
Back
Top