local config = {
storage = {
key = Storage.TheCallinKalys.Mission01,
requiredValue = 1,
newValue = 2
},
positions = {
origin = Position(32890, 31883, 9),
destination = Position(32816, 32260, 5)
},
teleportActionId = 32816,
teleportItemId = 20121,
teleportDecay = 180 -- seconds
}
local bossDamageMap = {} -- don't edit
local function removeTeleport(position, teleportItemId)
local tile = Tile(position)
if not tile then
print("Error: tile not found at location")
return
end
local teleport = tile:getItemById(teleportItemId)
if not teleport then
return
end
teleport:remove()
end
local function countDown(timer, position)
if timer % 5 == 0 and timer ~= 0 then
for _, creature in pairs(Game.getPlayers()) do
creature:say(timer, TALKTYPE_MONSTER_SAY, false, nil, position)
break
end
end
if timer > 0 then
addEvent(countDown, 1000, timer - 1, position)
end
end
local creatureevent = CreatureEvent("KillBossDeath")
function creatureevent.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
-- create and remove teleport
local teleport = Game.createItem(config.teleportItemId, 1, config.positions.origin)
teleport:setActionId(config.teleportActionId)
addEvent(removeTeleport, 1000 * config.teleportDecay, config.positions.origin, config.teleportItemId)
countDown(config.teleportDecay, config.positions.origin)
creature:say("YOU HAVE LITTLE TIME TO ENTER THE PORTAL!", TALKTYPE_ORANGE_1)
-- setup damage map
bossDamageMap = {}
for creatureId, damage in pairs(creature:getDamageMap()) do
local _creature = Creature(creatureId)
if _creature then
local master = _creature:getMaster()
if master and master:isPlayer() then
_creature = master
end
if _creature:isPlayer() then
local name = _creature:getName()
bossDamageMap[name] = (bossDamageMap[name] or 0) + damage.total
end
end
end
return true
end
creatureevent:register()
local moveevent = MoveEvent()
function moveevent.onStepIn(creature, item, position, fromPosition)
if not creature:isPlayer() then
creature:teleportTo(fromPosition, true)
return false
end
-- if quest is not started, don't allow access to portal
if creature:getStorageValue(config.storage.key) < config.storage.requiredValue then
creature:say("Quest not started.", TALKTYPE_ORANGE_1, false, creature)
creature:teleportTo(fromPosition, true)
return false
end
-- if no damage to boss, don't allow access to portal
if not bossDamageMap[creature:getName()] then
creature:say("This character dealt no damage to the boss.", TALKTYPE_ORANGE_1, false, creature)
creature:teleportTo(fromPosition, true)
return false
end
-- if portal hasn't been entered before, update storage
if creature:getStorageValue(config.storage.key) == config.storage.requiredValue then
creature:setStorageValue(config.storage.key, config.storage.newValue)
end
creature:teleportTo(config.positions.destination)
return true
end
moveevent:type("stepin")
moveevent:aid(config.teleportActionId)
moveevent:register()