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.

Script Request: Method for making character or enemy not selectable in battle

Basically I'm looking for what I'm assuming should be a relatively small script.  What I'm looking to do is to  have a status effect state that will call a script that allows the affected character or enemy to not be allowed to be selected by an attack or an "attack single enemy skill" command during battle for the duration of the state.  The idea is the character affected can not be seen, so I don't want the AI to waste attacks on something that can't be hit and is not supposed to be hit. Any help in this regard would be greatly appreciated, and credit will be given as is custom.
 

poccil

Sponsor

You would edit the exist? method of Game_Battler:

Code:
  def exist?
    # 2 here is the number of a state
    return !self.state?(2) && (not @hidden and (@hp > 0 or @immortal))
  end

[--Actually that approach doesn't work as I expected--]
 
You would think that would work...  Is it possible that the exist method is only utilized by the random targeting and last targeting selection methods in the Game_BattleAction class?

I suppose a modification could be made to the update_phase3_enemy_select method in Scene_Battle 3 class???  Thanks for the help btw.
Code:
#--------------------------------------------------------------------------
  # * Frame Updat (actor command phase : enemy selection)
  #--------------------------------------------------------------------------
  def update_phase3_enemy_select
    # Update enemy arrow
    @enemy_arrow.update
    # If B button was pressed
    if Input.trigger?(Input::B)
      # Play cancel SE
      $game_system.se_play($data_system.cancel_se)
      # End enemy selection
      end_enemy_select
      return
    end
    # If C button was pressed
    if Input.trigger?(Input::C)
      # Play decision SE
      $game_system.se_play($data_system.decision_se)
      # Set action
      @active_battler.current_action.target_index = @enemy_arrow.index
      # End enemy selection
      end_enemy_select
      # If skill window is showing
      if @skill_window != nil
        # End skill selection
        end_skill_select
      end
      # If item window is showing
      if @item_window != nil
        # End item selection
        end_item_select
      end
      # Go to command input for next actor
      phase3_next_actor
    end
  end

I'm guessing with my limited knowledge of scripting that a change in this could enable me to add an if statement that wouldn't allow the player to choose a target that I don't want to be selectable in the manner I described?  That would be half the battle at least.

Something to the tune of

If enemy_battler_state == i
play cancel sound
else
end enemy selection
 
I will try to help you out. Try doing this:

In Scene_Battle 4 Add this line:

Code:
contador = 0
          while target.states.include?(2) == true and contador < 9
          target = $game_party.smooth_target_actor(rand($game_party.actors.size))
          contador += 1
        end
      if contador == 9
      $game_temp.forcing_battler = nil
      @phase4_step = 1
      return
      end

Just after this one:

Code:
      
# If action battler is enemy
      if @active_battler.is_a?(Game_Enemy)
        if @active_battler.restriction == 3
          target = $game_troop.random_target_enemy
        elsif @active_battler.restriction == 2
          target = $game_party.random_target_actor
        else
          index = @active_battler.current_action.target_index
          target = $game_party.smooth_target_actor(index)

In Scene_Battle 3, after this:

Code:
  
#--------------------------------------------------------------------------
  # * Frame Updat (actor command phase : enemy selection)
  #--------------------------------------------------------------------------

change the whole code block, to this one:

Code:
  def update_phase3_enemy_select
    # Update enemy arrow
    @enemy_arrow.update
    # If B button was pressed
    if Input.trigger?(Input::B)
      # Play cancel SE
      $game_system.se_play($data_system.cancel_se)
      # End enemy selection
      end_enemy_select
      return
    end
    # If C button was pressed
    if Input.trigger?(Input::C) and $game_troop.enemies[@enemy_arrow.index].states.include?("put the id of your state") != true
      # Play decision SE
      $game_system.se_play($data_system.decision_se)
      # Set action
      @active_battler.current_action.target_index = @enemy_arrow.index
      # End enemy selection
      end_enemy_select
      # If skill window is showing
      if @skill_window != nil
        # End skill selection
        end_skill_select
      end
      # If item window is showing
      if @item_window != nil
        # End item selection
        end_item_select
      end
      # Go to command input for next actor
      phase3_next_actor
    elsif Input.trigger?(Input::C)
      $game_system.se_play($data_system.cancel_se)
    end
  end

Now, in those code, just change the part that says: "put the id of your state" to whatever you like.

The enemies will not attack any party member who have the state effect of your choice. Also, the player will not be able to attack an enemy with the state effect.
 
Works great but there's a bug on the enemies side of the issue.  If none of the actor party is selectable the script hangs.  How can we force another action to break that loop and keep the battle moving?  Thanks a lot btw.  I think I'm starting to get at how the engine works on a basic level.  This has been very helpful.

*update*

I just saw your update and made the new changes but now I'm getting a no method error on this line 229 of that battle_scene 4:

"undefined method for 'current_action' for nil:nilClass"

Here's what's on that line:
Code:
if @active_battler.current_action.basic == 1
 

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