Jump to content
Fomar0153

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

Recommended Posts

This tutorial can also be found on my blog at: http://cobbtocs.co.uk/wp/?p=271

 

So earlier today on irc the conversation moved to the scripts someone desired for their game which included:

 

favorite foods - i can specify each actorÂ’s favorite food and when the item is used on them, they heal extra hp or something

 

Anyhow I pretty quickly realised a script was not needed to implement this feature. RPG Maker Ace once again proves just how versatile it is because this feature can be implemented in a single input box. In particular this one:

 

SS0027.png

 

That formula box alone has tremendous potential. I offered two solutions to the problem.

 

if b.id == 1; 500; else; 100; end;

 

b.id == 1 ? 500 : 100

 

Let us first look at exactly what they are doing. They both check a conditional statement, namely:

 

b.id == 1

 

For the formula box in general a refers to the attacker or user and b refers to the defender or recipient, who may or may not be the same.

 

Any way what we are checking is that the recipient's id is equal to 1. Please note that this example is about an item which should be usable on party members only and therefore b is always going to be an actor (party member in English). So essentially we are checking that the person who the item is being used on is first in the database (Eric by default).

 

Now let's look at the rest of those lines.

 

if b.id == 1; 500; else; 100; end;

 

If you've done any programming before you will recognise this as a standard if statement. If you're confused about the presence of the semi-colons then let me quickly explain that they are like a way of inserting a new line. Were we not restricted to a single line then we could have written it like this:

 

if b.id == 1

500

else

100

end

 

So what this means is when the character id equals 1, heal 500HP otherwise heal 100HP. The other version achieves the same result but might be a little less clear if you are not overly familiar with ruby.

 

b.id == 1 ? 500 : 100

 

It still has the conditional, it is still checking if the item is being used on Eric but the rest of the code you could say has been condensed. This effectively boils down to:

 

condition ? true : false

 

