local tpId = 1387
local requiredMonsterCount = 3 -- Number of monsters that need to be killed
local tpPosition = {x=761, y=57, z=7} -- Position where the teleport will be created
local tpToPosition = {x=767, y=52, z=7} -- Position where the teleport will take players
local tpTime = 30 -- Time in seconds that the teleport will be open
local monsters = {
["Demon"] = 1,
["Rat"] = 2,
["Dragon"] = 3,
}
function removeTp()
local t = Tile(tpPosition):getItemById(tpId)
if t then
t:remove()
tpPosition:sendMagicEffect(CONST_ME_POFF)
end
end
function hasPlayerKilledRequiredMonsters(player)
local count = 0
for _, monsterId in pairs(monsters) do
if player:getStorageValue(monsterId) == 1 then
count = count + 1
end
end
return count >= requiredMonsterCount
end
function onDeath(creature, corpse, killer, mostDamage, lastHitUnjustified)
local monsterName = creature:getName()
local monsterId = monsters[monsterName]
if monsterId then
creature:setStorageValue(monsterId, 1)
if hasPlayerKilledRequiredMonsters(creature) then
Game.createTeleport(tpId, tpPosition, tpToPosition)
creature:say("You killed the three monsters! A teleport has been created.", TALKTYPE_ORANGE_1)
addEvent(removeTp, tpTime * 1000)
end
end
return true
end