Greetings.
For my first state copy paste, I figured I’d go for one of the first custom states I’d made, Block Chance. In my project, a hero who has a shield equipped has a chance to block when taking physical damage. This chance is different depending on what type of shield the actor has, with a buckler being the least effective, at a 1% chance, and a heavy shield offering a 15% chance to block.
When a block occurs, an animation is shown on the actor, and he takes no damage from the attack. This animation can also be different based on the type of shield, or, if you’re willing to put in some effort, the individual shield equipped can show different animations as well.
What do you need to set this up?
Setup Steps:
The Code
This is the copy-paste text that needs to go in your note box for the block chance state.
<Custom React Effect>
//this section occurs when the afflicted target is hit by an attack
if (value > 0 && this.isHpEffect() && this.isPhysical()) {
// checking if this was a valid physical attack to block
var rnd = (Math.floor(Math.random() * 99 + 1)) // random value from 1-100
var imp = target.isStateAffected(36); // see bonus section
var sng = target.isStateAffected(179); // see bonus section
var shd = $dataArmors[$gameActors._data[target.actorId()]._equips[1]._itemId].atypeId
// the above variable is storing what armor type the equipped shield is
var per = 0 // the default chance to block
if (shd == 1) { // if the shield is type 1 (common) it is a buckler
per = 1 // base block chance of buckler = 1%
}
if (shd == 5) { // type 5 for my project is light shield
per = 10 // base block chance of light shield is 10%
}
if (shd == 6) { //type 6 for my project is heavy shield
per = 15 // base block chance of heavy shield is 15%
}
per = per + (imp * 10) + (sng * 30)
// the above line is adding bonus for block chance based on other states
// I will cover this below in more detail.
if (rnd < per){
// if the random number we generated is within the value of 'per' a block has
// occurred
value -= value; // makes the attack do no damage
if (target.equips()[1].baseItemId == 7){
//this if statement is checking for a specific shield to be equipped
//it then shows the specific animation for that shield.
target.startAnimation(165, true, 0);
}else if (shd == 6) {
// if you have a heavy shield, show the heavy shield animation
target.startAnimation(131, true, 0);
}else if (shd == 5) {
// if you have a light shield, show the light shield animation
target.startAnimation(163, true, 0);
}else{
// if you don't have either heavy or light, you must be using a buckler show that
target.startAnimation(161, true, 0);
}
}
}
</Custom React Effect>
Bonus
In the above code we have two states that increase the block chance by 10% and 30% respectively. The first is labeled ‘imp’, and is short for improved block, or shield mastery. My project makes use of an ‘equip skills’ system to allow a lot of depth in customizing the actors, one such skill learned from a shield bearing class increases their base chance to block by 10%. This was simple enough to put into the state, as seen. The second state, ‘sng’, is short for song, and is an active buff that my bard characters can place on allies, which increases block chance by 30%. You can add as many of these states as you like, to increase block chance more and more, but be sure you add in some extra math to make sure the value doesn’t exceed 100%, or the block may actually fail when the value rolls over.
You can also add in some extra if…else checks to look for specific shields to set the base block to be per shield, instead of per type. If you’re familiar with javascript, you can even add these values to shields themselves, and use this react effect to simply pull the values from the item directly, instead of manually in the note tag like we’ve done here.
How does it look?
See for yourself
That’s all for today.
~Ramza