Code: Select all
function switchcandle()
candle1.model:enable()
candle2.model:disable()
candle1.light:enable()
candle2.light:disable()
end
function switchback()
candle1.model:disable()
candle2.model:enable()
etc.
end
K.
Code: Select all
function switchcandle()
candle1.model:enable()
candle2.model:disable()
candle1.light:enable()
candle2.light:disable()
end
function switchback()
candle1.model:disable()
candle2.model:enable()
etc.
end
Code: Select all
function hitMonster(self, attack, monster, tside, damage, champion)
local damageType = attack:getDamageType()
if damageType == "physical" or not damageType then
local dmg = damage
local pierce = attack:getPierce()
local protection = monster:getProtection()
if pierce then
protection = protection - pierce
end
if protection > 0 and protection < 100 then
dmg = math.max(1, math.floor(dmg * (1 - (protection * .01))))
elseif protection >= 100 then
dmg = 1
else -- protection <= 0
-- do nothing
end
local dmgText = ""..dmg
monster:setHealth(monster:getHealth() - dmg)
monster:showDamageText(dmgText, "FFFFFF")
playSoundAt(monster:getHitSound(), monster.go.level, monster.go.x, monster.go.y)
if monster:getHealth() <= 0 then
monster:die()
else
if monster:getHitEffect() then
local particle = spawn("particle_system", monster.go.level, monster.go.x, monster.go.y, monster.go.facing, monster.go.elevation)
particle.particle:setParticleSystem(monster:getHitEffect())
particle:setWorldPositionY(monster:getCapsuleHeight())
end
if not monster:getCurrentAction() and not monster:isPerformingAction("damaged") then
if tside == 0 then
if champion == party.party:getChampion(1) or champion == party.party:getChampion(3) then
monster.go.animation:play("getHitFrontRight")
else
monster.go.animation:play("getHitFrontLeft")
end
elseif tside == 1 then
monster.go.animation:play("getHitRight")
elseif tside == 2 then
monster.go.animation:play("getHitBack")
elseif tside == 3 then
monster.go.animation:play("getHitLeft")
end
end
end
end
end
Hey Huff!Huff wrote: ↑Sun Sep 09, 2018 5:31 pm I'm attempting to replicate the attack functionality for hitting monsters in the onHitMonster hook for weapons. My goal is to be able to use custom damage formulas that change protection to a percentage based 0 to 100% instead of flat addition and subtraction.
Everything here works except for the monster's interrupted state. Currently, this just plays the animation of getting hit, but doesn't actually put them in the "damaged" action state which stops them from attacking, moving, etc.
One thing I have tried is disabling the monster's brain class temporarily with use of delayedCall, but it has mixed results since the number of frames on getHit animations varies. I think it may also break scripted monsters too.
I'm wondering if there's some built-in function I'm not seeing like monster:performAction("damagedFrontRight").
Code: Select all
onHitMonster = function(self, monster)
if monster:isAlive() and not monster:isFalling() and monster:getCurrentAction() ~= "knockback" then
monster.go:setPosition(monster.go.x,monster.go.y,monster.go.facing,monster.go.elevation,monster.go.level)
monster:knockback(party.facing)
end
end,
Perhaps this can help??Setting a monster's position is the easiest way to interrupt monster actions.
Code: Select all
function monsterDamageAnimation(monster, anim)
if monster:getCurrentAction() == nil then
if not monster.go.damaged then
monster.go:createComponent("MonsterAction","damaged")
end
monster.go.damaged:setAnimation(anim)
monster:performAction("damaged")
end
Ahhh this is good news indeed!
This is also all very good news!minmay wrote: ↑Thu Sep 13, 2018 6:08 am Said "damaged" component is just a plain MonsterActionComponent without any special frills. This would be the code for recreating that behaviour:Call this every time a monster gets hit for more than 0 damage by something with the DamageFlags.Impact flag. The monster parameter should be the MonsterComponent and the anim parameter should be the name of the animation to play ("getHitBack", "getHitFrontLeft", "getHitFrontRight", "getHitLeft", or "getHitRight").SpoilerShowCode: Select all
function monsterDamageAnimation(monster, anim) if monster:getCurrentAction() == nil then if not monster.go.damaged then monster.go:createComponent("MonsterAction","damaged") end monster.go.damaged:setAnimation(anim) monster:performAction("damaged") end
If you wish to interrupt the current action, then you could use that setPosition hack I described first, but keep in mind that this would be undesirable for a lot of actions (such as moving).