VXAce Problem with make_damage_value & item_element_rate

Gentlemans, during combat, damage with elements is calculated incorrectly.
I changed the Game_battler item_element_rate so that while the attribute effectiveness coefficient was being calculated, conditions were being added/removed from me.
Ruby:
  def item_element_rate(user, item)
    $game_variables[15] = user.features_set(FEATURE_ATK_ELEMENT)
    $game_variables[16] = item.damage.element_id
    $game_variables[17] = element_rate(item.damage.element_id)
    case item.damage.element_id
      when 7 #earth
      result = user.atk_elements.empty? ? 1.0 : elements_max_rate(user.atk_elements)
      if state?(29)
        add_state(33)
        remove_state(29)
      end
      if state?(30)
        add_state(26)
        remove_state(30)
      else
        remove_state(26)
      end
    return result
      when 3 #fire
      result = user.atk_elements.empty? ? 1.0 : elements_max_rate(user.atk_elements)
      if state?(27)
        add_state(31)
        remove_state(27)
      end
      if state?(32)
        add_state(28)
        remove_state(32)
      else
        remove_state(28)
      end
    return result
      when 4 #frost
      result = user.atk_elements.empty? ? 1.0 : elements_max_rate(user.atk_elements)
      if state?(28)
        add_state(32)
        remove_state(28)
        end
      if state?(31)
        add_state(27)
        remove_state(31)
      else
        remove_state(27)
      end
    return result
        when 8 #air
      result = user.atk_elements.empty? ? 1.0 : elements_max_rate(user.atk_elements)
      if state?(26)
        add_state(30)
        remove_state(26)
      end
      if state?(33)
        add_state(29)
        remove_state(33)
      else
        remove_state(29)
      end
    return result
  else element_rate(item.damage.element_id)
  end
  $game_variables[18] = result
  end
But when I entered battle, conditions were being added/removed, but the damage of my attribute-based skills didn't change on targets with attribute effectiveness.
Ruby:
  def make_damage_value(user, item)
    value = item.damage.eval(user, self, $game_variables)
    $game_variables[19] = value
    value *= item_element_rate(user, item)
    $game_variables[20] = value
    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)
    $game_variables[21] = value
    @result.make_damage(value.to_i, item)
  end
I added lines so that the values were written to game_variables, but that didn't help me figure out the problem.
Because after looking at the variables, I saw that
variable 17 = 0.0
variable 18 = 0
variable 19 = 800
variable 20 = 800.0
even though variable 20 should be 0 and damage 0 when the expression value *= item_element_rate(user, item) was executed, where item_element_rate(user, item) is 0.
Help me find the error. PLZ
UPD
I noticed that the lines value *= pdr if item.physical? and value *= mdr if item.magical? don't change the value regardless of the value. It's as if the value doesn't change at all and the damage is dealt according to the formula.
Hello,

even though variable 20 should be 0 and damage 0 when the expression value *= item_element_rate(user, item) was executed, where item_element_rate(user, item) is 0.
Help me find the error. PLZ
Can you give more context to the skill/item you used? Like which elements did you use?

Just so you know, variable 18 will almost always be 0 in your code unless your item element is neither 3,4,7 nor 8. The reason why is because no lines will be executed after performing a return in a method, so $game_variables[18] = result will not be executed, in fact, if it is executed by using another element, then your game is likely to crash because result does not exist.

So I suspect you did not have any specific element rate for the target and the result of item_element_rate is indeed 1.0.

I noticed that the lines value *= pdr if item.physical? and value *= mdr if item.magical? don't change the value regardless of the value.
Unless pdr or mdr were modified by the target (being general physical resistance or magical resistance), then they won't change the value because they are 1.0 by default, so not a bug.



As a side note, you should probably avoid modifying states when calling item_element_rateas it may be used outside of using the item or skill, which could create some weird behaviors.
I suggest you use the state modification before or after the use of your item.

