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

Almost. It works for MP, but not for HP.

Any way to achieve that effect?
I'm going to assume you don't want this formula to cause damage.

Code:
b.mp = b.mmp/2; b.hp = b.mhp/2; 0
I think it was a typo there and should be:

b.mp=b.mmp/2;b.hp=b.mhp/2Edit: ninja'ed! 🙂
I'm going to assume you don't want this formula to cause damage.

b.mp = b.mmp/2; b.hp = b.mhp/2; 0
Well, technically I do.

See, I'm using the FF5 Mix script and I want the result of Elixir (100% HP and MP recovery) + Negative Potion (10% HP and MP loss to an ally. It's meant to be used in offensive mix combinations.) to be a Balance Potion, which has no practical use (as you're throwing away an Elixir), but is simply an amusing combination, causing the effect I wanted, for the potion to set HP and MP to 50% no matter what.

It seems like that formula you posted works. Thanks.

I have one more question. I saw someone mention an idea on another forum and I was wondering if it was possible.

His idea was to create a skill that dealt damage based on the contents of an equipment slot's stat value. His example was a "Shield Thrust" attack that would calculate damage based on the defensive value of your currently equipped Shield. How would one go about doing this?
Oh, i have another question... Is it possible to make a skill that cannot actually kill the enemy? Like, it will do whatever damage it is supposed to based on the formula, but it cannot reduce the enemy below 1 HP.

Something like False Swipe from Pokemon, basically.
Try:

d=a.atk*4-b.def*2;c=(d*20)/100;d+=rand(c+1)+rand(c+1)-c;[d,b.hp-1].min

And set variance to 0.
Try:

d=a.atk*4-b.def*2;c=(d*20)/100;d+=rand(c+1)+rand(c+1)-c;[d,b.hp-1].min

And set variance to 0.
I'll try that.

What about what I said above? About an attack formula that calls from the DEF value of your equipped shield to determine damage.
Hello Fomar!

I had posted a topic in the requests section about healing via damage and Xyper was most kind in providing me a formula to do that. However, I would also like to add for it to check if the actor is wearing a particular type of equipment (General, Heavy, etc) or using particular type of weapons (Dagger, Hammer, etc). I know near the beginning of the thread and on your website you had an example about the weapon, but it seemed to be using the specific weapon ID, not the type ID. I'm mainly going for a scenario where if the actor is wearing a particular type of armor, like Heavy, the healing output from the damage done is reduced.

I was wondering if you could kindly explain how to add an armor or weapon check to the formula I was provided:

c=4*a.atk-2*b.def;d=$game_party.alive_members;d.size.times{|i|d.hp+=(c*0.1).to_i};c
 

I know it won't fit in the box in the database itself so I'll be more or less scripting this via your second tutorial, but the actual equipment check part itself throws me. Any help would be greatly appreciated!
Hmm you could try adding in something like:

if (b.weapons.select { |item| item.wtype_id == 1 }).size > 0

or

if (b.armors.select { |item| item.atype_id == 1 }).size > 0

Also I'd just stick it in the notebox e.g.

eval($data_skills[x].note)
^ Wait, that's for his formula, right?

What about what I posted? Is there a way to calculate damage based on the DEF stat of your equipped shield?

Edit: Also, how can I call a character's level into the equation?
Try:

a.equips[1] == nil ? 0 :  a.equips[1].def

a.level
Hmm you could try adding in something like:

if (b.weapons.select { |item| item.wtype_id == 1 }).size > 0

or

if (b.armors.select { |item| item.atype_id == 1 }).size > 0

Also I'd just stick it in the notebox e.g.

eval($data_skills[x].note)
First, thank you very much for the reply!

But oh dear, I hope I don't sound too ignorant when I ask this... but 'b' is for the 'defender' or 'recipient' of a skill, right? So the check string as it is, is checking all other actors instead of the one performing the skill? If I wanted it to just check the performing actor it would be 'a'?

Would you mind breaking these down a little to explain them? I wouldn't ask for a deep in-depth explanation, just a sort of 'this part does this'. I'm mostly thrown by the ".size > 0" part.

As for the notebox part, that I can read from your notetagging tutorial, correct? You don't have to explain it here if it's in that, I'll scurry over to read. But thank you again for the reply!
b is for the "person" who is the target of the skill

a is for the user who uses the skill

(i switched b to a because u need the caster)

if (a.armors.select { |item| item.atype_id == 1 }).size > 0

a.armors gets all the armors of the caster (headgear,body, shield acces).

.select {...} gets all armors of the caster which fulfill the condition between "{" and "}".

|item| item.atype_id == 1 says that u wanna have all the armors which have the atype 1 (this would be all general armour items in the default project).

with .size u get the quantity of armors which fulfill  the condition.

>0 controls whether the caster has a an armor with atype 1 equpped.

Hope this helped u to understand it.

regards Bot
b is for the "person" who is the target of the skill

a is for the user who uses the skill

(i switched b to a because u need the caster)

if (a.armors.select { |item| item.atype_id == 1 }).size > 0

a.armors gets all the armors of the caster (headgear,body, shield acces).

.select {...} gets all armors of the caster which fulfill the condition between "{" and "}".

|item| item.atype_id == 1 says that u wanna have all the armors which have the atype 1 (this would be all general armour items in the default project).

with .size u get the quantity of armors which fulfill  the condition.

>0 controls whether the caster has a an armor with atype 1 equpped.

Hope this helped u to understand it.

regards Bot
Thank you very much for this explanation! It breaks it down very nicely. So if I wanted it to check for heavy armor, the only thing I would have to change is the "1", correct? The rest of it I don't necessarily have to change? (Unless I get complicated and check for particular pieces and all that.)
Try:

a.equips[1] == nil ? 0 :  a.equips[1].def

a.level
That works, thanks 🙂
a.equips[1] == nil ? 0 :  a.equips[1].def
'a.equips[1].def' doesn't work for me. I tried creating a block mechanic around it, where equipping a shield gives a chance to lower damage taken by an amount depending on the defense value of the shield. It breaks the formula. I also copy-pasted the full snippet into the Attack skill of a fresh project, and using the default Eric (with a shield of course), the skill does nothing.

Any idea why it might work for PushesTheButtons above, but not me? Did I miss something really obvious?
Since the test of this is hard to determine I wanted to check with people in the know if this custom formula would work:

a.atk * 3 - b.def * 1; if b.agi > a.agi ? a.hit*0.8 : a.hit*1.2

This would increase the attacker's hit % if they had higher agility or lower it if theirs was lower, right?
Formulas can't control hit-percentage at all.

A Formuale is executed after the decision whether the skill hits or not.

If the skill doesn't hit the formulae will not be executed at all.

regards Bot
This one keeps failing me and I don't know why...it says I have a missing ')', but I can't figure it out.

