• 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 Teleport by day

dervin13

Active Member
Joined
Apr 26, 2008
Messages
459
Solutions
1
Reaction score
28
Hello, i have this script to teleport and it just work when i put only one day... what i have to do to work in more than one day?? thanks

Code:
local configuration = {
    day = {"tuesday", "thursday", "saturday"},
    to_pos = {x = 1021, y = 1074, z = 5},    --Para onde o teleport levará.
    pos = {x = 858, y = 750, z = 7},       --Onde o teleport será criado.
    teleport_id = 1387,                --ID do teleport.
    aid = 3434,                        --Action ID do teleport.
    time = 120,                         --Tempo para fechar, em minutos.
}
function onTime()
    if os.date("%A") == configuration.day then
        local item = getTileItemById(configuration.pos, configuration.teleport_id).uid
        if item < 1 then
            local tp = doCreateTeleport(configuration.teleport_id, configuration.to_pos, configuration.pos)
            doItemSetAttribute(tp, "aid", configuration.aid)
            broadcastMessage("A arena foi aberta.", MESSAGE_STATUS_WARNING)
            addEvent(function()
                tp = getTileItemById(configuration.pos, configuration.teleport_id).uid
                if tp and tp > 0 then
                    doRemoveItem(tp)
                    broadcastMessage("A arena foi fechada.")
                end
            end, configuration.time * 60 * 1000)
        end
    end
    return true
end
 
Code:
local configuration = {
    days = {"tuesday", "thursday", "saturday"},
    to_pos = {x = 1021, y = 1074, z = 5},    --Para onde o teleport levará.
    pos = {x = 858, y = 750, z = 7},       --Onde o teleport será criado.
    teleport_id = 1387,                --ID do teleport.
    aid = 3434,                        --Action ID do teleport.
    time = 120,                         --Tempo para fechar, em minutos.
}
function onTime()
local x = configuration.days[os.date("%A",os.time())]
    if x then
        local item = getTileItemById(configuration.pos, configuration.teleport_id).uid
        if item < 1 then
            local tp = doCreateTeleport(configuration.teleport_id, configuration.to_pos, configuration.pos)
            doItemSetAttribute(tp, "aid", configuration.aid)
            broadcastMessage("A arena foi aberta.", MESSAGE_STATUS_WARNING)
            addEvent(function()
                tp = getTileItemById(configuration.pos, configuration.teleport_id).uid
                if tp and tp > 0 then
                    doRemoveItem(tp)
                    broadcastMessage("A arena foi fechada.")
                end
            end, configuration.time * 60 * 1000)
        end
    end
    return true
end
 