Here is a modified version of your code by me, I removed the variables modifications, synthetized some of your code and moved the states change to a more proper place:
Ruby:
class Game_Battler < Game_BattlerBase
  #--------------------------------------------------------------------------
  # new method: convert_state -> turn original state into another if the state
  # is here
  #--------------------------------------------------------------------------
  def convert_state(original_state, new_state)
    return unless state?(original_state)
    add_state(new_state)
    remove_state(original_state)
  end
 
  #--------------------------------------------------------------------------
  # new method: element4_states
  #--------------------------------------------------------------------------
  def element4_states(element_id)
    case element_id
    when 3 #fire
      convert_state(27, 31)
      convert_state(32, 28)
    when 4 # frost
      convert_state(28, 32)
      convert_state(31, 27)
    when 7 #earth
      convert_state(29, 33)
      convert_state(30, 26)
    when 8 #air
      convert_state(26, 30)
      convert_state(33, 29)
    end
  end
 
  #--------------------------------------------------------------------------
  # alias method: item_element_rate -> 4 base elements (3,4,7,8) are handled
  # like attack element (comment: not recommended to use this modified method)
  #--------------------------------------------------------------------------
  alias tim_elem4_item_element_rate item_element_rate
  def item_element_rate(user, item)
    case item.damage.element_id
    when 3,4,7,8 #if element if one of the main 4:
      user.atk_elements.empty? ? 1.0 : elements_max_rate(user.atk_elements)
    else #default behavior if another element is used:
      tim_elem4_item_element_rate(user,item)
    end
  end
 
  #--------------------------------------------------------------------------
  # alias method: item_apply -> states are modified if item has hit self
  #--------------------------------------------------------------------------
  alias tim_elem4_item_apply item_apply
  def item_apply(user, item)
    tim_elem4_item_apply(user, item) #call original method
    element4_states(item.damage.element_id) if @result.hit?
  end
end #Game_Battler
Hi, thanks for your reply.
Can you give more context to the skill/item you used? Like which elements did you use?
3, 4, 7, 8 are the elements of fire, ice, earth, and air, as they were in my default state.
I have elemental defense, in which the four different elements deal different damage and change certain states.
I cast a defense with 0% fire attribute effectiveness, but a fire spell that deals 800 damage dealt me 400 damage. When I cast the same spell on a target with this defense effect, it dealt 800 damage (I tried removing everything related to attack attributes from the character).
Unless pdr or mdr were modified by the target (being general physical resistance or magical resistance), then they won't change the value because they are 1.0 by default, so not a bug.
I had a state in which my mdr and fdr were changed, but the damage did not change at all.

Thanks for the help, but it didn't work and the damage didn't change. I need to understand more about how damage from attribute-based skills and attack effects is calculated.
If any other information is needed, I will be happy to provide it.
I have elemental defense, in which the four different elements deal different damage and change certain states.
When you say they deal different damage, what do you mean? Where is this different damage represented?

I cast a defense with 0% fire attribute effectiveness, but a fire spell that deals 800 damage dealt me 400 damage. When I cast the same spell on a target with this defense effect, it dealt 800 damage (I tried removing everything related to attack attributes from the character).
Can you show the state page in your database? Same question for the skill you've used.
Also, if you use my code you should remove my modifications to [FONT=Monaco, Menlo, Consolas, Roboto Mono, Andale Mono, Ubuntu Mono, monospace]item_element_rate and keep the vanilla behavior, the reason why is because I followed your original code by replacing the 4 elements with the attack elements. So this might be the source of your weird damage result.[/FONT]

[FONT=Monaco, Menlo, Consolas, Roboto Mono, Andale Mono, Ubuntu Mono, monospace]Also note that if you used the guard effect (from the guard state and skill), then any damage taken will be halved. Dunno if that applies here.[/FONT]

I had a state in which my mdr and fdr were changed, but the damage did not change at all.
What is the hit type of the skill you used?
If it is "certain hit", then pdr and mdr won't apply. You can check the hit type of a skill like this:

1764319009262.png

(also note that fdr is floor damage rate, which is related to map damage)