(a.atk*3 *(a.hp / a.mhp) - b.def) * (1+ ((a.agi - b.agi) / 100)).

Can anyone see what I am missing in the syntax? Seems like this should work...

Edit: Figured it out. Understand now that the system rounds every decimal DOWN, no matter what the value is.  So any partial values like 0.76, becomes 0, meaning an entire formula could result in a zero value.

My new formula ends up being very different:

(a.atk*3 - b.def)*(a.hp*100/a.mhp)*(100 + (a.agi - b.agi))/100/100

It means the actor's have to maintain a high health to be effective and agility plays a much more significant role in my game.
to get decimal values u have to use decimal numbers

for example

(a.agi - b.agi) / 100)

would transform to

(a.agi - b.agi) / 100.0)

as soon as one number is decimal the result is an decimal otherwise Ruby thinks that u wanna have an integer (I hope that is the way they are called outside computer since) and not an decimal.

Regarding the new formulae, I would encourage you to use some decimals as well:

(a.atk*3 - b.def)*(a.hp*100.0/a.mhp)*(100 + (a.agi - b.agi))/100/100

regards Bot
to get decimal values u have to use decimal numbers

for example

(a.agi - b.agi) / 100)

would transform to

(a.agi - b.agi) / 100.0)

as soon as one number is decimal the result is an decimal otherwise Ruby thinks that u wanna have an integer (I hope that is the way they are called outside computer since) and not an decimal.

Regarding the new formulae, I would encourage you to use some decimals as well:

(a.atk*3 - b.def)*(a.hp*100.0/a.mhp)*(100 + (a.agi - b.agi))/100/100

regards Bot
But the system is using whole numbers...also when the system comes up against a decimal value it rounds it down...no matter if it was 1.3 or 1.9, the system rounds this down to 1.  I don't want or need my gameplay to incorporate decimals...unless I am missing your point, why would I want it to have decimals anyways?

Also don't know if this was covered, but you can easily set up a minimum damage formula for your enemies, instead of them using the default attack a.atk*4 - b.def*2, set the formula to this: a.atk*4<b.def*2 ? 1 : a.atk* - b.def*2.  Or use whatever formula you are using for attack, I just used the default for an example.  I did see a forum where they used this: damage=[damage, 1].max, can this be used without scripting? Or is there a necessary snippet to go into the code?

Original thread: https://forums.rpgmakerweb.com/threads/how-to-make-the-most-of-custom-formulae-part-1.1143/