Lightning Shield

This week I’m going with another added effect state. Lightning shield is an active buff state that causes the affected battler to discharge lightning to all enemies when hit by a physical attack.

This state paste code will make use of our new plugin that I just released earlier today, which will make the copy + paste code for it much simpler to use and read. The plugin handles the calculations of the waiting and does the damage popups automatically based on the animation Id used.

So lets just jump into it.

What you need:

Our first state is the shield state. This is the state that is applied to the target when the lightning shield spell is cast on them. It has a turn duration, and some info in the note box.

lightningshieldstate

Here is the copy-paste code for this state:

<Custom React Effect>
if (this.isHpEffect() && this.isPhysical() && !target.isStateAffected(27)){
 user.addState(27)
 target.startAnimation(77, false, 0)
 for (i = 0; i < $gameTroop.members().length; i++){
  if (!$gameTroop.members()[i].isDead()){
   $gameTroop.members()[i].shddmg = origin.mat * 2
   target.addState(27)
   performStateAnimationDmg2(76, $gameTroop.members()[i], (Math.floor(($gameTroop.members()[i].shddmg) * ((Math.random()*40)+80)/100)), 4);
   $gameTroop.members()[i].shddmg = undefined
  }
 }
}
</Custom React Effect>
<Custom Deselect Effect>
target.removeState(27)
</Custom Deselect Effect>

StateId 27 is used as a fail safe to make sure that a lightning shield doesn’t trigger multiple times on the same action. Without it being applied and checked for, an attack that hit’s three times would trigger the shield three times as well.

The results?:

Have a look for yourself.

Added Effect Plugin

As I said when I first created this blog a little over two months ago, occasionally I will release plugins here as well as state codes.

With this weeks state, I have made the paste code simpler by including a function that performs the state animations, and calculates the amount of time waited before the damage popup automatically. It contains a couple of different versions of the same thing, which react differently when multiple animations are played, or when there are multiple targets of a state animation.

The idea of this plugin is simply to make the paste codes easier to read. It adds the following functions to the game engine, and can either be loaded as it’s own plugin, or have the code below pasted into a .js file of your own to add the functions to the game.

performStateAnimationDmg(animationId, target, damage, ele)

  • Takes the animation number provided and calculates the number of wait frame for the animation.
  • Shows the damage popup for damage, and does the elemental resistance calculation for the element on the target.
  • causes the enemy to do it’s flinch/damage pose after being hit
  • checks after damage if the target is dead, and performs collapse if so
  • checks after collapse if the enemy was the last one, and then ends the battle if true
  • if not, waits a short period and makes the target move back to position after flinching
  • Waits an extra 30 frames after the animation before the battle system continues

performStateAnimationDmg2(animationId, target, damage, ele)

  • Useful for state animations that affect multiple targets at the same time
  • Does the same thing as listed above with the following difference:
    • The waiting 30 extra frames at the end doesn’t happen, as it stacks in an aoe situation where the same animation is played on several battlers simultaneously, causing a huge wait after damage is dealt where the engine appears to hang.

performStateAnimationDmg3(animationId, target, damage, ele)

  • This version is the same as the first function, but doesn’t cause the flinching on the target, which is useful for states that do not cause damage, but still have a state animation, or for states that heal an ally using the same function, which should cause flinching.

All of this information is also in the help description of the javascript file. Please note that with the release of this plugin I will no longer be manually showing the settimeout functions used to delay the damage popup in any new added effect states, they will all make use of this plugin from today forward.

This plugin can be found here. Make sure that the filename does not change.

Enflame

This week I am showcasing a special type of states, the added effect. These states are special in that they cause an effect to happen after another action has taken place. The state this week is enflame, a single target buff spell that causes extra fire damage on a foe after being attacked.

This state is surprisingly technical, and I’ve already found a non-yanfly plugin that broke compatibility with it (an outdated plugin that I’m still using in my project), so it’s possible it might not entirely work for you. Let me know if there are any issues on your end.

How Does it Work?

This particular skill can be cast by one actor to affect another actor. When the affected actor makes a physical attack, the conditions for this state become true, and some extra fire elemental damage is dealt to the target. This has a separate animation, and a separate damage popup.

What you Need:

  • The usual plugins
  • A skill to apply the state
  • One state

Bonus:

I will include a more in depth explanation of the spaghetti code I’ve used and what each part of it does, to facilitate more easily using it for your own states.

The skill:

For this effect, I have a single target buff spell that can be used on the caster’s allies. It doesn’t really have anything special in it, aside from giving the state to the ally.

enflameskill

Next we need to make our state.

enflamestate

This state expires after a number of turns, like a lot of my states. Otherwise, the state itself does basically nothing. All of the effect is held in the note tags below:

<Custom Apply Effect>
target.enflameDmg = (origin.mat * 4)
// The above line sets the damage of the added effect
// origin is the caster of the spell, in this way the spell can have its 
// damage be based on the casting stats of the actor who applied it
if (target._name == origin._name){
 target._stateTurns[209] = target._stateTurns[209] + 1
// For this skill, I have made it so that if the caster uses it on himself
// its duration increases by one turn.
// In the CTB battle system, the actor's turn ends as soon as his action is
// over, causing the effect to last one less action than if he'd put it on 
// someone else
}
</Custom Apply Effect>
<Custom Conclude Effect>
if (target.result().isHit() && this.isHpEffect() && this.isPhysical() && target.hp > 0) {
 user.enfOn = true
 user.enfTarget = target
// This if statement is checking to see if the requirements for enflame have 
// been met. Because we can't interrupt the action just yet, this local variable
// is set on the user to denote that the effect will be triggered.
// This also doubles in preventing the effect from happening multiple times on 
// multi-hit skills
}else if (user.enfOn != true){
 user.enfOn = false
 user.enfTarget = null
// This else statement is preventing the added effect from not being applied, 
// if multiple actions had been taken, but the last one didn't meet the requirements
// eg. if a three hit attack had the third hit miss.
}
</Custom Conclude Effect>
<Custom Action End Effect>
if (user.enfOn == true && !user.enfTarget.isDead()) {
// If the effect was triggered, and the intended target isn't dead
  var extraFramesToWaitFor = 15;
  var animFrames = ($dataAnimations[178].frames.length * 4) + 1 + extraFramesToWaitFor;
  var waitSeconds = (animFrames/60) * 1000;
// These variables set up our wait time, which allows the animation to play before
//  the damage popup shows up.
  target.startAnimation(178, false, 0);
//Show the battle animation Id 178
  setTimeout(function () {
// everything below this line happens on a delay equal to waitSeconds above
    var total = Math.floor(user.enflameDmg * user.enftarget.elementRate(2))
// the above line adjusts the damage for elemental resistances
    user.enftarget.gainHp(-total); // deal damage
    user.enftarget.startDamagePopup(); // show the damage being dealt
    user.enftarget.performDamage(); // makes the affected battler do its damage pose
    if (user.enftarget.isDead()) {
        user.enftarget.performCollapse(); // kill the battler if it is now dead
    }
    BattleManager.checkBattleEnd(); // end the fight if this was the last unit alive
       setTimeout(function () {
// this second timeout waits 3 seconds after the damage popup and moves the 
// affected battler back into position after having been hit
        target.performActionEnd()
    }, 180);
  }, waitSeconds);
  BattleManager._logWindow._waitCount += (animFrames + 30);
// the above line makes the entire battle system wait for the specified time
// in this case, we add 30 frames to it, to ensure an enemy doesn't take an action
// while the damage popup is still on screen
  user.enfOn = false
// after the effect is complete, turn the local variable off, so it won't 
// trigger again on the same action.
}
</Custom Action End Effect>

Also, here is an action sequence for the skill, as mine is fancy and I don’t mind sharing it 🙂

<setup action>
camera clamp on
display action
immortal: targets, true
perform start
zoom: 300%
camera focus: user
wait for zoom
motion chant: user
cast animation
wait for animation
</setup action>
<target action>
motion spell: user
camera focus: target
zoom: 250%
wait for camera
motion attack: target
action animation: target
wait for animation
action effect: target
</target action>
<finish action>
perform finish
clear battle log
immortal: targets, false
reset camera
reset zoom
wait for camera
camera clamp on
</finish action>

How it looks:

See for yourself

That’s all for this update.

~Ramza

Edit: October 16, 2016 I have changed the paste code to correct an incorrect target issue, that would cause enflame to always deal damage to the battler who was using it, rather than the target of their attacks. If you were having this issue, please re-copy the code now. Thanks.