[VX Ace] Damage formula trouble

S.Court

Veteran
Veteran
Joined
Oct 17, 2012
Messages
394
Reaction score
98
First Language
Español
Primarily Uses
RMVXA
Hello, I'm trying to make a damage formula and I'm having some troubles with it, you'll see, the damage formula is the next one


class Game_Battler < Game_BattlerBase
def attack(a,b)
(((a.atk * 2) + a.luk + ((((a.level / 1.43) ** 2) * (a.atk / 16.0)) * (a.luk / 16.0)) / 24) * ((400 - b.def)/401.0))+1
end
end




The trouble is I still need to add some damage multipliers


If user has state number 23, the damage is multiplied by 1.3


If user has state number 24, the damage is multipied by 0.7


If target has state number 25, the damage is multiplied by 0,7


If target has state number 26, the damage is multiplied by 1,3


Well, can someone tell me how to add those multipliers to this formula? Thanks by the help :)
 

Rinobi

Veteran
Veteran
Joined
Mar 24, 2014
Messages
579
Reaction score
219
First Language
English
Primarily Uses
RMVXA
Code:
#==============================================================================
# ** Game_Battler
#------------------------------------------------------------------------------
#  A battler class with methods for sprites and actions added. This class 
# is used as a super class of the Game_Actor class and Game_Enemy class.
#==============================================================================
class Game_Battler < Game_BattlerBase
  #--------------------------------------------------------------------------
  # * New Method: Attack Damage Calculation
  #--------------------------------------------------------------------------
  def attack(a, b)
    #------------------------------------------------------------
    # >> Damage Setup
    #------------------------------------------------------------
      x0 = (a.atk * 2) + a.luk
      x1 = (((a.level / 1.43) ** 2) * (a.atk / 16.0))
      x2 = ((400 - b.def) / 401.0)
      dmg = (x0 + (x1 * (a.luk / 16.0)) / 24) * x2 + 1
    #------------------------------------------------------------
    # >> Use3 Has State 23
    #------------------------------------------------------------
      if a.state?(23) then dmg *= 1.30 end
    #------------------------------------------------------------
    # >> Use3 Has State 24
    #------------------------------------------------------------
      if a.state?(24) then dmg *= 0.70 end
    #------------------------------------------------------------
    # >> Target Has State 25
    #------------------------------------------------------------
      if b.state?(25) then dmg *= 0.70 end
    #------------------------------------------------------------
    # >> Target Has State 26
    #------------------------------------------------------------
      if b.state?(26) then dmg *= 1.30 end
    #------------------------------------------------------------
    # >> Finalize Damage
    #------------------------------------------------------------
      return dmg.round.to_i
  end # attack
end # Game_Battler
 
Last edited by a moderator:

S.Court

Veteran
Veteran
Joined
Oct 17, 2012
Messages
394
Reaction score
98
First Language
Español
Primarily Uses
RMVXA
#==============================================================================
# ** Game_Battler
#------------------------------------------------------------------------------
# A battler class with methods for sprites and actions added. This class
# is used as a super class of the Game_Actor class and Game_Enemy class.
#==============================================================================
class Game_Battler < Game_BattlerBase
#--------------------------------------------------------------------------
# * New Method: Attack Damage Calculation
#--------------------------------------------------------------------------
def attack(a, b)
#------------------------------------------------------------
# >> Damage Setup
#------------------------------------------------------------
x0 = (a.atk * 2) + a.luk
x1 = (((a.level / 1.43) ** 2) * (a.atk / 16.0))
x2 = ((400 - b.def) / 401.0)
dmg = (x0 + (x1 * (a.luk / 16.0)) / 24) * x2 + 1
#------------------------------------------------------------
# >> Use3 Has State 23
#------------------------------------------------------------
if a.state?(23) then dmg *= 1.30 end
#------------------------------------------------------------
# >> Use3 Has State 24
#------------------------------------------------------------
if a.state?(24) then dmg *= 0.70 end
#------------------------------------------------------------
# >> Target Has State 25
#------------------------------------------------------------
if b.state?(25) then dmg *= 0.70 end
#------------------------------------------------------------
# >> Target Has State 26
#------------------------------------------------------------
if b.state?(26) then dmg *= 1.30 end
#------------------------------------------------------------
# >> Finalize Damage
#------------------------------------------------------------
return dmg.round.to_i
end # attack
end # Game_Battler


