[RMVX] HALVE/DOUBLE DAMAGE AFTER DAMAGE CALCULATION VIA STATE

Posts

Pages: 1
I didn't really know where to post this, so hopefully I'm correct in assuming I can ask for this here. If not, I apologize in advance.

I have countlessly tried to make my buffs/debuffs be consistent and reliable, but due to the way damage calculation works with percentage based states that simply increase or decrease the stats, it just isn't as enjoyable as a simple halve/double damage if a state is applied (Just like in Final Fantasy the magic Shell and Protect basically).

Now I know the VX engine is as old as Time itself, but I am asking if anyone has any insight on a script that can provide me with just that, so I can tinker with it. Or if someone would be willing to work on one, should there be no such script around.
Marrend
Guardian of the Description Thread
21781
Have you tried a state that modifies the SP-Parameters of PDR (physical damage rate) and/or MDR (magical damage rate)? I'm looking at the help-file now, and it seems those are percentile-based parameters that modify damage based on whither skill is defined as a "Physical Attack" or "Magical Attack" in it's hit-type.
I honestly don't know what that is. There doesn't seem to be such a thing.

I should also clarify that I am horrible at scripting, I.e. I don't know jack.
I can only edit to a degree and see if it works or not. I don't even know where to start. Except I can look at the scripting for the Guard Command, which halves the damage when received like I wanted it and then just copy paste that part into a state, but then I realized I don't know how to do that lol.
You can modify that in the features area in the database, but idk if that was part of the things VX didn't have that was added later to VXA.
VX definitely does not have it, otherwise I would've created these states 3 years ago
Marrend
Guardian of the Description Thread
21781
Oh, VX. I was looking at Ace's help-file. Now I feel stupid. ;_;
Yeah, that's why I said its as old as time itself lol

Another thing I forgot to mention is (And it's probably insignificant to what I want, but mentioning it wouldn't hurt I think) that I do have Yanflys YERD Custom Damage Formula script(If anyone remembers that) and managed to transfer VXs quirky SPIs Defensive attributes against Magic damage to the DEF stat. (In VX there did not exist a MDF and MAT stat and the SPI stat determined how much damage you inflicted and took from Magic Attacks)
Now I'm no expert and am completely shooting in the dark, but I do not believe it would affect the requested script I ask for.
Here's something I whipped up: Demo Project!

It'll have to be inserted into your damage algorithms since idk Yerd Custom Damage Formula. I created two new values for states/battlers: Physical and Magical Vulnerability. It's a multiplier for physical/magical damage. 100 is 100% vulnerability. The bigger the number the more damage, 200% is x2 damage. Smaller is less damage, 50% is half damage.
They stack multiplicatively, so 50% and 200% vulnerability will become 100%. A 0% vulnerability will negate all damage.

Input values for mitigation are like so:

<physvul 100>
<magicvul 100>


See the project file for examples. The Hero has some skills that inflict states that change mitigation.

For adding it to your own damage value, use stuff like:
state_multiplier(:phys_vul)

Will get the state multiplier for physical vulnerability

state_multiplier(:magic_vul)

Same for magical vulnerability

These will return floating point values and VX wants Integers so make sure your damage values are Integers when you're done with them (holdover from my own code I shoved in)

damage = Integer(damage)

Can make the damage an integer.

See the example damage algorithm below or in the demo project for how to use it.

Code for posterity:
# I'm changing a bit how this is all calculated


# Put more generic stuff in here
class Game_Battler
  
  # Get the state multiplier for a stat
  def state_multiplier(stat)
    mul = states.compact.inject(1) {|product, state| product * get_state_rate(state, stat) }
    return mul
  end
  
  # Get the individual stat bonus (we don't do agi or eva because ugh)
  def get_state_rate(state, stat)
    case stat
      when :maxhp, :maxmp, :cri
        stat_fixed = stat
        # yf uses :hp, I use :maxhp, gotta fix that here
        stat_fixed = :hp if stat == :maxhp
        stat_fixed = :mp if stat == :maxmp
        x = state.stat_per[stat_fixed].nil? ? 1.0 : state.stat_per[stat_fixed] / 100.0
        return x
      when :atk
        return state.atk_rate / 100.0
      when :def
        return state.def_rate / 100.0
      when :spi
        return state.spi_rate / 100.0
      when :agi
        return state.agi_rate / 100.0
      when :hit, :eva # I didn't do these
        return 1
      when :phys_vul # Physical Vulnerability
        return state.physical_vulnerability / 100.0
      when :magic_vul # Magical Vulnerability
        return state.magical_vulnerability / 100.0
      else
        return 1
    end
  end

