How to make the most of custom formulae. Part #2

HamPants

Ayyy!
Member
Joined
Mar 14, 2012
Messages
90
Reaction score
10
First Language
English
Primarily Uses
[EDIT by Moderator.
The original first post has vanished. I have reconstructed it and you will find it in post #4. Edit ends.]

Bypassing the character limit is going to give me a lot of freedom, thanks Fomar!
 
Last edited by a moderator:

TheCastle

Veteran
Veteran
Joined
Apr 2, 2012
Messages
150
Reaction score
2
First Language
English
Primarily Uses
Thank you this was super helpful! I can now do the kinds of complex damage formulas I need for my game. :)
 
Last edited by a moderator:
Joined
Jul 19, 2012
Messages
34
Reaction score
3
First Language
Italian
Primarily Uses
Thanks dude. This is really useful. Now I can really crate unique and memorable skills :)
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,008
Reaction score
11,345
First Language
English
Primarily Uses
RMVXA
The first post containing the tutorial has gone missing - probably due to a forum update some years ago. Below is a copy of that tutorial. I have had to reconstruct the formatting manually, and I think I've got it right, but if anyone spots an error, please post to advise, then I can edit it.

[Original text begins]
So I have been talked into following up my last tutorial with another one. This one will be expanding on the previous one by going in to building upon the default scripts. First I want to talk about why you would do this and then go through a few worked examples.

One reason you might want to extend the default scripts for a formula could be the case that what you want to achieve doesn’t fit in the custom formula box. This is pretty easy to accomplish. Next up, you want to build in a default formula. I know that you can just use the same formula in every skill but I personally consider that bad practice. What if you discover your formula doesn’t act as you intended later in the game, fancy re-databasing all the skills and items? Or you want to create states that do different things to the formulas. We’ll be covering all that in this tutorial.

Let’s start by quickly analysing the formula box itself; as I’m sure you are aware a refers to the the attacker or user and b refers to the defender or recipient, now a and b refer either to an instance of Game_Actor or Game_Enemy. A quick glance at this class diagram shows us that both inherit from Game_Battler (which in turn inherits from Game_BattlerBase).

upload_2019-4-27_6-50-32.png


Why was that important? Simple because we have to decide where we are going to place our new bits of code. Personally I would recommend one of three places:
  • Game_Battler
  • Game_BattlerBase
  • A new Module

A module might in many ways make the most sense but being as I’m aiming this tutorial at people with limited scripting experience I’d rather avoid modules. Also if the code is added in Game_Battler we can directly access more variables directly (which suits me). So if we go to Materials in the script editor and insert us a new section then we need to add the code to add to the class:
Code:
class Game_Battler < Game_BattlerBase

end
Right next lets get down to examples. First let’s go through how to use a formula that’s too big for the box. Next let’s add a new method:

Code:
class Game_Battler < Game_BattlerBase
  def custom_formula_fireball
  end
 
end
If you don’t consider yourself to be a scripter then the easiest thing for you would probably be to enter the formula exactly how you would have in the custom formula box. Good news, we can do that. What we need to do is pass our new method the a,b from the custom formula. So this is what we’re up to:

Custom Formula Box:

Code:
 a.custom_formula_fireball(a,b)
Note: b.custom_formula_fireball(a,b) would be equally valid.

Script Editor:
Code:
class Game_Battler < Game_BattlerBase
  def custom_formula_fireball(a,b)
  end
 
end
So all that leaves us to do it put the formula in the method. I’m going to use the gambler example from the previous tutorial:
Code:
class Game_Battler < Game_BattlerBase
  def custom_formula_fireball(a,b)
    c=1+rand(6);d=1+rand(6);if c==1 and d==1;10000;elsif c==d;c*400;else;(c+d)*100;end;
  end
 
end
So that’s how to bypass the length limit on the custom formulae. If that’s all you’re interested in then you can stop here. I’ll be carrying onto covering adding a default formula and manipulating it.

I’m not going to cover anything to do with developing your formula I’m just going to show you how to implement it, here’s the formula I was using in my last game:
Code:
class Game_Battler < Game_BattlerBase
  def basef(a,b, magic = false)
    if magic
      return ([a.mat / 5, a.mat-b.mdf].max * (a.mat ** 0.5)).to_i
    else
      return ([a.atk / 5, a.atk-b.def].max * (a.atk ** 0.5)).to_i
    end
  end
 
end
First thing I’m going to point out is that I also pass a boolean (true or false) to the method to define whether it’s a magic attack or a physical one. You could do the same if you wanted. Just an example on the custom formula box:
Code:
a.basef(a,b,true)
Anyway the main reason for doing this is so that if you find your formula doesn’t work well later in the game you’ll only have to change it once. You can also simplify formulas if you wanted by making more methods. So for example in my last ill-fated game I had a character who could heal but I didn’t want him to be a dedicated healer so I made all his heals inflict statuses (with the turns they lasted reflecting the power of the heals) and if a character was affected by one of these statuses they only received half-healing. So the method I made looked like this:
Code:
def sorcery_healing?
  return state?(51) || state?(52) || state?(53)
end
My healing skill custom formulae looked a little like this

Code:
b.sorcery_healing? ? 100 : 200
Any how that just about concludes everything I wanted to cover in this tutorial, I hope it helped you.

 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Karen: Hi, I have a condition that prevents me from wearing a mask. :)

Employee: Can you tell me what it is?

Karen: >:(
Feeling a little overwhelmed... There are so many things to do.
- Building a simple website for portfolio
- Setup *******
- Manage social media
There are so many things inside of these tasks :(
Meet the cute little ghost, FhooFhoo. :kaopride:
If anyone here is looking for another high-potential RPGMaker game--besides She Dreams Elsewhere--be sure to follow Lawmage Academy. Good social media presence will take that game far.
Lol, I was about to write a small tutorial and realized it would belong to the MZ section ....that does not exist yet.

Forum statistics

Threads
99,574
Messages
966,819
Members
131,231
Latest member
Bektos
Top