Heal spell causes damage instead of healing...

● ARCHIVED · READ-ONLY
Started by Napoleon 7 posts View original ↗
  1. So I made this free script to always deal a certain minimum amount of damage. But sadly the heal spell (and a few other skills) now cause damage instead of healing. And some skills damage both the enemy AND me...

    I have no idea why. It's something simple I know it.

    Script (updated):

    Spoiler
    #sb:nap_min_dmg [battle]=beginAuthor: NapoleonVersion: 1.01About: Both you and enemies now always deal a minimum damage (percentage) when       dealing damage. This is to prevent doing 0 damage or just not enough       damage when an ally/enemy has just too much defense.Note:  When dealing percentage damage the percentage is based on a single       attack/magic damage * percentage. And not "attack x4" for example.License: CC3 (But attribution is not required).=end$imported ||= {}$imported[:nap_min_damage] = 1.01#===============================================================================# Settings#===============================================================================module Nap; module Battle  MIN_DMG_PERC = 0.25 # A value between 0.0 and 1.0  MIN_DMG      = 1  # The absolute minimum amount of damage dealt no matter whatend; end#===============================================================================# RPG::UsableItem::Damage# For: Never deal less than Nap::Battle::MIN_DMG damage for a damaging-ability#===============================================================================class RPG::UsableItem::Damage  alias nap_min_dmg_eval eval  def eval(a, b, v)    damage = nap_min_dmg_eval(a, b, v)    # if-check is required because HP/MP Recovery is a negative value.    damage >= 0 ? [damage, Nap::Battle::MIN_DMG].max : damage  endend#===============================================================================# Game Battler# For: To ensure to deal a minimum amount of damage (in %) when the target's#      defense is too high (part 1/2).#===============================================================================class Game_Battler < Game_BattlerBase  #-----------------------------------------------------------------------------  # Make Damage Value                                                    [ALIAS]  #-----------------------------------------------------------------------------  alias nap_min_dmg_perc_make_damage_value make_damage_value  def make_damage_value(user, item)    $nap_temp_battle_user = user    nap_min_dmg_perc_make_damage_value(user, item)  endend#===============================================================================# Game Action Result# For: To ensure to deal a minimum amount of damage (in %) when the target's#      defense is too high (part 2/2).#===============================================================================class Game_ActionResult  #-----------------------------------------------------------------------------  # Make Damage                                                          [ALIAS]  #-----------------------------------------------------------------------------  alias nap_min_dmg_perc_make_damage make_damage  def make_damage(value, item)    user = $nap_temp_battle_user    $nap_temp_battle_user = nil        # Return normally if it's a hp/mp recovery.    return nap_min_dmg_perc_make_damage(value.to_i, item) if item.damage.type.between?(3, 4)    if ((item.physical?) || item.certain?) && (value <= (user.atk * Nap::Battle::MIN_DMG_PERC))      value = (user.atk * Nap::Battle::MIN_DMG_PERC)    elsif value <= (user.mat * Nap::Battle::MIN_DMG_PERC)      value = (user.mat * Nap::Battle::MIN_DMG_PERC)    end    nap_min_dmg_perc_make_damage(value.to_i, item)  endend#===============================================================================
    I'm aware of the:

    item.damage.type == 3 # 3 = hp recoverybut I can't find a use for it.

    I also tried:

    def eval(a, b, v) damage = nap_min_dmg_eval(a, b, v) if damage >= 0 # if-check is required because HP Recovery is a negative value. return [damage, Nap::Battle::MIN_DMG].max else return damage end endto prevent it from making a negative value positive. But... to no avail.
  2. This

    item.damage.type == 3 # 3 = hp recoveryUsed to determine this

     

    RPG::UsableItem::Damage # the explanation from the help file
    recover? <= this method
    Determines whether there is recovery. Returns true if the value of type is 3 or 4. <= type is 3
    Then the implementation is in here :#===============================================================================# 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? # <= not do this line    value *= mdr if item.magical? # <= not do this line    value *= rec if item.damage.recover? # <= In here, if the item above item.damage.type == 3 then it will do this line.    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)  endNow for why it won't heal, see here:

    RPG::UsableItem::Damage # This is from the help file

    eval(a, b, v)# The explanation from the help file
    Evaluates the formula. The action-side battler, target-side battler, and in-game variable array ($game_variables) are specified by a, b, and v, respectively.
    Returns a negative value if recovery. <= Consider this, while you always do this => (if value <= something then blablah..)
    Now this is your method: def eval(a, b, v) damage = nap_min_dmg_eval(a, b, v) if damage >= 0 # if-check is required because HP Recovery is a negative value. <= your original comment return [damage, Nap::Battle::MIN_DMG].max # <= this will never return negative value else return damage endendHope it helps you..
  3. This method does return a negative value if the damage is negative. I put a print there and it does return a negative value.

    def eval(a, b, v)  damage = nap_min_dmg_eval(a, b, v)  if damage >= 0 # if-check is required because HP Recovery is a negative value. <= your original comment   return [damage, Nap::Battle::MIN_DMG].max # <= this will never return negative value  else   return damage # <<< this is the line that will return a negative value if the damage was negative. Works nicely. I'm not sure what you meant by not being able to return a negative value.  endend
    I do believe that I might have solved it by adding a 'quick and dirty line to':

    return nap_min_dmg_perc_make_damage(value.to_i, item) if item.damage.type.between?(3, 4) # Return normally if it's a hp/mp recovery.
    Code:
    class Game_ActionResult  #-----------------------------------------------------------------------------  # Make Damage                                                          [ALIAS]  #-----------------------------------------------------------------------------  alias nap_min_dmg_perc_make_damage make_damage  def make_damage(value, item)    return nap_min_dmg_perc_make_damage(value.to_i, item) if item.damage.type.between?(3, 4) # Return normally if it's a hp/mp recovery.    user = $game_variables[Nap::Battle::GAME_VAR_IDX]    $game_variables[Nap::Battle::GAME_VAR_IDX] = nil    if ((item.physical?) || item.certain?) && (value <= (user.atk * Nap::Battle::MIN_DMG_PERC))      value = (user.atk * Nap::Battle::MIN_DMG_PERC)    elsif value <= (user.mat * Nap::Battle::MIN_DMG_PERC)      value = (user.mat * Nap::Battle::MIN_DMG_PERC)    end    nap_min_dmg_perc_make_damage(value.to_i, item)  endend
    I'm not fully sure if I solved the problem but heal skills and items both heal properly now and also return negative values. So it might be good now.
  4. Oh, yes it was a mistake, I'm not read it carefully earlier, sorry..

    Well I do believe something goes wrong in here

    user = $game_variables[Nap::Battle::GAME_VAR_IDX] # this should not make a problem    $game_variables[Nap::Battle::GAME_VAR_IDX] = nil # <= this should not make a problem# probably the conditional below is the problem    if ((item.physical?) || item.certain?) && (value <= (user.atk * Nap::Battle::MIN_DMG_PERC))      value = (user.atk * Nap::Battle::MIN_DMG_PERC)    elsif value <= (user.mat * Nap::Battle::MIN_DMG_PERC)      value = (user.mat * Nap::Battle::MIN_DMG_PERC)    endBut if you have solved it, then it's great :) Even with a dirty method, if it's work then it works. Good job ^_^b
  5. Agreed, that conditional does never return a negative value. That's why I added the return in an attempt to fix it with one line.

    I only solved it (if it's solved) because of your post though. It gave me some new insights.
  6. Glad I can be some help to you, :)  
  7. Why don't you just follow through the RTP scripts and see what they do?