The last thing two things I want to say before moving on are firstly that for more complicated situations you are probably better going the if statement route and the last thing is that while the formula box is pretty powerful you need to be aware that it is capped at a certain length (let's be grateful that we use a & b and not attacker & defender) and if there is an error in your formula the skill will just miss repeatedly rather than crash the game.

 

Right so that concludes the explanation section of this tutorial. I personally find having a lot of examples to work from quite helpful so this next section is going to be a problem and solution section and hopefully one of them will be close enough to what you hope to achieve that you can adapt it.

 

Scenario: Half your party are demi-humans or robots and require different healing items than the rest of your party.

 

There are some quite creative solutions to this problem but for the sake of this tutorial I want to keep is simple. So the solution I offer just checks the ids again.

 

b.id==1 or b.id==3 or b.id==4 ? 500 : 0

 

A couple of things I would like to draw your attention to. I have omitted the spaces on both sides of == because when we're space conscious they are wasted characters. The other feature is the ors they act like you'd expect but be careful when using and because it has a bit more to it.

 

Scenario: One character's favourite food is peanut butter sandwiches but another character is allergic to peanuts.

 

So the way I'm going to implement it is that Eric gets a bonus 100 health when he eat the sandwich but Natalie is afflicted by poison when she eats one.

 

if b.id==1;200;elsif b.id==2;b.add_state(2);0;else;100;end;

 

So it was a bit more complicated this time so I went the route of the if statement, elsif is a way of checking another condition if the first one wasn't met. So let's just talk it through, if Eric gain 200HP, if Natalie add status number 2 (poison) otherwise restore 100HP.

 

Scenario: You have a thunder skill which doors more damage when outside, which you control with a switch

 

This is just a switch example.

 

$game_switches[x] ? 500 + a.mat * 4 - b.mdf * 2 :  200 + a.mat * 4 - b.mdf * 2

 

I've also included in it an example of how to include the default formula so you can see how to incorporate it.

 

Scenario: I have a skill whose power I want to control through a variable

 

Easy enough. Here's how to do 10 times the value of the variable.

 

$game_variables[x] * 10

 

Scenario: I have a gamber and I want him to use dice skills e.g. he rolls two six sided dice, the skill does 100 times the combined number of the faces. It does double if he rolls a double and 10000 if he rolls snake eyes.

 

This one has a lot in it so we'll look at it closely. We'll use the if method and then use the rand(x) method which returns a number from 0 to x-1 meaning we will add 1 to it to simulate dice. We will also need to create some local variables, I will use c & d (DO NOT USE a & cool.png.

 

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;

 

It's not perfect, I would quite like to know what he rolled rather than just seeing the damage. Don't worry the solution to this new problem will be shown in the next tutorial.

 

Scenario: We want a skill like White Wind (a final fantasy move which restores someone's current health).

 

An easier one for once, we want the target's ( cool.png hp

 

b.hp

 

Other parameters you can use:

 

hp,mp,tp,mhp (Maximum Hit Points), mmp *Maximum Magic Points), atk,def,mat (Magic ATtack power),mdf,agi,luk

 

Scenario: What about demi?

 

Demi was a move which took a quarter of your current health.

 

b.hp / 4

 

Scenario: I want a skill which uses someone else's stat e.g. my princess is bossing her guard around.

 

This is easier than you think, as long as it's a particular character.

 

$game_actors[1].atk * 4 - b.def * 2

 

Eric attack!

 

Scenario: I want a skill to do x

 

Leave a comment and I will try my best to direct you.

Share this post


Link to post
Share on other sites

Very, very nice. It took me a while to understand the implications of being able to use a custom formula for each skill, and a little longer to see what could be possible if you're allowed to use Ruby syntax within. Once I DID figure it out, the implications were staggering.

 

This should help people struggling with formula ideas.

Share this post


Link to post
Share on other sites

Nice, I didn't even notice this was posted here until just a moment ago. Your last scenario seems to be a template to ask for ideas? If so, my scenarios would be state related:

 

A skill that will do X% of increased/decreased damage than normal when another state is already applied. May require scripting, though.

 

1. We'll take a Poison Attack Skill as an example. The first part is casting, which would cause a certain amount of damage if it connects. What I wouldn't mind seeing is a formula to have that damage increased by, say, 10% of normal damage for that skill if the character is in a weakened state; or if they are in another state (say Healthy), then the damage is decreased by 10% of normal damage for that skill.

 

2. Continuing with scenario 1, aside from the initial cast damage, if the state of Poison is also applied to the character, for each round of battle have it continue to do a +10 or -10% of normal poison damage so long as that character is in their Weakened or Healthy State. Once they are no longer in these states, damage return for poison would be normal.

 

I see this as something that could greatly effect strategy and offer a bit of variance for characters and their states that could be applied in other areas as well. For example, a person who is enraged and goes into Berserk status may not receive as much damage from a Fire or Burn skills. A person who has been shocked by fear may receive more damage from an Ice or Freeze skill.

Share this post


Link to post
Share on other sites

While I'm not exactly sure what you mean by the scenarios you've given (Is it the attacker or the defender who should have the state?), you can check the states of both the target and the user by using:

 

a.debuff?(n) for the attacker's state, where n is the state ID, and

b.debuff?(n) for the target's state, where n is the state ID.

 

(I got that method from WindMesser's script. Isn't there something like a 'has_state?' method that might work better?)

Share this post


Link to post
Share on other sites

Once again I'm amazed at the custom formula's versatility.

There's just so much you can do with it, thanks for showing me about that "if else" can be used in it, I should have realized it, but all the same. :D

Share this post


Link to post
Share on other sites

Thanks guys :)

 

 

1. We'll take a Poison Attack Skill as an example. The first part is casting, which would cause a certain amount of damage if it connects. What I wouldn't mind seeing is a formula to have that damage increased by, say, 10% of normal damage for that skill if the character is in a weakened state; or if they are in another state (say Healthy), then the damage is decreased by 10% of normal damage for that skill.

Hmm, maybe something like:

c=a.atk*4-b.def*2;if b.state?(2);c=(c*110)/100;end;if b.state?(3);c=(c*90)/100;end;c

 

2. Continuing with scenario 1, aside from the initial cast damage, if the state of Poison is also applied to the character, for each round of battle have it continue to do a +10 or -10% of normal poison damage so long as that character is in their Weakened or Healthy State. Once they are no longer in these states, damage return for poison would be normal.

You want a state that makes poison more effective. I'm afraid that isn't something I can think of a way of doing without going into the default scripts.

 

a.debuff?(n) for the attacker's state, where n is the state ID, and

b.debuff?(n) for the target's state, where n is the state ID.

You could use .state?(id) it checks to see if you have a state applied.

Share this post


Link to post
Share on other sites

Yeah, pretty much was wondering if there was a way to make states more effective, especially if you already had another state applied. I wasn't sure if it could be done by the default formulas, but I'm thinking no. Still, it would make for an interesting design, to have states react differently depending on other applied states, so I may suggest this to somebody (Yanfly perhaps?) as a possible script.

 

By the way, what does the letter 'c' in the formula represent?

 

Edit: Thanks about clarify State ID (both Kirin and Formar), that should help within battle, where strategy is more important. If I want to apply a formula to the walking damage, I'm sure it's a matter of adding/changing something in the scripts.

Share this post


Link to post
Share on other sites

I personally had no clue that custom algorithms we're...well, that customizable. *blinks*

 

I both love and hate that you've opened my eyes to this. I love it because I realize the versatility that this now provides, and I equally hate it because now I have to go back and reconfigure just about every algorithm I've established.

 

Oy vey....

Share this post


Link to post
Share on other sites

Ok, how would I go about making an attack that causes recoil* on the user?

 

*(Basically, an attack that does damage to the enemy as normal, but does a portion of that damage back on the user as well, as a sort of penalty.)

 

Also, is it possible to make an attack that does damage based on the position a character occupies in the party?

For example, if I have Bob, Jane and Jill in my party (in that order, from left to right), then how can I make an attack that does normal damage to Jane and half damage to the other two party members?

 

(In other words, an attack that hits all, but hits the middle of the party the hardest).

 

Thanks in advance! :)

Edited by Winterfate

Share this post


