Damage Formula Help! (Multiple conditions??)

Hello!

So I've been working on my damage formula and have come across a problem...

This is a bit complicated so I'll do my best to describe the situation.

I have made a custom formula for Attack.

Using the formula,

My character attacks the enemy and deals 100 damage for example.

But in my game there is a skill called "Shield" that halves the damage taken.

Since I can't make the skill do this exactly (I just want to halve the damage not increase DEF),

I put a conditional on the formula that checks if the target of ''Attack'' has the "Shield" state.

if yes, it halves the result. If no,then deals normal damage.

So now instead for 100,if the enemy has "Shield" my character deals 50 damage for example.

Everything works fine,except these are not the only states in the game!

For example there is a skill called "Rage" that works like Berserk from Final Fantasy,making the character able only

to Attack and increasing attack. It reality, it multiplies the normal damage output * 1.5 .

Okay,So I made another conditional under the previous one that checks if the attacker has "Rage".

In our example, the character that dealt 100 damage,in "Rage" would deal 100* 1.5 = 150

It worked fine until I realized this:

What if the attacker has "Rage" AND the target has "Shield"??

Then it would have to be 150 / 2 = 75 damage

The question is, how do I do that?

How can I create conditionals that say for example:

if x=5 AND y=5 then do this

Is this possible or am I doing this the wrong way?

It would be a lot better if it was like this(since there are more states than these two that affect the formula):

When a. has no state and b. has no state => normal damage

When a. has no state and b. has "Shield" => normal damage / 2

When a. has "Rage" and b. has no state => normal damage * 1.5

When a.has "Rage and b. has "Shield" => (normal damage * 1.5)  /  2

Is this possible? And if yes how do I do it?

This is what I've done so far:

On the Database's formula space: eval (Normal)

On an empty script page:

Code:
#checks if target has "Shield"Normal = "b.state?(75) ? r = ((a.xstat.str - b.def) * (a.atk + rand(((a.level + a.atk) / 8) + 1))) / 2        : r = (a.xstat.str - b.def) * (a.atk + rand(((a.level + a.atk) / 8) + 1)) ; r"#checks if the attacker has "Rage"Normal =  "a.state?(74) ? r = ((a.xstat.str - b.def) * (a.atk + rand(((a.level + a.atk) / 8) + 1))) * 1.5         : r = (a.xstat.str - b.def) * (a.atk + rand(((a.level + a.atk) / 8) + 1)) ; r"
The formula-field is probably to small for this, so you have to create a (small) custom script for it.

As far is understand you the basic formula can be seen as:

base_damage*factor_shield*factor_rage*factor_other etc..Where factor_shield for example is 0.5 if the target has the shield-state and 1 otherwise and factor_rage would be 1.5 if the user has the rage-state and 1 otherwise, correct?

Now if all your conditions are just changing the damage by a percentage and can be multiplicated (so rage+shield would 1.5*0.5 = 0.75) then you can simplify your damage-formula:

base_damage*a.damage_factor_user*b.damage_factor_targetThe idea is to combine all effects that might change the damage output of the user into one factor (damage_factor_user) and all effects that might change the damage recieved into another factor (damage_factor_target) and then apply both of these factors to the base damage.

Whats then left to do is to write a script to actually calculate these combined factors:

class Game_BattlerBase # Since this has to affect Actors and enemys alike def damage_factor_user factor = 1.0 # Base Factor if no effect is in place if state?(74) # Assuming 74 is your rage-state factor *= 1.5 # Multiply with the rage factor end # You can add additional effects similar to the one above here return factor # finaly return the combined factorend def damage_factor_target # Now the same for effects on the target factor = 1.0 if state?(75) # Shield state factor *= 0.5 end # And add other effects here. return factorend end # End of classI have not tested this, it is just some quick code, but it should work.
Just give the state Shield a PDR (Physical Damage Rate) feature of 50%.  PDR flat out reduces physical damage taken by the set amount. (Magic uses MDR for the same thing)

And the state Rage would be an ordinary 50% ATK boost.
@MagicMagor =>  Thanks for writing all this but  I don't fully understand it...(My programming and maths skills are extremely limited)

If I copy-paste it,will it work?

@Kerbonklin => Damn I didn't know about PDR .Gonna try this now! I hope it does the job! 

EDIT: Tried it!PDR seems to work fine. Should I do it this way and keep things simpler?

Also I have some questions, if you could answer it would help me a lot..

1) Is it possible to have a state that increases strength according to this formula?

    [(atk * 125) / 100]

for example, my character has 25 atk so :

   (25 * 125) / 100 = 31

His new strength would be 31.

2)

When a character's TP is 100 then his normal Attack damage is multiplied * 1.5

Is this possible?

3)How are criticals handled in vx ace? do they just do double damage?

That's it for now...!Thanks for your time...!
@zero

Yes it will. Just insert it as a new script under Materials in your script editor.

Of course for the guard-effect, using the PDR is easier, but the script allows a bit more flexibility in your conditions.

