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

Time Top On Teleport

Forkz

Member
Joined
Jun 29, 2020
Messages
182
Solutions
1
Reaction score
24
Hi,
I am using the system below to create teleportation when the "monster" is over and I would like it to show the time that teleportation will close.
Example:
1.png


Lua:
local tps = {
    ["Abomination Fury"] = {pos = {x=1835, y=980, z=11}, toPos = {x=2135, y=1066, z=9}, time = 300},
    ["Orshabaal"] = {pos = {x=1835, y=980, z=11}, toPos = {x=2135, y=1066, z=9}, time = 300}
}
local function removeTp(tp)
local t = getTileItemById(tp.pos, 1387).uid
return t > 0 and doRemoveItem(t) and doSendMagicEffect(tp.pos, CONST_ME_POFF)
end
function onDeath(cid)
local tp = tps[getCreatureName(cid)]
    if tp then
        doCreateTeleport(1387, tp.toPos, tp.pos)
        doCreatureSay(cid, "O teleport irá sumir em "..tp.time.." segundos.", TALKTYPE_ORANGE_1)
        addEvent(removeTp, tp.time*1000, tp)
    end
return true
end
 
Solution
It worked, opened the teleport, but the cooling didn't work, this error occurred in the distro

View attachment 61182View attachment 61184
Lua:
local tps = {
    ["Abomination Fury"] = {pos = {x=1835, y=980, z=11}, toPos = {x=2135, y=1066, z=9}, time = 300},
    ["Orshabaal"] = {pos = {x=1835, y=980, z=11}, toPos = {x=2135, y=1066, z=9}, time = 300}
}

function removeTpAndShowTime(tp, secondsRemaining, cid)
    if secondsRemaining == 0 then
        local t = getTileItemById(tp.pos, 1387).uid
        return t > 0 and doRemoveItem(t) and doSendMagicEffect(tp.pos, CONST_ME_POFF)
    end
    -- if cid no longer exists, find a random player to use instead
    if not isCreature(cid) then
        for _, pid in ipairs(getPlayersOnline()) do
            cid...

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,672
Solutions
405
Reaction score
3,785
Use a looping function.

Lua:
function countdownTimer(secondsRemaining)
    doCreatureSay(cid, math.floor(secondsRemaining / 60) .. ":" .. (secondsRemaining % 60), TALKTYPE_ORANGE_1)
    if secondsRemaining > 0 then
        addEvent(countdownTimer, 1000, secondsRemaining - 1)
    end
end
Lua:
-- then in your script use this to activate the timer
local seconds = 5 * 60 -- 5 minutes in seconds
countdownTimer(seconds)

Of course use extra parameters to make the numbers appear on a specific position, if required.
 

Sarah Wesker

ค∂vαηcε รүηтαx ❤
Support Team
Joined
Mar 16, 2017
Messages
1,035
Solutions
102
Reaction score
1,086
Location
London
GitHub
MillhioreBT
Lua:
local tps = {
    ["Abomination Fury"] = {pos = {x=1835, y=980, z=11}, toPos = {x=2135, y=1066, z=9}, time = 300},
    ["Orshabaal"] = {pos = {x=1835, y=980, z=11}, toPos = {x=2135, y=1066, z=9}, time = 300}
}

function removeTpAndShowTime(tp, secondsRemaining, cid)
    if secondsRemaining == 0 then
        local t = getTileItemById(tp.pos, 1387).uid
        return t > 0 and doRemoveItem(t) and doSendMagicEffect(tp.pos, CONST_ME_POFF)
    end

    cid = isCreature(cid) and cid or getPlayersOnline()[1]
    if cid then
        doCreatureSay(cid, math.floor(secondsRemaining / 60) .. ":" .. (secondsRemaining % 60), TALKTYPE_ORANGE_1, false, 0, tp.pos)
    end
    addEvent(removeTpAndShowTime, 1000, tp, secondsRemaining - 1, cid)
end

function onDeath(cid)
    local tp = tps[getCreatureName(cid)]
    if tp then
        doCreateTeleport(1387, tp.toPos, tp.pos)
        doCreatureSay(cid, "O teleport irá sumir em "..tp.time.." segundos.", TALKTYPE_ORANGE_1)
        removeTpAndShowTime(tp, tp.time, cid)
    end
    return true
end
 
Last edited:
OP
OP
Forkz

Forkz

Member
Joined
Jun 29, 2020
Messages
182
Solutions
1
Reaction score
24
Lua:
local tps = {
    ["Abomination Fury"] = {pos = {x=1835, y=980, z=11}, toPos = {x=2135, y=1066, z=9}, time = 300},
    ["Orshabaal"] = {pos = {x=1835, y=980, z=11}, toPos = {x=2135, y=1066, z=9}, time = 300}
}

