Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Items/Skills that target living allies but also remove Dead status

Please allow me to skip the extemporaneous formalities, as I feel this BUGFIX (maybe it isn't technically, but it sure feels like it would be) should be so simple even I could do it...and yet I CAN'T seem to find the solution on my own.  Since it's been 24 hours since trying to figure this out, I ask the group: 

Anybody know how to make items/skills that heal One OR All allies, but include Dead allies IF the item/skill removes dead status? 

Scenario:  I want to create an item or skill that restores HP to all allies, and removes the "Dead" status for any allies that are dead.  Copping out by having the item or skill call a Common Event requires me to synthetically and inaccurately recreate the item's intended effects.  I'm looking for a fix to RMXP. 

It seems natural to believe that this would require a script fix. 

Can't delete this post, which probably doesn't belong here, so just ignore it, I guess.  Unless you WANT to answer it. 
 

poccil

Sponsor

The problem is actually rather complicated, because the targeting function checks whether a battler exists (has 1 or more HP and is not hidden) before it adds a battler as a target.  The set_target_battlers method of Scene_Battle must be modified, therefore, to allow an exception for skills and items that remove the "Knockout" state.  The code that does this follows.  Note that it also adds methods to Game_Battler for determining whether a skill removes the "Knockout" state.

Code:
class Game_Battler
  def skillRemovesDead?(skill)
      return false if !skill
      removesDead=false
      for i in 1...$data_states.size
       # If this state has the flag "Regard as HP 0" and this skill removes this state
       if $data_states[i] && $data_states[i].zero_hp && skill.minus_state_set.include?(i)
        removesDead=true
        break
       end
      end
      return removesDead
  end
  def existOrRemovesDead?(skill)
     return self.exist? || skillRemovesDead?(skill)
  end
end

class Scene_Battle
  def modifiedSmoothTarget(group,index,skill)
    # Get an actor
    battlers=group.is_a?(Game_Party) ? group.actors : group.enemies
    actor = battlers[index]
    # If an actor exists
    if actor != nil and actor.existOrRemovesDead?(skill)
      return actor
    end
    # Loop
    for actor in battlers
      # If an actor exists
      if actor.existOrRemovesDead?(skill)
        return actor
      end
    end
  end
  def set_target_battlers(scope)
    # If battler performing action is enemy
    skill = @active_battler.current_action.kind==1 ? @skill : @item
    if @active_battler.is_a?(Game_Enemy)
      # Branch by effect scope
      case scope
      when 1  # single enemy
        index = @active_battler.current_action.target_index
        @target_battlers.push(modifiedSmoothTarget($game_party,index,skill))
      when 2  # all enemies
        for actor in $game_party.actors
          if actor.existOrRemovesDead?(skill)
            @target_battlers.push(actor)
          end
        end
      when 3  # single ally
        index = @active_battler.current_action.target_index
        @target_battlers.push(modifiedSmoothTarget($game_troop,index,skill))
      when 4  # all allies
        for enemy in $game_troop.enemies
          if enemy.existOrRemovesDead?(skill)
            @target_battlers.push(enemy)
          end
        end
      when 5  # single ally (HP 0) 
        index = @active_battler.current_action.target_index
        enemy = $game_troop.enemies[index]
        if enemy != nil and enemy.hp0?
          @target_battlers.push(enemy)
        end
      when 6  # all allies (HP 0) 
        for enemy in $game_troop.enemies
          if enemy != nil and enemy.hp0?
            @target_battlers.push(enemy)
          end
        end
      when 7  # user
        @target_battlers.push(@active_battler)
      end
    end
    # If battler performing action is actor
    if @active_battler.is_a?(Game_Actor)
      # Branch by effect scope
      case scope
      when 1  # single enemy
        index = @active_battler.current_action.target_index
        @target_battlers.push(modifiedSmoothTarget($game_troop,index,skill))
      when 2  # all enemies
        for enemy in $game_troop.enemies
          if enemy.existOrRemovesDead?(skill)
            @target_battlers.push(enemy)
          end
        end
      when 3  # single ally
        index = @active_battler.current_action.target_index
        @target_battlers.push(modifiedSmoothTarget($game_party,index,skill))
      when 4  # all allies
        for actor in $game_party.actors
          if actor.existOrRemovesDead?(skill)
            @target_battlers.push(actor)
          end
        end
      when 5  # single ally (HP 0) 
        index = @active_battler.current_action.target_index
        actor = $game_party.actors[index]
        if actor != nil and actor.hp0?
          @target_battlers.push(actor)
        end
      when 6  # all allies (HP 0) 
        for actor in $game_party.actors
          if actor != nil and actor.hp0?
            @target_battlers.push(actor)
          end
        end
      when 7  # user
        @target_battlers.push(@active_battler)
      end
    end
  end
end

There's another facet to this problem.  The code for skill and item effects is found at lines 108-112 and lines 214-218, respectively, of the script section Game_Battler.  Both contain the following:
Code:
    # If skill scope is for ally with 1 or more HP, and your own HP = 0,
    # or skill scope is for ally with 0, and your own HP = 1 or more
    if ((skill.scope == 3 or skill.scope == 4) and self.hp == 0) or
       ((skill.scope == 5 or skill.scope == 6) and self.hp >= 1)
      # End Method
      return false
    end

By default, effects that target a single ally or all allies affect only those with HP greater than 1.  Thus, those effects cannot simultaneously target allies with HP 0.  You can, however, modify the code to grant an exception to this rule for certain skills:

Code:
    # If skill scope is for ally with 1 or more HP, and your own HP = 0
    if ((skill.scope == 3 or skill.scope == 4) and self.hp == 0)
      # End method unless skill removes "Knockout" state
      return false unless skillRemovesDead?(skill)
    end
    # If skill scope is for ally with 0, and your own HP = 1 or more
    if ((skill.scope == 5 or skill.scope == 6) and self.hp >= 1)
      return false
    end
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top