MV Chance to Block Mechanic

I just wanted to share the block mechanic I created for my game. Basically, if a shield is equipped, it grants a passive state that gives the shield bearer a % chance to reduce incoming physical damage by half. The likelihood of this effect scales w/ DEF.

1st add this notetag to the shield in question (or all shields, like I do in my game):
Code:
<Passive State: 42>
Of course you're gonna want to change "42" to w/e stateID corresponds w/ the block state we're about to make.

Next, create a state w/ the following code for the block effect:
Code:
<Custom React Effect>
if (value > 0 && this.isHpEffect() && this.isPhysical()) {
  var blockChance = (user.def / 1000) + 0.05;
  var blockText = target.name() + ' blocked ';
  if (Math.random() < blockChance) {
    value = Math.round(value / 2);
    blockText = blockText + value + ' damage!';
    $gameMessage.add(blockText);
  }
}
</Custom React Effect>

Alternatively, you could give the <Passive State: #> notetag to an actor or class instead, but you'll have to use this line instead:
Code:
if (user.isWtypeEquipped(6) && value > 0 && this.isHpEffect() && this.isPhysical()) {
For my game, shields are classified as a Weapon and is #6 in the database. If your shields fall under the Armor category you're gonna want to use "user.isAtypeEquipped(#)" instead.

Finally, feel free to adjust the formula for blockChance as you see fit. For my game, 1 point of DEF adds 0.1% chance to block plus a 5% base chance. So 100 DEF would mean 15% block chance.

Edit: I had to change "value /= 2;" to "value = Math.round(value / 2);" so we don't get decimal results lol.
That looks really cool.
This is very useful, i was using alistair's ap_blocking but now that i actually tested it, it doesnt seem to be working :/

Is it possible to add a animation to play when blocking? i havent really tried this kind of stuff much yet

I actually love the pop up window, the battle text often go by so fast that i cant tell what happend 😛 Any code for moving the window or making it smaller? (i really need to learn how to do stuff like this)
I'm pretty noob at JS myself, and just whipped this up in like 5 mins lol. I'm sure there's a way to specify all the window parameters, but I just use SRD's Super Tools plugin. As for animations, it's definitely possible and shouldn't be hard. I just haven't gotten around to it yet cuz I haven't even begun on art/music/etc... So those are things in the back-burner for me rn. Hopefully somone w/ more JS experience can chime in, cuz I'd like to know the answers to ur questions as well.

Edit: Here's what you need for animations...
Code:
user.startAnimation(#);
Just replace # w/ whichever animation you want.
I'm pretty noob at JS myself, and just whipped this up in like 5 mins lol. I'm sure there's a way to specify all the window parameters, but I just use SRD's Super Tools plugin. As for animations, it's definitely possible and shouldn't be hard. I just haven't gotten around to it yet cuz I haven't even begun on art/music/etc... So those are things in the back-burner for me rn. Hopefully somone w/ more JS experience can chime in, cuz I'd like to know the answers to ur questions as well.


Edit: Here's what you need for animations...
Code:
user.startAnimation(#);
Just replace # w/ whichever animation you want.

Cheers!
I tried using Super tools but it just reset, but maybe that's just in battle test 😛
Would also be cool to be able to upgrade the block chance and value on gear and/or passives 😛
Would also be cool to be able to upgrade the block chance and value on gear and/or passives 😛
Easy! I actually intend to but just haven't gotten around to it yet. I plan to create an actor variable, which I will then reference in the block state. So certain equipment could increase this variable, thus increasing block chance!

My game is full of secondary stats, to give players more customization besides just the primary 6 stats. It'll be stuff like: Hit, Crit, Counter, Evasion, Resistance (Magic Evasion), Crit Evasion, Armor Penetration, Spell Penetration, & now Block. ^.^
All those stats besides block and penetrations are already in the engine, do you want your own versions?
All those stats besides block and penetrations are already in the engine, do you want your own versions?
I'm using them because they're already in the engine. 😉
Armor penetration is from Yanfly's YEP_X_ArmorScaling plugin.
I had to create block myself tho.

Btw, I created a passive called "Armor Meister": Plate armor no longer drains your Focus. In addition, bonus Block chance gained from your DEF value is doubled.
Code:
<Custom React Effect>
if (value > 0 && this.isHpEffect() && this.isPhysical()) {
  var blockChance = (user.def / 1000) + 0.05;
  var blockText = target.name() + ' blocked ';
  if (user.isLearnedSkill(81) && Math.random() < (blockChance * 2 - 0.05)) {
    value = Math.round(value / 2);
    blockText = blockText + value + ' damage!';
    $gameMessage.add(blockText);
  } else if (Math.random() < blockChance) {
    value = Math.round(value / 2);
    blockText = blockText + value + ' damage!';
    $gameMessage.add(blockText);
  }
}
</Custom React Effect>
So I had to update my code to take advantage of this new passive skill.

Original thread: https://forums.rpgmakerweb.com/threads/chance-to-block-mechanic.122618/