function removeTpAndShowTime(tp, secondsRemaining, cid)
    if secondsRemaining == 0 then
        local t = getTileItemById(tp.pos, 1387).uid
        return t > 0 and doRemoveItem(t) and doSendMagicEffect(tp.pos, CONST_ME_POFF)
    end

    doCreatureSay(cid, math.floor(secondsRemaining / 60) .. ":" .. (secondsRemaining % 60), TALKTYPE_ORANGE_1, false, 0, tp.pos)
    addEvent(removeTpAndShowTime, 1000, tp, secondsRemaining - 1, cid)
end

function onDeath(cid)
    local tp = tps[getCreatureName(cid)]
    if tp then
        doCreateTeleport(1387, tp.toPos, tp.pos)
        doCreatureSay(cid, "O teleport irá sumir em "..tp.time.." segundos.", TALKTYPE_ORANGE_1)
        removeTpAndShowTime(tp, tp.time, cid)
    end
    return true
end
It worked, opened the teleport, but the cooling didn't work, this error occurred in the distro

Screenshot_13.pngScreenshot_15.png
 

Codinablack

Dreamer
Content Editor
Premium User
Joined
Dec 26, 2013
Messages
1,383
Solutions
7
Reaction score
512
It worked, opened the teleport, but the cooling didn't work, this error occurred in the distro

View attachment 61182View attachment 61184


Its because the monster is already dead, instead of using doCreatureSay, you will need to use a different method, and not use the "cid" , but instead use the creatures position, and that should get rid of any errors
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,672
Solutions
405
Reaction score
3,785
It worked, opened the teleport, but the cooling didn't work, this error occurred in the distro

View attachment 61182View attachment 61184
Lua:
local tps = {
    ["Abomination Fury"] = {pos = {x=1835, y=980, z=11}, toPos = {x=2135, y=1066, z=9}, time = 300},
    ["Orshabaal"] = {pos = {x=1835, y=980, z=11}, toPos = {x=2135, y=1066, z=9}, time = 300}
}

function removeTpAndShowTime(tp, secondsRemaining, cid)
    if secondsRemaining == 0 then
        local t = getTileItemById(tp.pos, 1387).uid
        return t > 0 and doRemoveItem(t) and doSendMagicEffect(tp.pos, CONST_ME_POFF)
    end
    -- if cid no longer exists, find a random player to use instead
    if not isCreature(cid) then
        for _, pid in ipairs(getPlayersOnline()) do
            cid = pid
            break
        end
    end
    if isCreature(cid) then -- if no player is online, then don't show text
        doCreatureSay(cid, math.floor(secondsRemaining / 60) .. ":" .. (secondsRemaining % 60), TALKTYPE_ORANGE_1, false, 0, tp.pos)
    end
    addEvent(removeTpAndShowTime, 1000, tp, secondsRemaining - 1, cid)
end

function onDeath(cid)
    local tp = tps[getCreatureName(cid)]
    if tp then
        doCreateTeleport(1387, tp.toPos, tp.pos)
        doCreatureSay(cid, "O teleport irá sumir em "..tp.time.." segundos.", TALKTYPE_ORANGE_1)
        removeTpAndShowTime(tp, tp.time, cid)
    end
    return true
end
 
Solution
OP
OP
Forkz

Forkz

Member
Joined
Jun 29, 2020
Messages
182
Solutions
1
Reaction score
24
Lua:
local tps = {
    ["Abomination Fury"] = {pos = {x=1835, y=980, z=11}, toPos = {x=2135, y=1066, z=9}, time = 300},
    ["Orshabaal"] = {pos = {x=1835, y=980, z=11}, toPos = {x=2135, y=1066, z=9}, time = 300}
}

function removeTpAndShowTime(tp, secondsRemaining, cid)
    if secondsRemaining == 0 then
        local t = getTileItemById(tp.pos, 1387).uid
        return t > 0 and doRemoveItem(t) and doSendMagicEffect(tp.pos, CONST_ME_POFF)
    end
    -- if cid no longer exists, find a random player to use instead
    if not isCreature(cid) then
        for _, pid in ipairs(getPlayersOnline()) do
            cid = pid
            break
        end
    end
    if isCreature(cid) then -- if no player is online, then don't show text
        doCreatureSay(cid, math.floor(secondsRemaining / 60) .. ":" .. (secondsRemaining % 60), TALKTYPE_ORANGE_1, false, 0, tp.pos)
    end
    addEvent(removeTpAndShowTime, 1000, tp, secondsRemaining - 1, cid)
end

function onDeath(cid)
    local tp = tps[getCreatureName(cid)]
    if tp then
        doCreateTeleport(1387, tp.toPos, tp.pos)
        doCreatureSay(cid, "O teleport irá sumir em "..tp.time.." segundos.", TALKTYPE_ORANGE_1)
        removeTpAndShowTime(tp, tp.time, cid)
    end
    return true
end
OMG @Xikini is best my friend, thanks <3
 
Top