[RMMV] [RMVX ACE] [RM2K3] THE MAKER MATHS THREAD

Posts

Pages: 1
Okay, so this is not STRICTLY programming but it's a very closely related topic: how the default formulas (or the formulas after modification by various common or even nigh-ubiquitous scripting/plugins) actually work. I remember I either made a topic about this in the past or asked a bunch of questions about this in the past possibly in the "What are you thinking about (game development)?" thread but as I cannot remember which or where, I figured it was worth making a new topic rather than invoking necromancy.

I tagged three different engines in the subject because those three seem to be the most widely used. This does not mean if you have a question about how the default math/formulas works in say, RMXP, RM2k, or VX you aren't allowed to ask it here. I DON'T HAVE THE POWER TO MAKE RULES LIKE THAT. But I do very much want people other than me to be able to ask their RM math related questions here and have other other people more knowledgeable than me answer them. (In the event I actually know the answer to something, I'll happily pitch in.)

I'll start with the question that prompted this thread. Format your questions this way if you don't mind, might make it easier to index this knowledge later on.

(I found this stuff was easier to puzzle out on my own in RPG Maker VX Ace because you could CTRL + SHIFT + F through all the default RGSS scripts that made up the game engine looking for an answer. If there's an equivalent way to do that with the "core" JavaScript that makes up RMMV, I don't know what it is.)

Engine: RPG Maker MV
Relevant Plugins/Scripts: None, I think.
In the skills tab of the database, in the "Invocation" section, the second field is Success (percentage). Hovering my mouth mouse (wow that's a hilarious typo if you think about it) over that parameter gave me the following less than useful tooltip: "Probability that the use of the action succeeds". That tells me none of what I need to know:
  • If the action fails, does it register as a "Failed" on the user or as a "Miss" on the target?
  • I assume if Hit Type is set to "Guaranteed Hit" that the number in this box is the absolute percentage chance that the skill will hit?
  • If hit type is set to Physical Attack, how does "Success" interact with the target's Evasion? Does the engine first check to see if the skill succeeds, then check to see if the target evades, separately? Or does it combine together? I.E. does a skill with a 90% "Succeed" chance used against a target with 10% Evasion actually have an 81% chance of hitting?
  • Same basic question but if hit type is set to Magical Attack. If a spell has an 80% succeed rate and the target has 25% Magic Evasion, is the real chance the spell will hit 60%? Or is it checked separately?
Example (Optional): Balancing a boss fight in my game. Two of the enemies are bodyguards dual-wielding pistols. Semi-auto pistols in my game already get two shots per attack (Repeat: 2). The bodyguards have a skill called "Double Shot" that lets them fire off four shots at once, the same Repeat: 2 but with a target scope of "2 Random Enemies". Now this fight is too hard and I'm in the process of re-balancing it and one of the problems is that these bodyguards are OP and need to be nerfed. The logical way to do it, it strikes me, is accuracy. The game is kind of sort of grounded in reality (it takes place in the real world in 2076) and in reality unfortunately no one is Jet Li being directed by John Woo and you can't really shoot two handguns at once with any sort of accuracy. So, the succeed rate for shooting this gun once is 95%, the gun's "accuracy". I'm cutting the accuracy for the double shot ability down to 70%. Both of the PCs in the party have (the default) 5% Evasion right now. Having changed Succeed to 70%, does that mean that Double Shot is now squeezing off two pairs of shots at random targets with an adjusted chance to hit of 66.5% (95% of 70%) each? Or is it checking four times to see if the skill succeeds (70% chance) then checking separately to see if the target evades (5% chance)? Or is the math that's actually happening under the hood something different from either of those?

Your questions don't need to include examples and the examples don't need to be as long as mine was if you do include them and yes, I would like an answer to the sample question if anyone has one, it was not just for show. I do think it's important that you name the engine you're asking about, both so the answer can be cataloged properly and because I strongly suspect the under-the-hood math has been at least slightly different in every single version of RPG Maker ever released.
Marrend
Guardian of the Description Thread
21806
I think the key to answering the question in the OP lies in Game_Battler, or it's equivalent. I'll use VX Ace as my example as that's what I have installed right now.

class Game_Battler < Game_BattlerBase
  #--------------------------------------------------------------------------
  # * Calculate Hit Rate of Skill/Item
  #--------------------------------------------------------------------------
  def item_hit(user, item)
    rate = item.success_rate * 0.01     # Get success rate
    rate *= user.hit if item.physical?  # Physical attack: Multiply hit rate
    return rate                         # Return calculated hit rate
  end

  #--------------------------------------------------------------------------
  # * Calculate Evasion Rate for Skill/Item
  #--------------------------------------------------------------------------
  def item_eva(user, item)
    return eva if item.physical?    # Return evasion if physical attack
    return mev if item.magical?     # Return magic evasion if magic attack
    return 0
  end

  #--------------------------------------------------------------------------
  # * Apply Effect of Skill/Item
  #--------------------------------------------------------------------------
  def item_apply(user, item)
    @result.clear
    @result.used = item_test(user, item)
    @result.missed = (@result.used && rand >= item_hit(user, item))
    @result.evaded = (!@result.missed && rand < item_eva(user, item))
    if @result.hit?
      unless item.damage.none?
        @result.critical = (rand < item_cri(user, item))
        make_damage_value(user, item)
        execute_damage(user)
      end
      item.effects.each {|effect| item_effect_apply(user, item, effect) }
      item_user_effect(user, item)
    end
  end
end


So, it looks like, at least in this case, it checks whither or not the item/skill hits first, based on it's "success rate", multiplied by the user's hit-rate. In your example, the base rate of hitting/succeeding would be 66.5% (0.7 * 0.95 = 0.665). Assuming it hit, it would then check for evasion. Making your assumption about it checking to see if a target is hit separately from checking for evasion correct. It's probably safe to assume that the other engines work similarly?

I will note that there is apparently no "else" case to handle "@result.hit? == false" in the above function. There is nothing to process, except the "Missed!" message, or whatever, which is set up...

class Window_BattleLog < Window_Selectable
  #--------------------------------------------------------------------------
  # * Display Action Results
  #--------------------------------------------------------------------------
  def display_action_results(target, item)
    if target.result.used
      last_line_number = line_number
      display_critical(target, item)
      display_damage(target, item)
      display_affected_status(target, item)
      display_failure(target, item)
      wait if line_number > last_line_number
      back_to(last_line_number)
    end
  end
  #--------------------------------------------------------------------------
  # * Display Failure
  #--------------------------------------------------------------------------
  def display_failure(target, item)
    if target.result.hit? && !target.result.success
      add_text(sprintf(Vocab::ActionFailure, target.name))
      wait
    end
  end
end


...as part of the battle log functionality.
author=StormCrow
(I found this stuff was easier to puzzle out on my own in RPG Maker VX Ace because you could CTRL + SHIFT + F through all the default RGSS scripts that made up the game engine looking for an answer. If there's an equivalent way to do that with the "core" JavaScript that makes up RMMV, I don't know what it is.)


If you install a text editor like notepad++ or vscode, you can ctrl+shift+f in the editor to search all the javascript in your project. Other editors may have a different hotkey, but the function is often "find in files" or "search in files"
There's no javascript editor built in to MV, but they're just text files in your project so easy to edit externally.
If you decide to version control your projects, the MV style is more friendly than the Ace way.
I should get Notepad++, thanks for the tip. It hadn't occurred to me that another program could search across multiple different files.

Are the core JS files created and copied into every new project's data section like the RTP is into the img and audio folders in MV?
Yes they are - if you look in the js/ folder of a new project, there's a set of files named rpg_*.js which are the core scripts.
Pages: 1