The basic layout for a condition (based on a state) is this:

if state?(id) factor *= FACTORendYou can insert as many of these into the methods (at the place where the comment-line stating this is (# -> Comment)) as you want.

What this does is multiplying the overall-factor (and therefore the damage) with FACTOR if the user/target (depending in which method) is afflicted by the state id.

Just take the percentage you want the damage to be and divide it by 100 to get the FACTOR. (150% -> 1.5, 50% -> 0.5 etc..)

And the state Rage would be an ordinary 50% ATK boost.
It can be, but it also can be something different depending what zero wants.

An attack boost will boost that, the attack by 50% and will then apply the defense of the target. But it could also mean applying a 50% boost to the damage after the defense is already applied. The first one will result in higher damage than the second, but they are not the same.

# Using the basic a.atk*4 - b.def*2 formula# Boost AtK 50%a.atk*4*1.5 - b.def*2 = a.atk*6 - b.def*2# Boost damage after applying defense by 50%(a.atk*4 - b.def*2)*1.5 = a.atk*4*1.5 - b.def*2*1.5 = a.atk*6 - b.def*3What to use depends on what you want and on the overall balance. Just to note though, that my script and the usage i applied it would do the second option, but that depends on the actual formula used do calculate the damage.

All my script is doing/offering is combining several factors into a single factor to be used in the calculation. This makes it easier to apply a variety of factors to the damage formula using a variety of conditions.

I had the impression from the first post that the OP didn't just wanted the Guard- and Rage-State but used these two skills as an example of how to combine different factors into the calculation.
Your impression is correct...! But since I'm new at programming maybe it's better if I keep things simpler...

But it's hard to decide which attack boosting method to use...!!

Anyway,thanks for this, I could never come up with something like that.

If you could answer some of my other questions it would be great!!

1) Is it possible to have a state that increases strength according to this formula?

    [(atk * 125) / 100]

for example, my character has 25 atk so :

   (25 * 125) / 100 = 31

His new strength would be 31.

2)

When a character's TP is 100 then his normal Attack damage is multiplied * 1.5

Is this possible?

3)How are criticals handled in vx ace? do they just do double damage?

4)Can you make it so that the duration a character stays in a state depends to a stat?

for example,

Jack has 30 Spirit => 30 / 2 = 15 , state stays on Jack for 15 turns  

That last one must be hard!

That's it for now.Again thanks for your help,guys!
Ok, i will try to answer all of your questions:

1. Yes that is possible. The formula is basicly a 25% increase in ATK. Have a look at the "Feature"-section in the database, when editing a state. You can set many nice effects with this, including increasing or decreasing a stat by a certain percentage. No need for scripting.

2. Yes it is. There are several ways of doing that, writing a script or having an event constantly running and checking wether the TP of an actor equals 100 and if yes then adding a state, that will boost the attack. (And if the TP are not 100 the said state is removed)

I find the script-solution more elegant, but i'm a scripter so i'm biased. Since you seem to have no prior knowledge in scripting i would advise the event-solution.

3. If a hit is critical the damage is tripled.

4. That is possible yes, but i don't think it is possible without resorting to scripting.

How familar are you with the editor? Especially the first question hinted that you are not yet familar with what the editor alone can do, without scripting. I would advise poking around in the editor, trying things out to get a feel for it.

With scripting almost nothing is impossible but even without scripts a lot can be achieved with clever eventing. Try to learn what you can do with the database and events alone - and only if that fails resort to scripts.
Actually I use RPG maker since the 2003 version...I know about it's features,I'm just really really bad at math 😀  (I'm more of a writer/director kind of guy)

(I couldn't figure out that the equation from question one is just a 25% percent increase)[Also I had totally forgotten about the PDR option,lol].

2.Hey I haven't thought of that!Haha it's gonna be a pain eventing it though.

I have made some events that work in battle like a  "steal" skill but after finishing it I gave up and decided to use Yanfly's script...So So much easier!

Now I'm working on a morph command that transforms enemies into items using eventing but it's not done yet!

I wish I could script it to use notetags...

3.Damn that's too muchl!!Is there a way to make it double?

4.So do you think that would be a very hard to do script? 😉
In regards to 3:

class Game_Battler < Game_BattlerBase alias apply_critical_double apply_criticaldef apply_critical(damage)  damage*2end endPlug&Play.

In regards to 4.

Probably not very hard for an experienced scripter. But it is a bit of work so i can't just write down here like i did with the other two script-snippets. You could make a script-request for that in the corresponding sub-forum.
Thanks for the critical!I would have spent all day trying to find it!

4.I see.Well it's not the most crucial thing right now so I'll leave it for later!  🙂

Umm, I didn't want to ask you more things but there is one more thing (It's now my second biggest problem)...

It strays from the topic though...

Should I send you a PM about it??

Original thread: https://forums.rpgmakerweb.com/threads/damage-formula-help-multiple-conditions.23042/