dfs1
Member
- Joined
- Aug 27, 2011
- Messages
- 75
- Solutions
- 1
- Reaction score
- 5
The script works perfectly, only if I kill the boss before the kick doesn't kick the player out, but if I don't kill the boss the boss disappears and kicks me out of the room.
I pass the script that I am using.
I pass the script that I am using.
Lua:
local config = {
leverUniqueID = 49006,
requiredLevel = 100,
daily = true,
bossName = "dragon",
storage = 7500,
roomCenterPosition = Position(423, 483, 7),
playerPositions = {
Position(425, 488, 7),
Position(424, 488, 7),
Position(423, 488, 7),
Position(422, 488, 7),
Position(421, 488, 7)
},
teleportPosition = Position(423, 481, 7),
bossPosition = Position(426, 485, 7),
kickMinutes = 2, -- minutes
kickPosition = Position(423, 490, 7)
}
local leverBoss = Action()
function leverBoss.onUse(player, item, fromPosition, target, toPosition, isHotkey)
if item:getId() == 1945 then
if player:getPosition() ~= config.playerPositions[1] then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You can\'t start the battle.")
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:sendCancelMessage("Not all players are ready yet from last battle.")
return true
end
participants[#participants +1] = participant
end
end
end
for _, spectator in pairs(Game.getSpectators(config.roomCenterPosition, false, false, 3, 3, 3, 3)) 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:setStorageValue(config.storage, os.time() + 20*60*60)
end
config.teleportPosition:sendMagicEffect(CONST_ME_ENERGYAREA)
config.kickEventId = addEvent(function ()
for _, spectator in pairs(Game.getSpectators(config.roomCenterPosition, false, false, 3, 3, 3, 3)) do
if spectator:isPlayer() then
spectator:teleportTo(config.kickPosition, false)
spectator:sendCancelMessage("Time is up!")
else
spectator:remove()
end
end
config.kickPosition:sendMagicEffect(CONST_ME_TELEPORT)
end, config.kickMinutes * 60 * 120)
end
item:transform(1945)
return true
end
leverBoss:uid(config.leverUniqueID)
leverBoss:register()
local cancelKickEvent = CreatureEvent("CancelKickEvent")
function cancelKickEvent.onDeath(...) stopEvent(config.kickEventId) return true end
cancelKickEvent:register()