Edit: A good way to check if there is a database issue is to test your skill on a project with no script.
You should be able to see if there is an issue. If there is, it is very likely to be a mistake in your parameters.

Then, if it worked, you can test the skill in your project but without your script or mine, if it does not work, then it's probably another script from your project that mess things up.

Finally, if it worked for both cases, then this is indeed an issue with both mine and your code. I really think removing the modifications to item_element_rate should do the trick.

I need to understand more about how damage from attribute-based skills and attack effects is calculated.
Maybe the damage flow explanation can help you.
When you say they deal different damage, what do you mean? Where is this different damage represented?
Я попробовал сделать это с помощью element_rate
1764352772204.png

Can you show the state page in your database? Same question for the skill you've used.
1764352862062.png


What is the hit type of the skill you used?
If it is "certain hit", then pdr and mdr won't apply.
brooooooo, you just pointed out something I needed to pay attention to. lol
When I created these custom skills, I didn't change the hit type (because I didn't know anything about them)
(also note that fdr is floor damage rate, which is related to map damage)
my bad, i fixed it and it worked
Edit: A good way to check if there is a database issue is to test your skill on a project with no script.
You should be able to see if there is an issue. If there is, it is very likely to be a mistake in your parameters.
It worked when I deleted both mine and yours from the rate item element and everything seemed to work as it should.(but I launched it many times and sometimes with the same element rate I got different damage numbers (800 or 1600), although I checked the states and their element rate(I can pretend it's RNG 🙂 ))
Maybe the damage flow explanation can help you.
Thanks bro, I'll get to reading this article.
It worked when I deleted both mine and yours from the rate item element and everything seemed to work as it should.(but I launched it many times and sometimes with the same element rate I got different damage numbers (800 or 1600), although I checked the states and their element rate(I can pretend it's RNG 🙂 ))

Do you mean that you've experienced it without any script or did you use something like my script below? (same script without the item_element_ratepart)

Ruby:
class Game_Battler < Game_BattlerBase
  #--------------------------------------------------------------------------
  # new method: convert_state -> turn original state into another if the state
  # is here
  #--------------------------------------------------------------------------
  def convert_state(original_state, new_state)
    return unless state?(original_state)
    add_state(new_state)
    remove_state(original_state)
  end
 
  #--------------------------------------------------------------------------
  # new method: element4_states
  #--------------------------------------------------------------------------
  def element4_states(element_id)
    case element_id
    when 3 #fire
      convert_state(27, 31)
      convert_state(32, 28)
    when 4 # frost
      convert_state(28, 32)
      convert_state(31, 27)
    when 7 #earth
      convert_state(29, 33)
      convert_state(30, 26)
    when 8 #air
      convert_state(26, 30)
      convert_state(33, 29)
    end
  end
 
  #--------------------------------------------------------------------------
  # alias method: item_apply -> states are modified if item has hit self
  #--------------------------------------------------------------------------
  alias tim_elem4_item_apply item_apply
  def item_apply(user, item)
    tim_elem4_item_apply(user, item) #call original method
    element4_states(item.damage.element_id) if @result.hit?
  end
end #Game_Battler

If it's the case, then maybe one of added state in element4_states did modify the element weakness for the next attacks? Or maybe the pdr/mdr?

Otherwise I can't explain it since you have no critical nor variance in your skill parameters.
Hi!
Do you mean that you've experienced it without any script or did you use something like my script below? (same script without the item_element_ratepart)
I removed the change from yours (the same script without the item_element_rate part)
If it's the case, then maybe one of added state in element4_statesdid modify the element weakness for the next attacks? Or maybe the pdr/mdr?
All states in element4_states manipulate element weakness. However, for some reason, item_element_rate sometimes works incorrectly, and damage values don't correspond to element weakness(maybe I overloaded this moment).
I tested it without any extra effects and didn't make any pdr/mdr changes during the tests.
Well I curently have no idea what is the source of your issue and I won't be able to help for quite some time so hopefuly someone else can solve your issue :/

Original thread: https://forums.rpgmakerweb.com/threads/problem-with-make_damage_value-item_element_rate.181189/