dfs1
Member
- Joined
- Aug 27, 2011
- Messages
- 75
- Solutions
- 1
- Reaction score
- 5
Good morning, could you help me with this script, it works correctly, only when you pull the lever from another position than in front and there are players inside the room, the boss erases them.
Lua:
local config = {
leverUniqueID = 49210,
requiredLevel = 110,
daily = true,
bossName = "rat",
storage = 7777,
roomCenterPosition = Position(577, 478, 5),
playerPositions = {
Position(580, 479, 6),
Position(580, 478, 6),
Position(580, 580, 6)
},
teleportPosition = Position(578, 479, 5),
bossPosition = Position(577, 478, 5),
kickMinutes = 15, -- minutes
kickPosition = Position(503, 503, 7)
}
local rat = Action()
function rat.onUse(player, item, fromPosition, target, toPosition, isHotkey)
if item:getId() == 1945 then
if player:getPosition() ~= config.playerPositions[1] then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Stand in front of the book..")
return true
end
local participants = {}
for _, playerPos in pairs(config.playerPositions) do
local tile = Tile(playerPos)
if tile then
local participant = tile:getTopCreature()
if participant and participant:isPlayer() then
if participant:getLevel() < config.requiredLevel then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("All the players need to be level %d or higher.", config.requiredLevel))
return true
end
if config.daily and participant:getStorageValue(config.storage) > os.time() then
player:getPosition():sendMagicEffect(CONST_ME_POFF)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Not all the players are ready yet since the last battle, they have to wait 1 hrs.")
return true
end
participants[#participants +1] = participant
end
end
end
for _, spectator in pairs(Game.getSpectators(config.roomCenterPosition, false, false, 5, 5, 5, 5)) do
if spectator:isPlayer() then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "A team is already inside the boss room.")
return true
end
spectator:remove()
end
local boss = Game.createMonster(config.bossName, config.bossPosition)
if boss then boss:registerEvent("CancelKickEvent") end
for _, participant in pairs(participants) do
participant:getPosition():sendMagicEffect(CONST_ME_POFF)
participant:teleportTo(config.teleportPosition)
participant:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have 10 minute(s) to defeat the boss.')
participant:setStorageValue(config.storage, os.time() + 0*60*60)
end
config.teleportPosition:sendMagicEffect(CONST_ME_ENERGYAREA)
config.kickEventId = addEvent(function ()
for _, spectator in pairs(Game.getSpectators(config.roomCenterPosition, false, false, 5, 5, 5, 5)) do
if spectator:isPlayer() then
spectator:teleportTo(config.kickPosition, false)
spectator:sendTextMessage(MESSAGE_EVENT_ADVANCE,"Time is out!")
else
spectator:remove()
end
end
config.kickPosition:sendMagicEffect(CONST_ME_TELEPORT)
end, config.kickMinutes * 1000 * 60)
end
item:transform(1945)
return true
end
rat:uid(config.leverUniqueID)
rat:register()