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()