Custom Hit Formula MZ

● ARCHIVED · READ-ONLY
Started by ATT_Turan 32 posts Page 1 of 2 View original ↗
  1. Custom Hit Formula 1.4
    ATT_Turan

    Introduction
    As far as I know, there's still no plugin written with the ability to provide a custom hit formula in MZ, and I got tired of telling people that :wink:

    (apparently caethyril actually had one and I didn't know about it! Well, now you can try both and tell us who you like better. It should be me.)

    So I wrote this to allow for custom hit formulae globally and/or per skill.

    I tested the basic functions, please let me know if you run into any errors. Because it was necessary to modify code in the middle of the Game_Action.apply() function, this may cause conflicts with other plugins that modify the same function.

    I will consider making compatibility patches if the other plugin is free to use and unobfuscated. Otherwise, other authors are free to modify this code to make it compatible with theirs so long as I am still credited.

    Features
    You may use this plugin to bypass MZ's default hit formula (a percentile check against the attacker's hit rate). You can redefine one universal formula to supplant it, modify it at the skill level, and decide whether evasion is checked separately.

    The default behavior of the engine is to determine a hit and then check for evasion or magic evasion, depending on the skill type. You can choose to bypass this behavior in order to incorporate the eva/mev parameters into your formula (or to disregard them).

    The hit formula notetags and plugin parameter function identically; the notetags will always override the plugin parameter, and the parameter is set to MZ's built-in calculation by default. So this plugin is as plug-and-play as the user desires, with the ability to change the hit calculations on just one or few skills if that's all that's required.

    How to Use
    Use the following notetag in the notebox of your skills:

    <hitformula>
    your_formula_here
    </hitformula>

    The formula can be any valid JavaScript expression. An evaluation of "true" means the skill will hit, whereas "false" is a miss.

    The below example is fashioned after the D20 system, adding d20 + level and comparing it to the target's Defense:
    <hitformula>
    Math.randomInt(20)+1+a.level >= b.def
    </hitformula>

    Included variables are the same as those listed in MZ's damage formula, as well as user and target.

    Terms and Credits
    Free for non-commercial and commercial use. Credit ATT_Turan.
  2. For anyone who wants to use this with VisuStella Battle Core, it should be compatible as long as you place this plugin somewhere above Battle Core in your plugin manager.
  3. This is so incredible i'm beyond words!
    It's simple, effective and give us plenty of possibilities.
    Thank you so much @ATT_Turan

    Just a quick question tho.
    This formula already takes the evade parameters in consideration or i need to add it?

    <hitformula: Math.randomInt(20)+1+a.level >= b.def>
  4. murilloc said:
    This formula already takes the evade parameters in consideration or i need to add it?
    That depends on how you configured the plugin parameters.

    As I described in the instructions, checking evade is normally a second check unrelated to the hit formula.

    So if you left that option on, then the engine will check evade as it always does.

    If you turned it off, then no, there's nothing in your formula that references it.
  5. Sorry, but it doesn't seem to work for me. No matter what I put in the Hit Formula it doesn't do anything. I even tried making the formula always return false and it still just kept to the default. I turned all other plugins off to see if that made a difference and it didn't.

    Edit: Nevermind, I forgot about hit rate with the default formula.
  6. How do I make a certain hit formula for this plugin? I have tried <hitformula: true>, but it doesn't work in all cases. Would this be a compatibility issue with another plugin in that case?

    EDIT: Nevermind, I answered my own question as I was asking it. I got my issue resolved by making sure both plugins were telling the skill to always hit.
  7. I added a custom hit formula, but it doesn't seem to be working. I'm just using the D20 formula provided here, but edited so that it's no longer adding level.
  8. @LordEdmundGod Please post what you actually have entered, rather than describing it. There may be an error in syntax that you're not noticing.

    Aside from that:
    - What do you mean that it "doesn't seem" to be working?
    - When you press F8 and go to the Console tab during a playtest, do you see any warnings or errors (aside from the pixi map thing)?
    - What engine are you using? Your profile says you use MV, but this is an MZ plugin.
  9. Well, then there's my problem! It appears I missed that this was an MZ plugin! Do you know of any plugins that would allow for me to create a similar effect to this one that work for MV?
  10. @LordEdmundGod Yup, if you Google the terms there are a number of plugins that do this stuff for MV.

    Yanfly has a hit formula plugin, as does...I wanna say Victor Engine. There may be more, depending on exactly which features you want.
  11. I really just want to be implement a D20 system for my game- thanks for your help!
  12. Where would I add individualized + to hit for different enemies/actors. For example I have the hit formula setup for a basic d20 system plus their attack/2 but some have bonuses to hit. Can I add this in the notes of each enemy and if so what would be the formula for that?
  13. Falastur18 said:
    Where would I add individualized + to hit for different enemies/actors. For example I have the hit formula setup for a basic d20 system plus their attack/2 but some have bonuses to hit. Can I add this in the notes of each enemy and if so what would be the formula for that?
    Hm. There isn't an easy way to do that built into the plugin, because everyone's equation is potentially different - so me making a notetag that "adds this much" to the formula wouldn't necessarily mean anything.

    Two thoughts:
    1 - what are you using ATK for? You could simply make that be the hit bonus, then you're incorporating a.atk into your formula.

    2 - you could use a notetag. The only trick is you'd have to use a bit of fanciness because the way you access notetags is different for actors vs. enemies.

    So if you give your actors and enemies a <tohit:x> notetag, you could then do:
    Code:
    (a.isActor() ? Number(a.actor().meta.tohit) : Number(a.enemy().meta.tohit))
    and stick that wherever in your formula you want to add the value.

    You just need to make sure every actor and enemy has that notetag, even if it's <tohit:0>
  14. I've tried the following formula.

    <hitformula: Math.randomInt(20)+1+a.agi >= b.agi>

    however the game seems to revert to the game's default formula. I've set the enemy agility to 200, but the player characters are still landing hits. I'm really bad with code, and I'm honestly just looking to add character speed state to both hit and evasion rates. Would someone be able to tell me where I'm going wrong?

    The plugin itself is working fine as I tried simply <hitformula: false> which made sure all attacks missed, so there is no conflict with other plugins.
  15. @Aquras Just making sure you're using this in MZ - your profile says you use MV, and this plugin has JavaScript syntax that will prevent it from loading in MV.

    I did confirm a bug when using some characters in the hitformula notetag, and I've uploaded a new version.

    Please notice the format of the notetag has changed to:
    Code:
    <hitformula>
    formula
    </hitformula>
  16. ATT_Turan said:
    @Aquras Just making sure you're using this in MZ - your profile says you use MV, and this plugin has JavaScript syntax that will prevent it from loading in MV.

    I did confirm a bug when using some characters in the hitformula notetag, and I've uploaded a new version.

    Please notice the format of the notetag has changed to:
    Code:
    <hitformula>
    formula
    </hitformula>
    Thanks for the help. It's working just fine now. Glad it was a bug in the end and not me.
  17. Hi, me again. I believe I have found another bug potentially. When I have a character use an item, any item, i get a "Cannot read property "Length" undefined. I have tried using items without the plugin and all goes as normal. I'll insert an image of the debug window. Screenshot (58).png
  18. @Aquras Thanks for the heads up, should be corrected in the new version on the first post.
  19. Updated to correct an error with the ApplyEvasion parameter.
  20. Thank you for the amazing plugin.
    I have one question: how can I write a code to use a notetag to check a condition where an actor's attack misses or the enemy evades?
    I tried writing it as follows, but it didn't work:

    <hitformula>
    if (target.result().missed || target.result().evaded) {
    // process
    } else {
    // process
    }
    </hitformula>