potinho
Advanced OT User
Hello guys, i tried to adapt an anihilator script to create some bossrooms, monster is summoned and player position are validating, but when new players try to jump in, they can. Script is not validating players inside room or cleaning previous bosses created. What im doing wrong? None errors on console.
Lua:
local config = {
questLevel = 300,
minimumPlayersRequired = 2,
playerPositions = {
{start = {x=1893, y=447, z=11}, destination = {x=1801, y=472, z=9}},
{start = {x=1894, y=447, z=11}, destination = {x=1802, y=472, z=9}},
{start = {x=1895, y=447, z=11}, destination = {x=1803, y=472, z=9}},
{start = {x=1896, y=447, z=11}, destination = {x=1804, y=472, z=9}},
{start = {x=1893, y=448, z=11}, destination = {x=1801, y=471, z=9}},
{start = {x=1894, y=448, z=11}, destination = {x=1802, y=471, z=9}},
{start = {x=1895, y=448, z=11}, destination = {x=1803, y=471, z=9}},
{start = {x=1896, y=448, z=11}, destination = {x=1804, y=471, z=9}}
},
spawnMonsters = {
{position = {x=1812, y=452, z=9}, monster = "Ulquiorra"}
},
roomPosition = {from = {x = 1800, y = 443, z = 9}, to = {x = 1819, y = 474, z = 9}},
kickTime = 1 * 60,
kickPosition = {x = 1899, y = 448, z = 11},
lastEventUlquiorra = 0
}
function getCreaturesOnRoom()
local creatures = {
monsters = {},
players = {}
}
for x = config.roomPosition.from.x, config.roomPosition.to.x do
for y = config.roomPosition.from.y, config.roomPosition.to.y do
local thing = getTopCreature({x = x, y = y, z = config.roomPosition.from.z})
if thing.uid > 0 then
local type = isPlayer(thing.uid) and "players" or "monsters"
creatures[type][#creatures[type] + 1] = thing.uid
end
end
end
return creatures
end
function resetRoom(creatures)
creatures = creatures or getCreaturesOnRoom()
if #creatures.monsters > 0 then
for i = 1, #creatures.monsters do
local monster = creatures.monsters[i]
if isCreature(monster) then
doRemoveCreature(monster)
end
end
end
if #creatures.players > 0 then
for i = 1, #creatures.players do
local pid = creatures.players[i]
if isPlayer(pid) then
doTeleportThing(pid, config.kickPosition)
doSendMagicEffect(getThingPosition(pid), CONST_ME_TELEPORT)
end
end
end
end
function onUse(cid, item, frompos, item2, topos)
if item.uid ~= 9102 then
return true
end
local players = {}
for i = 1, #config.playerPositions do
local topPlayer = getTopCreature(config.playerPositions[i].start).uid
if topPlayer > 0 and isPlayer(topPlayer) and getPlayerLevel(topPlayer) >= config.questLevel then
players[#players + 1] = topPlayer
end
end
if #players < config.minimumPlayersRequired then
doPlayerSendCancel(cid, "Sorry, not enough players.")
return false
end
local creatures = getCreaturesOnRoom()
if #creatures.players > 0 then
doPlayerSendCancel(cid, "There are players inside.")
return false
end
if #creatures.monsters > 0 then
resetRoom(creatures)
end
for i = 1, #players do
doSendMagicEffect(getThingPosition(players[i]), CONST_ME_POFF)
doTeleportThing(players[i], config.playerPositions[i].destination)
doSendMagicEffect(getThingPosition(players[i]), CONST_ME_TELEPORT)
end
for i = 1, #config.spawnMonsters do
doCreateMonster(config.spawnMonsters[i].monster, config.spawnMonsters[i].position)
doSendMagicEffect(config.spawnMonsters[i].position, CONST_ME_TELEPORT)
end
if config.kickTime > 0 then
stopEvent(config.lastEventUlquiorra)
config.lastEventUlquiorra = addEvent(resetRoom, config.kickTime * 1000)
end
return doTransformItem(item.uid, item.itemid == 1945 and 1946 or 1945)
end