local configQuest = {
actionId = 901,
players = { -- Positions where players are standing to enter
Tile(3051, 1828, 8),
Tile(3051, 1829, 8),
Tile(3051, 1830, 8),
Tile(3051, 1831, 8),
Tile(3051, 1832, 8),
Tile(3051, 1833, 8),
Tile(3051, 1834, 8)
},
minPlayers = 1, -- Minimum number of players that can enter. in this case 1 or more
destination = Position(3056, 1831, 8), -- Position where the players will be teleported when entering the room
requirements = {
level = 2000, -- level required to enter the room
storages = {} -- if you need some storage to be able to enter or several storages
},
room = {
centerPos = Position(3068, 1831, 8), -- center of the room
fromPos = Position(3055, 1812, 8), -- the upper left corner of the room
toPos = Position(3084, 1844, 8) -- the lower right corner of the room
},
boss = {
name = "Demon", -- boss name
spawnPos = Position(3068, 1831, 8), -- spawn boss position
exitIn = 1 -- minutes to get out of the room
},
debug = {
enabled = false, -- for testing with /reload scripts
exitPos = Position(3051, 1826, 8), -- Position to which players will be sent off after a while
leverIds = {1945, 1946}, -- lever on / lever off
admins = false -- detect administrators in the room
}
}
local function getPlayersInQuest()
local spectators = Game.getSpectators(configQuest.room.centerPos, false, true, configQuest.radius.x, configQuest.radius.x, configQuest.radius.y, configQuest.radius.y)
local players = {}
for _, spectator in pairs(spectators) do
if spectator:getGroup():getId() == 1 or configQuest.debug.admins then
players[#players +1] = spectator
end
end
return players
end
local function closeQuest()
local ground = configQuest.players[1]:getGround()
for _, p in pairs(getPlayersInQuest()) do
p:teleportTo(configQuest.debug.exitPos)
end
local boss = Monster(ground:getCustomAttribute("bossId"))
if boss then
boss:remove()
end
ground:removeCustomAttribute("evId")
end
local action = Action()
function action.onUse(player, item, fromPos, target, toPos, isHotkey)
if not configQuest.radius then
configQuest.radius = {
x = math.ceil((configQuest.room.toPos.x - configQuest.room.fromPos.x) / 2),
y = math.ceil((configQuest.room.toPos.y - configQuest.room.fromPos.y) / 2)
}
end
local leverCanUse = false
local playerPosition = player:getPosition()
for _, tile in pairs(configQuest.players) do
leverCanUse = playerPosition == tile:getPosition()
if leverCanUse then
break
end
end
if not leverCanUse then
return false
end
local questPlayers = getPlayersInQuest()
for _, p in pairs(questPlayers) do
if configQuest.debug.enabled then
p:teleportTo(configQuest.debug.exitPos)
end
end
if configQuest.debug.enabled then
configQuest.debug.exitPos:sendMagicEffect(CONST_ME_TELEPORT)
end
local ground = configQuest.players[1]:getGround()
local boss = Monster(ground:getCustomAttribute("bossId"))
if boss then
if configQuest.debug.enabled or #questPlayers == 0 then
boss:remove()
stopEvent(ground:getCustomAttribute("evId"))
ground:removeCustomAttribute("evId")
else
player:sendCancelMessage(string.format("You must wait for the boss to be defeated or wait %d seconds.", ground:getCustomAttribute("now") - os.time()))
return true
end
end
local players = {}
for _, tile in pairs(configQuest.players) do
local p = tile:getTopCreature()
if p and p:isPlayer() then
if p:getLevel() < configQuest.requirements.level then
player:sendCancelMessage(string.format("%s must be level %d or higher.", p:getName(), configQuest.requirements.level))
p:getPosition():sendMagicEffect(CONST_ME_POFF)
return true
end
for _, storage in pairs(configQuest.requirements.storages) do
if p:getStorageValue(storage) == -1 then
player:sendCancelMessage(string.format("%s still cannot face this boss.", p:getName()))
p:getPosition():sendMagicEffect(CONST_ME_POFF)
return true
end
end
players[#players +1] = p
end
end
if #players < configQuest.minPlayers then
player:sendCancelMessage(string.format("Sorry, only groups of %d or more players are allowed.", configQuest.minPlayers))
return true
end
for _, p in pairs(players) do
p:getPosition():sendMagicEffect(CONST_ME_POFF)
p:teleportTo(configQuest.destination)
end
configQuest.destination:sendMagicEffect(CONST_ME_TELEPORT)
boss = Game.createMonster(configQuest.boss.name, configQuest.boss.spawnPos)
if boss then
ground:setCustomAttribute("bossId", boss:getId())
ground:setCustomAttribute("evId", addEvent(closeQuest, configQuest.boss.exitIn * 60 * 1000))
ground:setCustomAttribute("now", os.time() + (configQuest.boss.exitIn * 60))
end
item:transform(item:getId() == configQuest.debug.leverIds[1] and configQuest.debug.leverIds[2] or configQuest.debug.leverIds[1])
return true
end
action:aid(configQuest.actionId)
action:register()