end

class RPG::State
  
  PHYSICAL_VUL_REGEX = /<PhysVul[\s]+([0-9]+)>/i
  MAGICAL_VUL_REGEX  = /<MagicVul[\s]+([0-9]+)>/i
  
  def physical_vulnerability
    return @phys_vul unless @phys_vul.nil?
    
    if @note =~ PHYSICAL_VUL_REGEX
      @phys_vul = $1.to_i
    else 
      @phys_vul = 100
    end
    
    return @phys_vul 
  end
  
  
  def magical_vulnerability
    return @mag_vul unless @mag_vul.nil?
    
    if @note =~ MAGICAL_VUL_REGEX
      @mag_vul = $1.to_i
    else
      @mag_vul = 100
    end
    
    return @mag_vul 
  end
  
end

(I adapted some code from one of my own projects so there's a bit of excess in here)


And example added to damage algorithms:
class Game_Battler
  
    #--------------------------------------------------------------------------
  # * Calculation of Damage From Normal Attack
  #     attacker : Attacker
  #    The results are substituted for @hp_damage
  #--------------------------------------------------------------------------
  def make_attack_damage_value(attacker)
    damage = attacker.atk * 4 - self.def * 2        # base calculation
    damage = 0 if damage < 0                        # if negative, make 0
    damage *= elements_max_rate(attacker.element_set)   # elemental adjustment
    damage /= 100
    if damage == 0                                  # if damage is 0,
      damage = rand(2)                              # half of the time, 1 dmg
    elsif damage > 0                                # a positive number?
      
      # Apply physical mitigation
      damage *= state_multiplier(:phys_vul)
      damage = Integer(damage) # I did math in floats but VX wants ints so oops
      
      @critical = (rand(100) < attacker.cri)        # critical hit?
      @critical = false if prevent_critical         # criticals prevented?
      damage *= 3 if @critical                      # critical adjustment
    end
    damage = apply_variance(damage, 20)             # variance
    damage = apply_guard(damage)                    # guard adjustment
    @hp_damage = damage                             # damage HP
  end
  #--------------------------------------------------------------------------
  # * Calculation of Damage Caused by Skills or Items
  #     user : User of skill or item
  #     obj  : Skill or item (for normal attacks, this is nil)
  #    The results are substituted for @hp_damage or @mp_damage.
  #--------------------------------------------------------------------------
  def make_obj_damage_value(user, obj)
    damage = obj.base_damage                        # get base damage
    if damage > 0                                   # a positive number?
      damage += user.atk * 4 * obj.atk_f / 100      # Attack F of the user
      damage += user.spi * 2 * obj.spi_f / 100      # Spirit F of the user
      unless obj.ignore_defense                     # Except for ignore defense
        damage -= self.def * 2 * obj.atk_f / 100    # Attack F of the target
        damage -= self.spi * 1 * obj.spi_f / 100    # Spirit F of the target
      end
      
      # Apply physical vulnerability if the atk_f is > 0
      damage *= state_multiplier(:phys_vul) if obj.atk_f > 0
      # Apply magical vulnerability if the spi_f is >0
      damage *= state_multiplier(:magic_vul) if obj.spi_f > 0
      damage = Integer(damage) # I did math in floats but VX wants ints so oops
      
      damage = 0 if damage < 0                      # If negative, make 0
    elsif damage < 0                                # a negative number?
      damage -= user.atk * 4 * obj.atk_f / 100      # Attack F of the user
      damage -= user.spi * 2 * obj.spi_f / 100      # Spirit F of the user
    end
    damage *= elements_max_rate(obj.element_set)    # elemental adjustment
    damage /= 100
    damage = apply_variance(damage, obj.variance)   # variance
    damage = apply_guard(damage)                    # guard adjustment
    if obj.damage_to_mp  
      @mp_damage = damage                           # damage MP
    else
      @hp_damage = damage                           # damage HP
    end
  end

end
This does work, however it also seems that it does make YERDs Custom Damage Formula useless, which I wouldn't want.

I will post the script here. It's a bit altered from the original to make the thing work I talked about earlier.
https://pastebin.com/V35jdSqc
Sure, I grabbed that and added my vulnerability to it. Demo link. Since the YERD Custom Damage has its own ATK & SPI F values, my script uses those >0 to tell if physical or magic vulnerability apply (attack for physical, spirit for magical). I tagged my changes with GRS in the YERD Custom Damage script in the demo project if you want to see and make further changes to what I did.
This solves the issue. Thank you very much!

I'm a lil' embarrassed to admit, but I do not know how to set the state_multiplier(:phys_vul) and magic_vul respectively.
Now, I also assume these are meant for increasing the actors damage output, i.e. apply state to actor so that he/she deals double physical/magical damage.
If that is not the case I apologize for the ignorance, considering my aim, from the start, wasn't it to just have a Defense buff/debuff, but also Strength/Magic buffs/debuffs work this way as well. If it sounded like I was aiming for a just the Protect/Shell Magic like states, then I apologize for that as well lol
Check the Vulnerability Up, Protect, and Shell states. In their notes they have stuff like:

<physvul 200>
<magicvul 200>

<physvul 50>

<magicvul 50>

It sets the vulnerability and is treated like a % where 100 is 100%. Higher numbers = more vulnerable to physical/magical damage, so <physvul 200> is 200% vulnerable, or x2 damage from physical damage. Lower numbers is less vulnerable, so <magicvul 50> is 50% vulnerable, or 50% vulnerable to magic attacks.

These stack multiplicatively, so if a character has both Vulnerability Up and Protect, they have 200% * 50% = 100% physical vulnerability.

This only applies to states right now. There's no other way to get vulnerability as I coded it.

As I did it, the vulnerability is only applied to the target of damage too. A battler can't do extra damage because of a state they have (ie Physical Damage up or so) since I didn't think of that at all. I can make changes if you want that.

e: reread and yeah, I did miss you wanted the buffs completely. I'll add that too
If doubling your own damage output, by increasing your own Atk, isn't feasible then that wouldn't be the end of the world, since I do have a backup plan for that.
It'd just be nice to have the option though
I was going to make a state flag that gives bonus damage when the attacker has it. It wont' change ATK/SPI or any other stat, but the state could say "150% physical damage" and all physical damage would be multiplied by x1.5 (aka +50% damage)
That's exactly what I want. Just a straight percentile increase in physical and magical damage output
Alright, third demo project: Download here!

I added a new property to states, seen in the Physical Damage Up and Magic Damage Up:

<physdmg 200>
<magicdmg 200>

With these states the attacker's physical and magic damage are increased. Like vulnerability, 200 = 200% = x2 damage, 100 = 100% = no change, 50 = 50% = x0.5 damage, stacks multiplicatively.

This is not applied to healing! Damage boost & vulnerability are only applied if a skill's base damage is 1 or greater. There might be other cases I missed with all the other damage algorithm bits too.

CHeck the YERD Custom Damage GRS bits, the new line of code is stuff like:
damage *= user.state_multiplier(:phys_dmg)

damage *= user.state_multiplier(:magic_dmg)

That happens right after the vulnerability checks.
(Regular attacks are a bit different, the "user" is called "attacker" there)


Does this cover your use cases? And if you experience any bugs, let me know!
Everything works just like I wanted it! Thank you so much for the trouble!
Of course, I'll make sure to credit you in my Games for these Scripts. I hope it wasn't too much trouble!

Should any problems arise then I'll make sure to private message you. At the moment there are many battles I need to look through and a lot of boss fights are unique in how they are handled. I am 100% sure that this change won't affect them though.
Again, thank you so much!
Glad to hear it! Good luck with your game.
Pages: 1