Jump to content
slentara1

Battle damage issues

Recommended Posts

Apparently VX Ace treats decimals less than one as zeros like it does with negative numbers, ex: 0.75 or -20, etc = 0. Here is my damage formula: (a.atk/b.def)*(a.atk+b.def). My issue is when the first part of the formula equals a decimal less than one (b.def>a.atk) it treats it like a zero and deals no damage. I want it to use the decimal anyway instead of making it zero and voiding the whole formula. for example: (12/16)*(12+16) should equal 21 but instead it deals no damage because 12/16= 0.75. I need to get this fixed.

Share this post


Link to post
Share on other sites

Add this method to Game_BattlerBase

def decimal_fix(a, 
  damage = (a.atk / b.def).to_f * (a.atk + b.def).to_f
  if damage <= 0
    damage = 1
  else
    damage = damage
  end
  damage.to_i
end

In the skill's damage notebox, simply call

a.decimal_fix(a, 

Mathematically, this would do what you want, but I'm pretty sure VX Ace forces damage to be a whole number no matter what (converting the values to floats like in the example there might undo that if we're lucky). What this method call would do, otherwise, is force damage equal or less than 0 to be converted to 1 damage, at the minimum.

Edited by William C

Share this post


Link to post
Share on other sites

It's not converting to zero until after the calculation. Methods run in the order in which they're input. The damage value is calculated first, then evaluated in the if case.

 

You might also want to do the addition of the two stats FIRST, then multiply it by the division.

Edited by William C

Share this post


Link to post
Share on other sites

the script isn't working and neither is flipping the formula. it's counting the decimal as zero then multiplying with the addition which comes out zero. it only happens when the decimal is less than one.

Share this post


Link to post
Share on other sites

VX Ace doesn't output damage in decimals for HP or MP, only for TP, as far as I know. It would automatically convert any integer less than a zero to zero.

 

What you're asking for is a rewrite of how damage is calculated and output within the base scripts. Definitely possible, though! You'd also have to consider that a rewrite would apply to all skills and all damage formulae, unless you wrote separate methods that only applied to certain skills.

Share this post


Link to post
Share on other sites

I don't think we're on the same page. I'm not trying to make the final output a decimal. Refer back to my original example. (12/16)*(12+16)=(0.75)*(28)=21, thats what the final output would be if the formula functions correctly. however it does this: (12/16)*(12+16)=(.75)*(28)=(0)*(28)=0. keep in mind that a decimal is not less than zero. negative numbers are less than zero. vx ace is treating all numbers less than 1 as zero and it's causing the final output to be zero when it shouldn't be zero.

Share this post


Link to post
Share on other sites

I get you. There must be something that converts the integers of parameters to a whole number. Try this test, use the actual values in your example above in a damage formula (without any variance) instead of calling the parameters. See if the damage output is the same, or if it's 21, as you suspect it should be. That will help us determine whether it's the parameter methods or the damage methods.

Share this post


Link to post
Share on other sites

That's telling me that somewhere during the course of calculating a value to output as damage, decimals are being reduced down to the next whole number (zero).

 

So this is what we have in Game_Battler...

  #--------------------------------------------------------------------------
  # * Calculate Damage
  #--------------------------------------------------------------------------
  def make_damage_value(user, item)
    value = item.damage.eval(user, self, $game_variables)
    value *= item_element_rate(user, item)
    value *= pdr if item.physical?
    value *= mdr if item.magical?
    value *= rec if item.damage.recover?
    value = apply_critical(value) if @result.critical
    value = apply_variance(value, item.damage.variance)
    value = apply_guard(value)
    @result.make_damage(value.to_i, item)
  end

Try changing that last line from value.to_i to value.to_f (to_i forces an integer value, to_f forces a float or a decimal number).

Share this post


Link to post
Share on other sites

changing the script didn't work, but I added .to_f to the formula: (a.atk/b.def.to_f)*(a.atk+b.def), it works now but I'd like it to apply to all formulas without having to write it into each skill.

 

also I would like to use different formulas depending on the user's atk. if below 100 this, if 101 to 125 this so on and so forth. How would I construct that script

Share this post


Link to post
Share on other sites

When your formula is equal as 1/3 then it will print 0.3333333333333333333 *unlimited*

Do you want to print the number in that way in the battle log?

 

Also ...

Your character has 100 HP

When it get 0.75 damage, it will print 99.25 on the HUD?

 

What if he got 0.3 damage?

will it print 99.6666666 HP?

  • Like 1

Share this post


Link to post
Share on other sites

changing the script didn't work, but I added .to_f to the formula: (a.atk/b.def.to_f)*(a.atk+b.def), it works now but I'd like it to apply to all formulas without having to write it into each skill.

 

also I would like to use different formulas depending on the user's atk. if below 100 this, if 101 to 125 this so on and so forth. How would I construct that script

 

For this, it's easier to write methods into Game_BattlerBase and call them in the skill's damage formula note box.

Share this post


Link to post
Share on other sites

You can just add things to Game_BattlerBase, and follow the same guidelines you would when writing damage formulas into the game the normal way.

def conditional_attack(a, 
  damage = a.atk * 4 - b.def * 2
  if a.atk >= 100
    damage = damage * 1.2
  else
    damage = damage
  end
  damage.to_i
end

That would increase damage by 20% if the user's ATK is equal or greater than 100.

 

In the skill's damage formula, you'd write... "a.conditional_attack(a, b)"

 

It's important to always have the last line in a damage method be a call for the damage.

Share this post


Link to post
Share on other sites
def morale_attack(a, 
  damage = a.atk  4 - b.def * 2
  damage = damage * $game_party.alive_members.size
  damage.to_i
end

This would multiply the damage dealt by the number of living party members. You can come up with tons of different special formula by using Game_BattlerBase for methods instead of just filling in the damage formula note in the database.

Share this post


Link to post
Share on other sites


atk_range = 125 # this sets the limit on the range of the stat that you want

if a.atk >= 100 && a.atk <= atk_range # If greater than or equal to 100 and less than or equal to 125

code here # damage formula when conditions are met

else

code here # damage formula when conditions not met

end

call damage here # call the damage output

 

Edited by William C

Share this post


Link to post
Share on other sites

ok this is what I'm doing. it's base damage until 101 atk, then it adds a multiplier @ 101-125; 126-150;151-175;176-200:201-300;301-400; & 401 +. it's a multiconditional formula

Share this post


Link to post
Share on other sites
def conditional_attack(a, 
  base_damage = BASE DAMAGE FORMULA HERE
  case a.atk
  when > 100
    base_damage * 1.1
  when > 125
    base_damage * 1.2
  when > 150
    base_damage * 1.3
  when > 175
    base_damage * 1.4
  when > 200
    base_damage * 1.5
  # etc.
  # etc.
  # etc.
  end
  final_damage = base_damage.to_i
  final_damage.to_i
end

This is assuming that using a "case" statement instead of an "if" statement only allows one case to be applied at a time. I'm not sure if it does or not. Test out the damage input using static values and comparing them to what the result should be. For instance, give a character 20 attack, give an enemy 5 defense. Give the attack skill zero variance, and no critical chance, and make sure no elements alter the damage output. Give it a simple a.atk - b.def base_damage formula, and any character with less than 100 ATK should be dealing 15 damage. It should increase to 16-17 when the first case applies. When the second case applies, it should be dealing 18 damage. If it's dealing more than that, then it's applying multiple multipliers within the case and we're gonna have to write this up a different way.

Edited by William C

Share this post


Link to post
Share on other sites

not working I keep getting an error when trying a test battle

 

script ' game_battlerbase' line 737: syntaxerror occurred

unexpected tidentifier. expecting keyword_end end damage.to_i

Share this post


Link to post
Share on other sites
def conditional_attack(a, 
  base_damage = 15
  if a.atk <= 100
    base_damage = base_damage
  elsif a.atk <= 125
    base_damage = base_damage * 2
  elsif a.atk <= 150
    base_damage = base_damage * 3
  elsif a.atk <= 175
    base_damage = base_damage * 4
  elsif a.atk <= 200
    base_damage = base_damage * 5
  end
  final_damage = base_damage.to_i
  final_damage.to_i
end

Oops.

Edited by William C

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

  • Recently Browsing   0 members

    No registered users viewing this page.

×
Top ArrowTop Arrow Highlighted