local teleportCountdownRange = { --how close to the teleport to see the countdown? best to set to your viewport radiuses
x = 7, --default tibia client x radius
y = 5 --default tibia client y radius
}
local config = {
{
bossName = "demon",
area = {
from = Position(32320, 32210, 7),
to = Position(32322, 32213, 7),
},
teleportId = 1387,
teleportTime = 90,
teleportPos = Position(32320, 32218, 7),
teleportToPos = Position(32331, 32215, 7),
killMessage = "You have survived, and a portal has spawned for you.",
killMessageType = MESSAGE_EVENT_ADVANCE,
},
{
bossName = "dragon",
area = {
from = Position(32320, 32210, 7),
to = Position(32322, 32213, 7),
},
teleportId = 1387,
teleportTime = 90,
teleportPos = Position(32320, 32218, 7),
teleportToPos = Position(32331, 32215, 7),
killMessage = "You have survived, and a portal has spawned for you.",
killMessageType = MESSAGE_EVENT_ADVANCE,
},
}
local function countdownTeleport(eventId, timer)
local event = config[eventId]
if not event then
return
end
local teleport = event.teleport
if not teleport then
return
end
timer = timer - 1
if timer == 0 then
teleport:remove()
event.teleport = nil
return
end
local teleportPosition = teleport:getPosition()
local spectators = Game.getSpectators(teleportPosition, false, true, teleportCountdownRange.x, teleportCountdownRange.x, teleportCountdownRange.y, teleportCountdownRange.y)
if spectators then
for _, spectator in ipairs(spectators) do
spectator:say(timer, TALKTYPE_MONSTER_SAY, false, spectator, teleportPosition)
end
end
addEvent(countdownTeleport, 1000, eventId, timer)
end
local deathTeleportOnKill = CreatureEvent("deathTeleportOnKill")
function deathTeleportOnKill.onKill(player, target)
if not target:isMonster() then
return true
end
local monsterName = target:getName():lower()
for eventId, event in ipairs(config) do
if monsterName == event.bossName
and player:getPosition():isInRange(event.area.from, event.area.to)
and not event.teleport then
local teleport = Game.createItem(event.teleportId, 1, event.teleportPos)
if teleport then
teleport:setDestination(event.teleportToPos)
event.teleport = teleport
addEvent(countdownTeleport, 1000, eventId, event.teleportTime)
if event.killMessage and event.killMessageType then
local damageMap = target:getDamageMap()
if damageMap then
for playerId, _ in pairs(damageMap) do
local contributor = Player(playerId)
if contributor then
contributor:sendTextMessage(event.killMessageType, event.killMessage)
end
end
end
end
end
break
end
end
return true
end
deathTeleportOnKill:register()
--or register "deathTeleportLogin" on player login (data/creaturescripts/login.lua) and remove the code below
local deathTeleportLogin = CreatureEvent("deathTeleportLogin")
function deathTeleportLogin.onLogin(player)
player:registerEvent("deathTeleportOnKill")
return true
end
deathTeleportLogin:register()