Link to post
Share on other sites

*(Basically, an attack that does damage to the enemy as normal, but does a portion of that damage back on the user as well, as a sort of penalty.)

 

Something like this should work (fair warning, untested):

 

r = a.atk * 2 - b.def; a.hp -= r / 4; r

 

What we basically do is first calculate the resultant damage; then, we decrease the user's hp by 1/4 that amount. Then return the calculated damage value.

Share this post


Link to post
Share on other sites

Also, is it possible to make an attack that does damage based on the position a character occupies in the party?

For example, if I have Bob, Jane and Jill in my party (in that order, from left to right), then how can I make an attack that does normal damage to Jane and half damage to the other two party members?

 

(In other words, an attack that hits all, but hits the middle of the party the hardest).

 

There might be a smaller way to do this but currently I haven't found a way without going into the default scripts.

for c in $game_troop.members;unless c==b;c.item_apply(a,$data_skills[x]);end;end;a.atk * 4 - b.def * 2

Skill x should be a weaker version of the skill or something.

I'm about halfway through the more advanced version of this tutorial, I'll add this an example.

 

r = a.atk * 2 - b.def; a.hp -= r / 4; r

Pretty much exactly how I would have done it :)

Share this post


Link to post
Share on other sites

Going at it Tim's way, I can see a benefit in adding such a formula, not so much based on order of the party, but position (ie., front, middle, or rear). Front would be great for physical combat, but greater chance of a miss or less damage in the rear. Likewise, bow and arrow would be better in the rear than in the front when you are up close.

Share this post


Link to post
Share on other sites

In my game, I have a 'warrior' class. I would like to know how I would go about adding a debuff to the target only if the players attack was a critical hit. Is it possible to do this in the damage formula or would this have to be done with scripting? (Example, if the warrior critically hits with an attack, the target will now have a "Bleeding" debuff condition, where they take x damage over 3 turns.)

Share this post


Link to post
Share on other sites

In my game, I have a 'warrior' class. I would like to know how I would go about adding a debuff to the target only if the players attack was a critical hit. Is it possible to do this in the damage formula or would this have to be done with scripting? (Example, if the warrior critically hits with an attack, the target will now have a "Bleeding" debuff condition, where they take x damage over 3 turns.)

 

I nearly said no before deciding I should check.

Luckily for you, critical hits are determined before the formula is used.

Try:

if b.result.critical;b.add_state(1);end;1

Share this post


Link to post
Share on other sites

In my game, I have a 'warrior' class. I would like to know how I would go about adding a debuff to the target only if the players attack was a critical hit. Is it possible to do this in the damage formula or would this have to be done with scripting? (Example, if the warrior critically hits with an attack, the target will now have a "Bleeding" debuff condition, where they take x damage over 3 turns.)

 

I nearly said no before deciding I should check.

Luckily for you, critical hits are determined before the formula is used.

Try:

if b.result.critical;b.add_state(1);end;1

 

You...are...amazing! When I get home I'll throw this in and give it a whirl. And thanks for getting back to my question so quickly as well! =D

Share this post


Link to post
Share on other sites

b.id == 1 ? 500 : 100

okay, i have to admit it that statement above is a bit frustating for me who only able to "read" conventional if-then-else-endif statements :blink:

 

well, i have some questions

which one is correct (or close to)

case: i want to check if character with ID number 2 is included in the party

yes then set damage to 500

else 250

 

if $party_member.include?(2);500;else;250;end

 

or

 

if $party_member.include?('$game_actor[2]');500;else;250;end

 

sorry for my dumb question and poor english :P

Share this post


Link to post
Share on other sites

b.id == 1 ? 500 : 100

okay, i have to admit it that statement above is a bit frustating for me who only able to "read" conventional if-then-else-endif statements :blink:

 

well, i have some questions

which one is correct (or close to)

case: i want to check if character with ID number 2 is included in the party

yes then set damage to 500

else 250

 

if $party_member.include?(2);500;else;250;end

 

 

if $game_party.members.include?(2);500;else;250;end

Share this post


Link to post
Share on other sites

Sorry If This Was Asked Already, not Too Good At Formulas.

But I Want A Skill To Add A Debuff/Buff to An Ally

(Im trying To Add A Cooldown Like State That Restricts Usage Of A Skill Type)

This Is What I Have, But When I Use It The Skill Doesn't deal damage but It Does Apply the State

1 + a.atk * 4 - b.def * 1;a.add_state(39)

Again Sorry For The Stupid Question...

Share this post


Link to post
Share on other sites

Having a little trouble with this :)

 

I'm trying to create a mana drain spell that will absorb a small amount of mana, but is affected by the target's RES stat. I want it set so that it always deals at least 1 MP in damage to the foe.

 

I was considering something along the lines of:

 

1 + (a.mat * 1.2 - b.mdf * 2), but I'm always getting a nullified result. I'm assuming I need something so that if the result is < 1 it will be bumped up to 1. Does anyone have any formulaic suggestions?

Share this post


Link to post
Share on other sites

Your content will need to be approved by a moderator

Guest
You are commenting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×