It works perfectly, thank you! Now, I'm not sure if I'd like to add a think


You'll see, I'm changing the random factor where when the target has more MP, it'll receive less and more consistent damage from attacks


Exactly before applying the buff/debufs represented by states, I need to multiply the damage by this:


dmg * ([Random number between Low and High]/243)


Where: Low = (b.mmp - 90 * 2 / 3.0)


And High = (b.mmp - 90)


How can I add this? Thanks by the help again, Rinobi
 

Rinobi

Veteran
Veteran
Joined
Mar 24, 2014
Messages
579
Reaction score
219
First Language
English
Primarily Uses
RMVXA
Based on the math, your 'low' value would return a greater number than your 'high' value.


If b.mmp == 500


500 - 90 * 2 / 3.00 = 440


500 - 90 = 410


If b.mmp == 100


100 - 90 * 2 / 3.00 = 40


100 - 90 = 10


Anyway, there are quite a few approaches to generating a range of random numbers, but I think this one is fairly easy to modify.


#==============================================================================
# ** Game_Battler
#------------------------------------------------------------------------------
# A battler class with methods for sprites and actions added. This class
# is used as a super class of the Game_Actor class and Game_Enemy class.
#==============================================================================
class Game_Battler < Game_BattlerBase
#--------------------------------------------------------------------------
# * New Method: Attack Damage Calculation
#--------------------------------------------------------------------------
def attack(a, b)
#------------------------------------------------------------
# >> Damage Setup
#------------------------------------------------------------
x0 = (a.atk * 2) + a.luk
x1 = (((a.level / 1.43) ** 2) * (a.atk / 16.0))
x2 = ((400 - b.def) / 401.0)
dmg = (x0 + (x1 * (a.luk / 16.0)) / 24) * x2 + 1
#------------------------------------------------------------
# >> Mana Damage Variance
#------------------------------------------------------------
mp_low = b.mmp - 90 * 2 / 3.0
mp_high = b.mmp - 90
dmg *= (mp_high..mp_low).to_a.sample / 243.0
#------------------------------------------------------------
# >> User Has State 23
#------------------------------------------------------------
if a.state?(23) then dmg *= 1.30 end
#------------------------------------------------------------
# >> User Has State 24
#------------------------------------------------------------
if a.state?(24) then dmg *= 0.70 end
#------------------------------------------------------------
# >> Target Has State 25
#------------------------------------------------------------
if b.state?(25) then dmg *= 0.70 end
#------------------------------------------------------------
# >> Target Has State 26
#------------------------------------------------------------
if b.state?(26) then dmg *= 1.30 end
#------------------------------------------------------------
# >> Finalize Damage
#------------------------------------------------------------
return dmg.round.to_i
end # attack
end # Game_Battler