still not working :((((

Try this, and if it doesn't work, post the error.
PS: It might be important that the days in the 'days' array all start with a capital letter.

Code:
local configuration = {
    days = {"Tuesday", "Thursday", "Saturday"},
    to_pos = {x = 1021, y = 1074, z = 5},    --Para onde o teleport levará.
    pos = {x = 858, y = 750, z = 7},       --Onde o teleport será criado.
    teleport_id = 1387,                --ID do teleport.
    aid = 3434,                        --Action ID do teleport.
    time = 120,                         --Tempo para fechar, em minutos.
}
function onTime()
local x = os.date("%A")
    if isInArray(configuration.days, x) then
        local item = getTileItemById(configuration.pos, configuration.teleport_id).uid
        if item < 1 then
            local tp = doCreateTeleport(configuration.teleport_id, configuration.to_pos, configuration.pos)
            doItemSetAttribute(tp, "aid", configuration.aid)
            broadcastMessage("A arena foi aberta.", MESSAGE_STATUS_WARNING)
            addEvent(function()
                tp = getTileItemById(configuration.pos, configuration.teleport_id).uid
                if tp and tp > 0 then
                    doRemoveItem(tp)
                    broadcastMessage("A arena foi fechada.")
                end
            end, configuration.time * 60 * 1000)
        end
    end
    return true
end
 
Try this, and if it doesn't work, post the error.
PS: It might be important that the days in the 'days' array all start with a capital letter.

Code:
local configuration = {
    days = {"Tuesday", "Thursday", "Saturday"},
    to_pos = {x = 1021, y = 1074, z = 5},    --Para onde o teleport levará.
    pos = {x = 858, y = 750, z = 7},       --Onde o teleport será criado.
    teleport_id = 1387,                --ID do teleport.
    aid = 3434,                        --Action ID do teleport.
    time = 120,                         --Tempo para fechar, em minutos.
}
function onTime()
local x = os.date("%A")
    if isInArray(configuration.days, x) then
        local item = getTileItemById(configuration.pos, configuration.teleport_id).uid
        if item < 1 then
            local tp = doCreateTeleport(configuration.teleport_id, configuration.to_pos, configuration.pos)
            doItemSetAttribute(tp, "aid", configuration.aid)
            broadcastMessage("A arena foi aberta.", MESSAGE_STATUS_WARNING)
            addEvent(function()
                tp = getTileItemById(configuration.pos, configuration.teleport_id).uid
                if tp and tp > 0 then
                    doRemoveItem(tp)
                    broadcastMessage("A arena foi fechada.")
                end
            end, configuration.time * 60 * 1000)
        end
    end
    return true
end

Still not working :/ dont appear any error...
this is my original that i use, but i want to put more days :
Code:
local configuration = {
    day = "Saturday",
    to_pos = {x = 1021, y = 1077, z = 7},    --Para onde o teleport levará.
    pos = {x = 858, y = 750, z = 7},       --Onde o teleport será criado.
    teleport_id = 1387,                --ID do teleport.
    aid = 3434,                        --Action ID do teleport.
    time = 120,                         --Tempo para fechar, em minutos.
}
function onTime()
    if os.date("%A") == configuration.day then
        local item = getTileItemById(configuration.pos, configuration.teleport_id).uid
        if item < 1 then
            local tp = doCreateTeleport(configuration.teleport_id, configuration.to_pos, configuration.pos)
            doItemSetAttribute(tp, "aid", configuration.aid)
            broadcastMessage("A arena foi aberta.", MESSAGE_STATUS_WARNING)
            addEvent(function()
                tp = getTileItemById(configuration.pos, configuration.teleport_id).uid
                if tp and tp > 0 then
                    doRemoveItem(tp)
                    broadcastMessage("A arena foi fechada.")
                end
            end, configuration.time * 60 * 1000)
        end
    end
    return true
end
 
Still not working :/ dont appear any error...
this is my original that i use, but i want to put more days :

Did you use capital letters for the days in the array?

days = {"Tuesday", "Thursday", "Saturday"},

If this doesn't work, can you try this and then send what the console prints? (I added a print to see if your os.date("%A") returns a string of day's name and to see what it returns.)

Code:
local configuration = {
    days = {"Tuesday", "Thursday", "Saturday"},
    to_pos = {x = 1021, y = 1074, z = 5},    --Para onde o teleport levará.
    pos = {x = 858, y = 750, z = 7},       --Onde o teleport será criado.
    teleport_id = 1387,                --ID do teleport.
    aid = 3434,                        --Action ID do teleport.
    time = 120,                         --Tempo para fechar, em minutos.
}
function onTime()
local x = os.date("%A")
    print("Day is: " .. x .. ".")
    if isInArray(configuration.days, x) then
        local item = getTileItemById(configuration.pos, configuration.teleport_id).uid
        if item < 1 then
            local tp = doCreateTeleport(configuration.teleport_id, configuration.to_pos, configuration.pos)
            doItemSetAttribute(tp, "aid", configuration.aid)
            broadcastMessage("A arena foi aberta.", MESSAGE_STATUS_WARNING)
            addEvent(function()
                tp = getTileItemById(configuration.pos, configuration.teleport_id).uid
                if tp and tp > 0 then
                    doRemoveItem(tp)
                    broadcastMessage("A arena foi fechada.")
                end
            end, configuration.time * 60 * 1000)
        end
    end
    return true
end
 
Code:
        local configuration = {
            days = {"Tuesday", "Thursday", "Saturday"}
        }
       
       
        local x = os.date("%A")
       
            print("Day is: " .. x .. ".")
            if isInArray(configuration.days, x) then
            print(x .. " found in the configuration.days array.")
            end

I just tested this short script and this is the result:
https://i.imgur.com/L69BmXi.png

Meaning that there's no problem with this part of the code, it should pass.
I was in doubt whether you actually had the 'isInArray' function in your engine, but if you didn't and you tried to use it, the console would definitely throw an error.
You can use more print() in various places in that code to debug it and determine where the problem lies, if it really isn't throwing any errors.
 
Back
Top