• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

RevScripts Boss mechanic: Second boss does damage to first

Icaraii

Well-Known Member
Joined
Jan 5, 2020
Messages
469
Solutions
1
Reaction score
58
Hi guys, TFS 1.3

I would like to implement a mechanic for a boss that the player enters in the boss room and faces the first boss (but he is imune) and from time to time, a custom demon will spawn and the player has to kill it, once the player kill the demon, a portal will spawn on the demon body or on a specific position (x,y,z) and the player need to enter the portal to go to a second location and face on of the many parts of the boss (second boss). Everytime the player kill the second boss, the first boss (imune one) will lose 25% of health.

I think thats a great mechanic, but it seems very dificult to do that ina script.
 
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.
 
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.
Yeah I really should try harder to do those on my own, I know a lot about a lot of parts of script (decay to, transform to, all about item.xml, monsters, 90% about spells (I really did a lot of great spells) 100% about sprites (also got awesome sprites to my server), weapons scripts and other stuff, but specific stuff I have a really hard time like script structure, functions and what should come first and second. I'm very good in seeing something like what I need and trying to edit to what I want and you are a big inspiration for me, you show me so much well made and easy to ready scripts.

I will try to make the next boss mechanic on my own and I will show it to you.
 

Similar threads

Back
Top