Here is yet another way to do it...
Code: Select all
-- Added to the monster component. Function expects the monsters to have the same name, and the id suffix '_twin1' and '_twin2'
onDamage = function(self, damage, damageType)
--if damageType ~= "fire" then --optional filter for monsters with tile damager fire attacks (that would trigger self healing)
for x = 1, 2 do
if not self.go.id:match(x) then
local twin = findEntity(self.go.name.."_twin"..x)
if twin and twin.monster:getHealth() > self.go.monster:getHealth() then
self.go.monster:showDamageText("\n\nHealed by\nTwin's Essence!", vec(200,200,256)) self.go.monster:setHealth(twin.monster:getHealth())
--optional healing effect [can be commented out]
if not self.go.effect then
local effect = self.go:createComponent("Particle", "effect")
effect:setParticleSystem("monster_heal")
effect:setDestroySelf(true)
end
-----------------------------
end
end
end
return true
--end
end,
-- Visible Healing particle effect [optional]
defineParticleSystem{
name = "monster_heal",
emitters = {
-- fog
{
emissionRate = 10,
emissionTime = 0,
maxParticles = 1000,
spawnBurst = true,
boxMin = {-1.5, 0.0,-1.5},
boxMax = { 1.5, 3.0, 1.5},
sprayAngle = {0,360},
velocity = {0.1,1},
objectSpace = true,
texture = "assets/textures/particles/fog.tga",
lifetime = {3,3},
color0 = {0.190294, 0.365000, 0.450490},
opacity = 1,
fadeIn = 2,
fadeOut = 2,
size = {2, 2},
gravity = {0,0,0},
airResistance = 0.1,
rotationSpeed = 0.3,
blendMode = "Additive",
},
-- stars
{
emissionRate = 200,
emissionTime = 0,
maxParticles = 1000,
spawnBurst = true,
boxMin = {-1.5,-0.5,-1.5},
boxMax = { 1.5, 2.5, 1.5},
sprayAngle = {0,30},
velocity = {0.5,1.5},
objectSpace = true,
texture = "assets/textures/particles/teleporter.tga",
lifetime = {1,1},
color0 = {1.8,1.8,1.8},
opacity = 1,
fadeIn = 0.1,
fadeOut = 0.1,
size = {0.1, 0.3},
gravity = {0,-1,0},
airResistance = 0.1,
rotationSpeed = 2,
blendMode = "Additive",
},
-- small stars
{
emissionRate = 300,
emissionTime = 0,
maxParticles = 1000,
spawnBurst = true,
boxMin = {-1.5,-0.5,-1.5},
boxMax = { 1.5, 2.5, 1.5},
sprayAngle = {0,30},
velocity = {0.5,1.0},
objectSpace = true,
texture = "assets/textures/particles/teleporter.tga",
lifetime = {1,1},
color0 = {1.6,1.8,1.8},
opacity = 1,
fadeIn = 0.1,
fadeOut = 0.1,
size = {0.05, 0.1},
gravity = {0,-0.5,0},
airResistance = 0.1,
rotationSpeed = 2,
blendMode = "Additive",
}
}
}
I found it to be a fun fight.