• 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 specif ground heal boss

Icaraii

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

I would like a script that when the boss step on a specific ground id, it spawn a creature and this creature will heal the boss. Can someone help me with that?
 
There's a ton of ways to do this.. but here's an extremely simple way.

Lua:
local bossName = "Cave Rat"
local summonName = "Rat"
local healingRate = 2000
local healingAmount = {min = 50, max = 100}



local function summonHealBoss(bossId, summonId, healingRate, healingAmount)
    local boss = Creature(bossId)
    if not boss then
        return
    end
    local summon = Creature(summonId)
    if not summon then
        return
    end

    local maxhealth = boss:getMaxHealth()
    local currentHealth = boss:getHealth()

    if currentHealth < maxhealth then
        local healthToAdd = math.random(healingAmount.min, healingAmount.max)
        healthToAdd = math.min(healthToAdd, (maxhealth - currentHealth))
        boss:addHealth(healthToAdd)
        boss:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
        summon:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
    end

    addEvent(summonHealBoss, healingRate, bossId, summonId, healingRate, healingAmount)
end


local moveevent = MoveEvent()

function moveevent.onStepIn(creature, item, position, fromPosition)
    if creature:getName():lower() ~= bossName:lower() then
        return true
    end
    local spawnedCreature = Game.createMonster(summonName:lower(), creature:getPosition(), true, true, CONST_ME_TELEPORT)
    if not spawnedCreature then
        return true
    end
    summonHealBoss(creature:getId(), spawnedCreature:getId(), healingRate, healingAmount)
    return true
end

moveevent:register()
 
There's a ton of ways to do this.. but here's an extremely simple way.

Lua:
local bossName = "Cave Rat"
local summonName = "Rat"
local healingRate = 2000
local healingAmount = {min = 50, max = 100}



local function summonHealBoss(bossId, summonId, healingRate, healingAmount)
    local boss = Creature(bossId)
    if not boss then
        return
    end
    local summon = Creature(summonId)
    if not summon then
        return
    end

    local maxhealth = boss:getMaxHealth()
    local currentHealth = boss:getHealth()

    if currentHealth < maxhealth then
        local healthToAdd = math.random(healingAmount.min, healingAmount.max)
        healthToAdd = math.min(healthToAdd, (maxhealth - currentHealth))
        boss:addHealth(healthToAdd)
        boss:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
        summon:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
    end

    addEvent(summonHealBoss, healingRate, bossId, summonId, healingRate, healingAmount)
end


local moveevent = MoveEvent()

function moveevent.onStepIn(creature, item, position, fromPosition)
    if creature:getName():lower() ~= bossName:lower() then
        return true
    end
    local spawnedCreature = Game.createMonster(summonName:lower(), creature:getPosition(), true, true, CONST_ME_TELEPORT)
    if not spawnedCreature then
        return true
    end
    summonHealBoss(creature:getId(), spawnedCreature:getId(), healingRate, healingAmount)
    return true
end

moveevent:register()
Awesome, I have a few other ideas for boss mechanics, I will request some of them in a few days, thank you so much, I'm trying to learn as much as I can with your scripts.
 
Awesome, I have a few other ideas for boss mechanics, I will request some of them in a few days, thank you so much, I'm trying to learn as much as I can with your scripts.
minor detail I forgot
above moveevent:register() you have to register the tile with something.. probably an actionId

so add this
moveevent:aid(45001) -- or w/e actionId you haven't used before.
 
Back
Top