I know this is in requests, but I think you should be getting to the point where you can tackle this on your own, then if you get stuck ask for help. xD
You have the 'scripter brain', at this point. You can see what should happen, and the flow of events..
You just need to sit down and figure out each part separately, and then piece them altogether.
So let's start with the main boss.
You want him to be immune to damage?
Okay, so make a monster, and give him immunity to everything in the monster file.
Done.
Okay now you want a player to spawn the boss when they enter a room.
So make a stepIn tile, and spawn the boss.
Lua:
local spawnBoss = MoveEvent()
spawnBoss:type("stepin")
function spawnBoss.onStepIn(player, item, position, fromPosition)
if not player or player:isInGhostMode() then
return true
end
Game.createMonster("Boss Name", Position(1000, 1000, 7))
return true
end
spawnBoss:aid(45001)
spawnBoss:register()
Done.
Oh, you probably don't want the boss to be spawn multiple times.
So let's add that.
Lua:
local bossId = 0 -- track the boss
local spawnBoss = MoveEvent()
spawnBoss:type("stepin")
function spawnBoss.onStepIn(player, item, position, fromPosition)
if not player or player:isInGhostMode() then
return true
end
if bossId == 0 then
-- boss already spawned.
return true
end
local boss = Game.createMonster("Boss Name", Position(1000, 1000, 7))
bossId = boss:getId() -- track the boss
return true
end
spawnBoss:aid(45001)
spawnBoss:register()
local bossDeath = CreatureEvent("bossDeath")
function creatureevent.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
bossId = 0 -- if the boss dies, reset the bossId, so another one can spawn.
return true
end
creatureevent:register()
and inside the boss, register the script for onDeath
XML:
<script>
<event name="bossDeath"/>
</script>
Cool, done.
Alright.. now we want a demon to spawn randomly.. so make an onThink event or a looping addEvent..
I'm impartial to looping addEvents, because they only run when the boss is summoned..
so I'll do it that way.
Lua:
local spawnBoss = MoveEvent()
spawnBoss:type("stepin")
function spawnBoss.onStepIn(player, item, position, fromPosition)
if not player or player:isInGhostMode() then
return true
end
if bossId == 0 then
return true
end
local boss = Game.createMonster("Boss Name", Position(1000, 1000, 7))
bossId = boss:getId()
local rand = math.random(30, 60) -- add the looping addEvent when the boss spawns
addEvent(summonCreatureIntermittently, rand * 1000, bossId) -- add the looping addEvent when the boss spawns
return true
end
spawnBoss:aid(45001)
spawnBoss:register()
the looping addEvent
Lua:
local function summonCreatureIntermittently(mastersId)
local master = Creature(masterId)
if not master then
return
end
local summons = player:getSummons()
if #summons == 0 then
local summon = Game.createMonster("Demon", master:getPosition(), true, true, CONST_ME_TELEPORT)
summon:setMaster(master)
summon:setDropLoot(false)
summon:registerEvent("summonDeath")
end
local rand = math.random(30, 60)
addEvent(summonCreatureIntermittently, rand * 1000, mastersId)
end
We'll add a table, and a way to track the boss progression
Lua:
local bossProgression = 0
local teleports = {
[0] = {
teleportToPosition = Position(1000, 1000, 7),
teleportCreatePosition = Position(2000, 2000, 7)
},
[1] = {
teleportToPosition = Position(1000, 1000, 7),
teleportCreatePosition = Position(2000, 2000, 7)
},
[2] = {
teleportToPosition = Position(1000, 1000, 7),
teleportCreatePosition = Position(2000, 2000, 7)
},
[3] = {
teleportToPosition = Position(1000, 1000, 7),
teleportCreatePosition = Position(2000, 2000, 7)
}
}
and we'll make the summonDeath of the demon, and another function to remove the portal after x time. (set as 5 minutes.)
Lua:
local function removeTeleport(position)
local teleportItem = Tile(position):getItemById(1387)
if teleportItem then
teleportItem:remove()
position:sendMagicEffect(CONST_ME_POFF)
end
end
local summonDeath = CreatureEvent("summonDeath")
function creatureevent.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
if corpse:isItem() then
corpse:remove()
end
local index = teleports[bossProgression]
if index then
local teleport = Game.createItem(1387, 1, index.teleportCreatePosition)
if teleport:isTeleport() then
teleport:setDestination(index.teleportToPosition)
addEvent(removeTeleport, 5 * 60 * 1000, index.teleportCreatePosition)
end
end
return true
end
creatureevent:register()
So all in all, this is where we're at.
Lua:
local bossId = 0 -- track the boss
local bossProgression = 0 -- update this when 2nd/3rd/4th/5th boss's die
local teleports = {
[0] = {
teleportToPosition = Position(1000, 1000, 7),
teleportCreatePosition = Position(2000, 2000, 7)
},
[1] = {
teleportToPosition = Position(1000, 1000, 7),
teleportCreatePosition = Position(2000, 2000, 7)
},
[2] = {
teleportToPosition = Position(1000, 1000, 7),
teleportCreatePosition = Position(2000, 2000, 7)
},
[3] = {
teleportToPosition = Position(1000, 1000, 7),
teleportCreatePosition = Position(2000, 2000, 7)
}
}
local function summonCreatureIntermittently(mastersId)
local master = Creature(masterId)
if not master then
return
end
local summons = player:getSummons()
if #summons == 0 then
local summon = Game.createMonster("Demon", master:getPosition(), true, true, CONST_ME_TELEPORT)
summon:setMaster(master)
summon:setDropLoot(false)
summon:registerEvent("summonDeath")
end
local rand = math.random(30, 60)
addEvent(summonCreatureIntermittently, rand * 1000, mastersId)
end
local function removeTeleport(position)
local teleportItem = Tile(position):getItemById(1387)
if teleportItem then
teleportItem:remove()
position:sendMagicEffect(CONST_ME_POFF)
end
end
local spawnBoss = MoveEvent()
spawnBoss:type("stepin")
function spawnBoss.onStepIn(player, item, position, fromPosition)
if not player or player:isInGhostMode() then
return true
end
if bossId == 0 then
return true
end
local boss = Game.createMonster("Boss Name", Position(1000, 1000, 7))
bossId = boss:getId()
local rand = math.random(30, 60)
addEvent(summonCreatureIntermittently, rand * 1000, bossId)
return true
end
spawnBoss:aid(45001)
spawnBoss:register()
local bossDeath = CreatureEvent("bossDeath")
function creatureevent.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
bossId = 0
bossProgression = 0 -- reset the bossProgression as well.
return true
end
creatureevent:register()
local summonDeath = CreatureEvent("summonDeath")
function creatureevent.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
if corpse:isItem() then
corpse:remove()
end
local index = teleports[bossProgression]
if index then
local teleport = Game.createItem(1387, 1, index.teleportCreatePosition)
if teleport:isTeleport() then
teleport:setDestination(index.teleportToPosition)
addEvent(removeTeleport, 5 * 60 * 1000, index.teleportCreatePosition)
end
end
return true
end
creatureevent:register()
At this point.. you haven't described how you want the next boss's to spawn or how the player gets back from these locations..
But I imagine you should be able to do those parts on your own.
You just gotta take the tiny parts, make em.. then mash em together into the bigger picture.
You got this dude.