As mentioned above, mp_low returns a higher value than mp_high, so I flipped them around (won't work otherwise). With this formula, the greater the target's maximum MP value, the more damage it receives (doesn't really affect variance itself). It's the opposite of what you said your intention was, but I used your own math since I don't know enough about your project to 'correct' this.


If you were meaning to compare the target's current mp with their maximum mp values, then I think I can produce the results you're after.
 

S.Court

Veteran
Veteran
Joined
Oct 17, 2012
Messages
394
Reaction score
98
First Language
Español
Primarily Uses
RMVXA
Based on the math, your 'low' value would return a greater number than your 'high' value.


If b.mmp == 500


500 - 90 * 2 / 3.00 = 440


500 - 90 = 410


If b.mmp == 100


100 - 90 * 2 / 3.00 = 40


100 - 90 = 10


Anyway, there are quite a few approaches to generating a range of random numbers, but I think this one 


As mentioned above, mp_low returns a higher value than mp_high, so I flipped them around (won't work otherwise). With this formula, the greater the target's maximum MP value, the more damage it receives (doesn't really affect variance itself). It's the opposite of what you said your intention was, but I used your own math since I don't know enough about your project to 'correct' this.


If you were meaning to compare the target's current mp with their maximum mp values, then I think I can produce the results you're after.


Ohh dear, my bad, I totally messed up there D:


The formula is:  dmg * ((180-[Random number between Low and High])/243)
Low = 180 - ((b.mmp -90) * 2 / 3)


High = 224- (b.mmp - 90)


In that case


If b.mmp == 100


Low: (180 - (100 - 90)) * 2 / 3.00 = 113


High: 224 - (100 - 90) = 214


In that case, Low is... Well, lower than High, can you fix that, please?


EDIT: What does the ".to_a.sample" part mean?
 
Last edited by a moderator:

Rinobi

Veteran
Veteran
Joined
Mar 24, 2014
Messages
579
Reaction score
219
First Language
English
Primarily Uses
RMVXA
.to_a Converts a range such as (1..10) to an array like: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]


.sample Returns a random value from an array.


Just need to replace this part...


#------------------------------------------------------------
# >> Mana Damage Variance
#------------------------------------------------------------
mp_low = (180 - (100 - 90)) * 2 / 3.00
mp_high = 224 - (100 - 90)
dmg *= (mp_low..mp_high).to_a.sample / 243.0




Alternatively, if you wanted current MP to influence the damage variance.


#------------------------------------------------------------
# >> Mana Damage Variance
#------------------------------------------------------------
variance = Random.new
min_range = b.mp_rate
max_range = 1 - b.mp_rate + 1
dmg = [dmg * variance.rand(min_range..max_range), 1].max


So if the target had 60 out of 100 MP for example, the damage variance would about 40%.


Meaning a damage value of 50 wound return a number anywhere between 30 and 70.


When the target's MP is full, the damage variance is 0%, and always returns a value of 50.
 
Last edited by a moderator:

S.Court

Veteran
Veteran
Joined
Oct 17, 2012
Messages
394
Reaction score
98
First Language
Español
Primarily Uses
RMVXA
.to_array Converts a range such as (1..10) to an array like: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]


.sample Returns a random value from an array.


Just need to replace this part...



#------------------------------------------------------------
# >> Mana Damage Variance
#------------------------------------------------------------
mp_low = (180 - (100 - 90)) * 2 / 3.00
mp_high = 224 - (100 - 90)
dmg *= (mp_low..mp_high).to_a.sample / 243.0
Ohh dear, ANOTHER mistake of my part, Low would be 243 - ((b.mmp - 90) * 2 / 3.0) and High would be 302 - (b.mmp - 90). I did modify that when I copied it in my projject thought, and it's not working


You'll see, the desired effect is the next one: A bigger mana pool will make you receive less -and more cosistent- damage, affecting the random variance


For example, if target has 90 of MMP, (which would mean 0 due to the mmp would subtract 90) the random variance would be from 100% [That would be = (243-(0*(2/3.0))/243)] to ~125% [That would be = (302-0)/243]


But if target has for example, 180 MMP (90 in the b.mmp-90 formula) the random variance would be from ~75% [That would be = (243-(90*(2/3.0))/243)] to ~87% [That would be = ((302-90)/243)]


I hope this explanation can help to fix my doubt, thanks a lot by the help ^_^


EDIT: I tried this, but it's not working either
 

Code:
#------------------------------------------------------------
# >> Mana Damage Variance
#------------------------------------------------------------
    x2 = b.mmp - 90
    mp_low = (243 - (x2 * (2 / 3.00)))
    mp_high = (302 - x2)
    dmg *= (mp_low..mp_high).to_a.sample / 243.0
 
Last edited by a moderator:

Rinobi

Veteran
Veteran
Joined
Mar 24, 2014
Messages
579
Reaction score
219
First Language
English
Primarily Uses
RMVXA
It's likely just a float value interfering with the conversion from range to array.


This should fix the issue:

#==============================================================================
# ** Game_Battler
#------------------------------------------------------------------------------
# A battler class with methods for sprites and actions added. This class
# is used as a super class of the Game_Actor class and Game_Enemy class.
#==============================================================================
class Game_Battler < Game_BattlerBase
#--------------------------------------------------------------------------
# * New Method: Attack Damage Calculation
#--------------------------------------------------------------------------
def attack(a, b)
#------------------------------------------------------------
# >> Damage Setup
#------------------------------------------------------------
x0 = (a.atk * 2) + a.luk
x1 = (((a.level / 1.43) ** 2) * (a.atk / 16.0))
x2 = ((400 - b.def) / 401.0)
dmg = (x0 + (x1 * (a.luk / 16.0)) / 24) * x2 + 1
#------------------------------------------------------------
# >> Mana Damage Variance
#------------------------------------------------------------
mp_low = (243 - ((b.mmp - 90) * 2 / 3.0)).round.to_i
mp_high = 302 - (b.mmp - 90)
dmg *= (mp_low..mp_high).to_a.sample / 243.0
#------------------------------------------------------------
# >> User Has State 23
#------------------------------------------------------------
if a.state?(23) then dmg *= 1.30 end
#------------------------------------------------------------
# >> User Has State 24
#------------------------------------------------------------
if a.state?(24) then dmg *= 0.70 end
#------------------------------------------------------------
# >> Target Has State 25
#------------------------------------------------------------
if b.state?(25) then dmg *= 0.70 end
#------------------------------------------------------------
# >> Target Has State 26
#------------------------------------------------------------
if b.state?(26) then dmg *= 1.30 end
#------------------------------------------------------------
# >> Finalize Damage
#------------------------------------------------------------
return dmg.round.to_i
end # attack
end # Game_Battler



Or if really want float values:

Code:
#==============================================================================
# ** Game_Battler
#------------------------------------------------------------------------------
#  A battler class with methods for sprites and actions added. This class 
# is used as a super class of the Game_Actor class and Game_Enemy class.
#==============================================================================
class Game_Battler < Game_BattlerBase
  #--------------------------------------------------------------------------
  # * New Method: Attack Damage Calculation
  #--------------------------------------------------------------------------
  def attack(a, b)
    #------------------------------------------------------------
    # >> Damage Setup
    #------------------------------------------------------------
      x0 = (a.atk * 2) + a.luk
      x1 = (((a.level / 1.43) ** 2) * (a.atk / 16.0))
      x2 = ((400 - b.def) / 401.0)
      dmg = (x0 + (x1 * (a.luk / 16.0)) / 24) * x2 + 1
    #------------------------------------------------------------
    # >> Mana Damage Variance
    #------------------------------------------------------------
      variance = Random.new
      mp_low = 243 - ((b.mmp - 90) * 2 / 3.0)
      mp_high = 302 - (b.mmp - 90)
      dmg *= variance.rand(mp_low..mp_high) / 243.0
    #------------------------------------------------------------
    # >> User Has State 23
    #------------------------------------------------------------
      if a.state?(23) then dmg *= 1.30 end
    #------------------------------------------------------------
    # >> User Has State 24
    #------------------------------------------------------------
      if a.state?(24) then dmg *= 0.70 end
    #------------------------------------------------------------
    # >> Target Has State 25
    #------------------------------------------------------------
      if b.state?(25) then dmg *= 0.70 end
    #------------------------------------------------------------
    # >> Target Has State 26
    #------------------------------------------------------------
      if b.state?(26) then dmg *= 1.30 end
    #------------------------------------------------------------
    # >> Finalize Damage
    #------------------------------------------------------------
      return dmg.round.to_i
  end # attack
end # Game_Battler
 

S.Court

Veteran
Veteran
Joined
Oct 17, 2012
Messages
394
Reaction score
98
First Language
Español
Primarily Uses
RMVXA
It's likely just a float value interfering with the conversion from range to array.


This should fix the issue:

#==============================================================================
# ** Game_Battler
#------------------------------------------------------------------------------
# A battler class with methods for sprites and actions added. This class
# is used as a super class of the Game_Actor class and Game_Enemy class.
#==============================================================================
class Game_Battler < Game_BattlerBase
#--------------------------------------------------------------------------
# * New Method: Attack Damage Calculation
#--------------------------------------------------------------------------
def attack(a, b)
#------------------------------------------------------------
# >> Damage Setup
#------------------------------------------------------------
x0 = (a.atk * 2) + a.luk
x1 = (((a.level / 1.43) ** 2) * (a.atk / 16.0))
x2 = ((400 - b.def) / 401.0)
dmg = (x0 + (x1 * (a.luk / 16.0)) / 24) * x2 + 1
#------------------------------------------------------------
# >> Mana Damage Variance
#------------------------------------------------------------
mp_low = (243 - ((b.mmp - 90) * 2 / 3.0)).round.to_i
mp_high = 302 - (b.mmp - 90)
dmg *= (mp_low..mp_high).to_a.sample / 243.0
#------------------------------------------------------------
# >> User Has State 23
#------------------------------------------------------------
if a.state?(23) then dmg *= 1.30 end
#------------------------------------------------------------
# >> User Has State 24
#------------------------------------------------------------
if a.state?(24) then dmg *= 0.70 end
#------------------------------------------------------------
# >> Target Has State 25
#------------------------------------------------------------
if b.state?(25) then dmg *= 0.70 end
#------------------------------------------------------------
# >> Target Has State 26
#------------------------------------------------------------
if b.state?(26) then dmg *= 1.30 end
#------------------------------------------------------------
# >> Finalize Damage
#------------------------------------------------------------
return dmg.round.to_i
end # attack
end # Game_Battler



Or if really want float values:

#==============================================================================
# ** Game_Battler
#------------------------------------------------------------------------------
# A battler class with methods for sprites and actions added. This class
# is used as a super class of the Game_Actor class and Game_Enemy class.
#==============================================================================
class Game_Battler < Game_BattlerBase
#--------------------------------------------------------------------------
# * New Method: Attack Damage Calculation
#--------------------------------------------------------------------------
def attack(a, b)
#------------------------------------------------------------
# >> Damage Setup
#------------------------------------------------------------
x0 = (a.atk * 2) + a.luk
x1 = (((a.level / 1.43) ** 2) * (a.atk / 16.0))
x2 = ((400 - b.def) / 401.0)
dmg = (x0 + (x1 * (a.luk / 16.0)) / 24) * x2 + 1
#------------------------------------------------------------
# >> Mana Damage Variance
#------------------------------------------------------------
variance = Random.new
mp_low = 243 - ((b.mmp - 90) * 2 / 3.0)
mp_high = 302 - (b.mmp - 90)
dmg *= variance.rand(mp_low..mp_high) / 243.0
#------------------------------------------------------------
# >> User Has State 23
#------------------------------------------------------------
if a.state?(23) then dmg *= 1.30 end
#------------------------------------------------------------
# >> User Has State 24
#------------------------------------------------------------
if a.state?(24) then dmg *= 0.70 end
#------------------------------------------------------------
# >> Target Has State 25
#------------------------------------------------------------
if b.state?(25) then dmg *= 0.70 end
#------------------------------------------------------------
# >> Target Has State 26
#------------------------------------------------------------
if b.state?(26) then dmg *= 1.30 end
#------------------------------------------------------------
# >> Finalize Damage
#------------------------------------------------------------
return dmg.round.to_i
end # attack
end # Game_Battler


Splendid, it works now, thank you very much!
 

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

Latest Threads

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,867
Messages
1,017,062
Members
137,575
Latest member
akekaphol101
Top