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.

Status effect request - Guess this has to be scripted

Hello, dear scripters.
I was planning a boss battle for my game, but ran into a problem...
I need a status effect, that one nemy (not the boss himself) casts on itself. Now as long as this status is active the player should not be able to attack the boss, but the other monsters. (Note that there are two of those) If the player tries I would like a message box to appear with some text like: "Helper protected boss" (Has to be customizable of course)

As far as I can see this requires scripting, and I would be really glad if someone would do that for me.

Thanks in advance

~Dalton~
 
Thanks. If you do it i am sure it will turn out great. Take your time.

Sorry for the late replie, but I am not at home at the moment, so I don't see a computer very often. But tomorrow i will be back home. So my replies will become faster again.

Thank you again in advance, SephirothSpawn.
 
first make sure your boss is id no 2 (i.e enemy 2) in your troop
1. make a status effect call it "Protected"
2. Set evade to 100
3. then make a newskill call it "Protect"
4. set up it up so target is none
5. make it call a common event that sets a few variable to enemy 2's stats (enemy 2 should be our boss)
6. make it add the status effect  protected to enemy 2
7. then make a conditon that depending on the values of the variables we set prints our a message box like so "<insert boss nme> has been protected" 
 
Good Idea, but sadly one of my characters has a skill, that ignores the enemies evade value, so it never misses.

So this wouldn't work here.

Thank you, anyways. But I guess I really need a script for this.
 
I made a script that works with the basic combat system, but I didn't try it with a CBS.

You need two additionnal states : "Protected" and "Protection".
You must add the state "Protected" to the boss at the beginning of the battle.
The enemy able to protect the boss shall have a skill which adds the state "Protection" to him.

Here's the script (paste it above main as usual) :
Code:
 25/03/08 - MGCaladtogel
#==============================================================================
# ** Game_Battler
#==============================================================================

class Game_Battler
  attr_accessor :protectors
  attr_accessor :protected
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  alias initialize_protect initialize
  def initialize
     initialize_protect
    self.protectors = Array.new
    self.protected = false
  end
  #--------------------------------------------------------------------------
  # * add_protector
  #     member : Game_Battler (protector)
  #--------------------------------------------------------------------------
  def add_protector(battler)
    self.protectors.push(battler)
  end
  #--------------------------------------------------------------------------
  # * remove_protector
  #     member : Game_Enemy (protector)
  #--------------------------------------------------------------------------
  def remove_protector(battler)
    self.protectors.delete(battler)
  end
  #--------------------------------------------------------------------------
  # * protected?
  #--------------------------------------------------------------------------
  def protected?
    result = false
    if protectors.size > 0
      for battler in protectors
        battler.dead? ? remove_protector(battler) : result = true
      end
    end
    return result
  end
  #--------------------------------------------------------------------------
  # * select_protector
  #--------------------------------------------------------------------------
  def select_protector
    protector =  protectors[rand(protectors.size)]
  end
  #--------------------------------------------------------------------------
  # * Add State
  #     state_id : state ID
  #     force    : forcefully added flag (used to deal with auto state)
  #--------------------------------------------------------------------------
  alias add_state_protect add_state
  def add_state(state_id, force = false)
    add_state_protect(state_id, force)
    if $data_states[state_id].name.include?("Protected")
      self.protected = true
    end
    if $data_states[state_id].name.include?("Protection")
      if self.is_a?(Game_Enemy)
        for enemy in $game_troop.enemies
          enemy.add_protector(self) if enemy.protected
        end
      else
        for actor in $game_party.actors
          actor.add_protector(self) if actor.protected
        end
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Remove State
  #     state_id : state ID
  #     force    : forcefully removed flag (used to deal with auto state)
  #--------------------------------------------------------------------------
  alias remove_state_protect remove_state
  def remove_state(state_id, force = false)
    remove_state_protect(state_id, force)
    if $data_states[state_id].name.include?("Protected")
      self.protected = false
    end
    if $data_states[state_id].name.include?("Protection")
      if self.is_a?(Game_Enemy)
        for enemy in $game_troop.enemies
          enemy.remove_protector(self)
        end
      else
        for actor in $game_party.actors
          actor.remove_protector(self)
        end
      end
    end
  end
end

#==============================================================================
# ** Scene_Battle
#==============================================================================

class Scene_Battle
  #--------------------------------------------------------------------------
  # * Make Basic Action Results
  #--------------------------------------------------------------------------
  def make_basic_action_result
    # If attack
    if @active_battler.current_action.basic == 0
      # Set anaimation ID
      @animation1_id = @active_battler.animation1_id
      @animation2_id = @active_battler.animation2_id
      # 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)
        end
      end
      # If action battler is actor
      if @active_battler.is_a?(Game_Actor)
        if @active_battler.restriction == 3
          target = $game_party.random_target_actor
        elsif @active_battler.restriction == 2
          target = $game_troop.random_target_enemy
        else
          index = @active_battler.current_action.target_index
          target = $game_troop.smooth_target_enemy(index)
        end
      end
      # Set array of targeted battlers
      @target_battlers = [target]
      # Apply normal attack results
      for target in @target_battlers
        if target.protected?
          new_target = target.select_protector
          @target_battlers.push(new_target) if !@target_battlers.include?(new_target)
          @target_battlers.delete(target)
          @help_window.set_text(new_target.name + " protected " + target.name, 1)
        end
      end
      for target in @target_battlers
        target.attack_effect(@active_battler)
      end
      return
    end
    # If guard
    if @active_battler.current_action.basic == 1
      # Display "Guard" in help window
      @help_window.set_text($data_system.words.guard, 1)
      return
    end
    # If escape
    if @active_battler.is_a?(Game_Enemy) and
       @active_battler.current_action.basic == 2
      # Display "Escape" in help window
      @help_window.set_text("Escape", 1)
      # Escape
      @active_battler.escape
      return
    end
    # If doing nothing
    if @active_battler.current_action.basic == 3
      # Clear battler being forced into action
      $game_temp.forcing_battler = nil
      # Shift to step 1
      @phase4_step = 1
      return
    end
  end
  #--------------------------------------------------------------------------
  # * Make Skill Action Results
  #--------------------------------------------------------------------------
  def make_skill_action_result
    # Get skill
    @skill = $data_skills[@active_battler.current_action.skill_id]
    # If not a forcing action
    unless @active_battler.current_action.forcing
      # If unable to use due to SP running out
      unless @active_battler.skill_can_use?(@skill.id)
        # Clear battler being forced into action
        $game_temp.forcing_battler = nil
        # Shift to step 1
        @phase4_step = 1
        return
      end
    end
    # Use up SP
    @active_battler.sp -= @skill.sp_cost
    # Refresh status window
    @status_window.refresh
    # Show skill name on help window
    @help_window.set_text(@skill.name, 1)
    # Set animation ID
    @animation1_id = @skill.animation1_id
    @animation2_id = @skill.animation2_id
    # Set command event ID
    @common_event_id = @skill.common_event_id
    # Set target battlers
    set_target_battlers(@skill.scope)
    # Apply skill effect
    for target in @target_battlers
      if target.protected?
        new_target = target.select_protector
        @target_battlers.push(new_target) if !@target_battlers.include?(new_target)
        @target_battlers.delete(target)
        @help_window.set_text(new_target.name + " protected " + target.name, 1)
      end
    end
    for target in @target_battlers
      target.skill_effect(@active_battler, @skill)
    end
  end
  #--------------------------------------------------------------------------
  # * Make Item Action Results
  #--------------------------------------------------------------------------
  def make_item_action_result
    # Get item
    @item = $data_items[@active_battler.current_action.item_id]
    # If unable to use due to items running out
    unless $game_party.item_can_use?(@item.id)
      # Shift to step 1
      @phase4_step = 1
      return
    end
    # If consumable
    if @item.consumable
      # Decrease used item by 1
      $game_party.lose_item(@item.id, 1)
    end
    # Display item name on help window
    @help_window.set_text(@item.name, 1)
    # Set animation ID
    @animation1_id = @item.animation1_id
    @animation2_id = @item.animation2_id
    # Set common event ID
    @common_event_id = @item.common_event_id
    # Decide on target
    index = @active_battler.current_action.target_index
    target = $game_party.smooth_target_actor(index)
    # Set targeted battlers
    set_target_battlers(@item.scope)
    # Apply item effect
    for target in @target_battlers
      if target.protected?
        new_target = target.select_protector
        @target_battlers.push(new_target) if !@target_battlers.include?(new_target)
        @target_battlers.delete(target)
        @help_window.set_text(new_target.name + " protected " + target.name, 1)
      end
    end
    for target in @target_battlers
      target.item_effect(@item)
    end
  end
end

#==============================================================================
# ** Window_Base
#==============================================================================

class Window_Base < Window
  #--------------------------------------------------------------------------
  # * Make State Text String for Drawing
  #     actor       : actor
  #     width       : draw spot width
  #     need_normal : Whether or not [normal] is needed (true / false)
  #--------------------------------------------------------------------------
  def make_battler_state_text(battler, width, need_normal)
    # Get width of brackets
    brackets_width = self.contents.text_size("[]").width
    # Make text string for state names
    text = ""
    for i in battler.states
      if $data_states[i].rating >= 1 and !$data_states[i].name.include?("Protection") and
        !$data_states[i].name.include?("Protected")
        if text == ""
          text = $data_states[i].name
        else
          new_text = text + "/" + $data_states[i].name
          text_width = self.contents.text_size(new_text).width
          if text_width > width - brackets_width
            break
          end
          text = new_text
        end
      end
    end
    # If text string for state names is empty, make it [normal]
    if text == ""
      if need_normal
        text = "[Normal]"
      end
    else
      # Attach brackets
      text = "[" + text + "]"
    end
    # Return completed text string
    return text
  end
end

The message called when an enemy protects the boss is displayed in the help window (l.142, 210, 252 in the script).
 
Hm... I tried this, but nothing happens... They don't get the status, even though they cast their spells...

I am using Minkoff's animated battlers, but that can't be it. I mean it is just a graphical overlay system and has nothing to do with the Battle system...
 
OK, I think that I misunderstood.
With my script the player is able to target the boss, but the protector takes all the damage.

What do you want is :
- when the player chooses his target, the cursor may be on the boss.
- if he validates his choice when the cursor is on the boss, a message appears, and he still have to select a target.

Is that correct ?

And what happens with an all-enemies attack ?
 
MGCaladtogel":s3cmkuxe said:
OK, I think that I misunderstood.
With my script the player is able to target the boss, but the protector takes all the damage.

What do you want is :
- when the player chooses his target, the cursor may be on the boss.
- if he validates his choice when the cursor is on the boss, a message appears, and he still have to select a target.

Is that correct ?

And what happens with an all-enemies attack ?


That is what I ment. Except you may rry to attack the boss, but the message box comes up and you can not choose again whom to attack, until next turn.
When there is an all enemies attack (which is unlikely at since those are more likely to come up later in the game) the boss should be unharmed.

Thank you for your hard work.
 
Try with this script : it's the same configuration as the previous one.

Code:
# 28/03/08 - MGCaladtogel
#==============================================================================
# ** Game_Battler
#==============================================================================

class Game_Battler
  attr_accessor :protectors
  attr_accessor :protected
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  alias initialize_protect initialize
  def initialize
     initialize_protect
    self.protectors = Array.new
    self.protected = false
  end
  #--------------------------------------------------------------------------
  # * add_protector
  #     member : Game_Battler (protector)
  #--------------------------------------------------------------------------
  def add_protector(battler)
    self.protectors.push(battler)
  end
  #--------------------------------------------------------------------------
  # * remove_protector
  #     member : Game_Enemy (protector)
  #--------------------------------------------------------------------------
  def remove_protector(battler)
    self.protectors.delete(battler)
  end
  #--------------------------------------------------------------------------
  # * protected?
  #--------------------------------------------------------------------------
  def protected?
    result = false
    if protectors.size > 0
      for battler in protectors
        battler.dead? ? remove_protector(battler) : result = true
      end
    end
    return result
  end
  #--------------------------------------------------------------------------
  # * select_protector
  #--------------------------------------------------------------------------
  def select_protector
    protector =  protectors[rand(protectors.size)]
  end
  #--------------------------------------------------------------------------
  # * Add State
  #     state_id : state ID
  #     force    : forcefully added flag (used to deal with auto state)
  #--------------------------------------------------------------------------
  alias add_state_protect add_state
  def add_state(state_id, force = false)
    add_state_protect(state_id, force)
    if $data_states[state_id].name.include?("Protected")
      self.protected = true
    end
    if $data_states[state_id].name.include?("Protection")
      if self.is_a?(Game_Enemy)
        for enemy in $game_troop.enemies
          enemy.add_protector(self) if enemy.protected
        end
      else
        for actor in $game_party.actors
          actor.add_protector(self) if actor.protected
        end
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Remove State
  #     state_id : state ID
  #     force    : forcefully removed flag (used to deal with auto state)
  #--------------------------------------------------------------------------
  alias remove_state_protect remove_state
  def remove_state(state_id, force = false)
    remove_state_protect(state_id, force)
    if $data_states[state_id].name.include?("Protected")
      self.protected = false
    end
    if $data_states[state_id].name.include?("Protection")
      if self.is_a?(Game_Enemy)
        for enemy in $game_troop.enemies
          enemy.remove_protector(self)
        end
      else
        for actor in $game_party.actors
          actor.remove_protector(self)
        end
      end
    end
  end
end

#==============================================================================
# ** Scene_Battle
#==============================================================================

class Scene_Battle
  #--------------------------------------------------------------------------
  # * Make Basic Action Results
  #--------------------------------------------------------------------------
  def make_basic_action_result
    # If attack
    if @active_battler.current_action.basic == 0
      # Set anaimation ID
      @animation1_id = @active_battler.animation1_id
      @animation2_id = @active_battler.animation2_id
      # 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)
        end
      end
      # If action battler is actor
      if @active_battler.is_a?(Game_Actor)
        if @active_battler.restriction == 3
          target = $game_party.random_target_actor
        elsif @active_battler.restriction == 2
          target = $game_troop.random_target_enemy
        else
          index = @active_battler.current_action.target_index
          target = $game_troop.smooth_target_enemy(index)
        end
      end
      # Set array of targeted battlers
      @target_battlers = [target]
      # Apply normal attack results
      for target in @target_battlers
        if target.protected?
          protector = target.select_protector
          @target_battlers.delete(target)
          $game_temp.message_text = (protector.name + " protected " + target.name)
        end
      end
      for target in @target_battlers
        target.attack_effect(@active_battler)
      end
      return
    end
    # If guard
    if @active_battler.current_action.basic == 1
      # Display "Guard" in help window
      @help_window.set_text($data_system.words.guard, 1)
      return
    end
    # If escape
    if @active_battler.is_a?(Game_Enemy) and
       @active_battler.current_action.basic == 2
      # Display "Escape" in help window
      @help_window.set_text("Escape", 1)
      # Escape
      @active_battler.escape
      return
    end
    # If doing nothing
    if @active_battler.current_action.basic == 3
      # Clear battler being forced into action
      $game_temp.forcing_battler = nil
      # Shift to step 1
      @phase4_step = 1
      return
    end
  end
  #--------------------------------------------------------------------------
  # * Make Skill Action Results
  #--------------------------------------------------------------------------
  def make_skill_action_result
    # Get skill
    @skill = $data_skills[@active_battler.current_action.skill_id]
    # If not a forcing action
    unless @active_battler.current_action.forcing
      # If unable to use due to SP running out
      unless @active_battler.skill_can_use?(@skill.id)
        # Clear battler being forced into action
        $game_temp.forcing_battler = nil
        # Shift to step 1
        @phase4_step = 1
        return
      end
    end
    # Use up SP
    @active_battler.sp -= @skill.sp_cost
    # Refresh status window
    @status_window.refresh
    # Show skill name on help window
    @help_window.set_text(@skill.name, 1)
    # Set animation ID
    @animation1_id = @skill.animation1_id
    @animation2_id = @skill.animation2_id
    # Set command event ID
    @common_event_id = @skill.common_event_id
    # Set target battlers
    set_target_battlers(@skill.scope)
    # Apply skill effect
    for target in @target_battlers
      if target.protected?
        protector = target.select_protector
        @target_battlers.delete(target)
        $game_temp.message_text = (protector.name + " protected " + target.name)
      end
    end
    for target in @target_battlers
      target.skill_effect(@active_battler, @skill)
    end
  end
  #--------------------------------------------------------------------------
  # * Make Item Action Results
  #--------------------------------------------------------------------------
  def make_item_action_result
    # Get item
    @item = $data_items[@active_battler.current_action.item_id]
    # If unable to use due to items running out
    unless $game_party.item_can_use?(@item.id)
      # Shift to step 1
      @phase4_step = 1
      return
    end
    # If consumable
    if @item.consumable
      # Decrease used item by 1
      $game_party.lose_item(@item.id, 1)
    end
    # Display item name on help window
    @help_window.set_text(@item.name, 1)
    # Set animation ID
    @animation1_id = @item.animation1_id
    @animation2_id = @item.animation2_id
    # Set common event ID
    @common_event_id = @item.common_event_id
    # Decide on target
    index = @active_battler.current_action.target_index
    target = $game_party.smooth_target_actor(index)
    # Set targeted battlers
    set_target_battlers(@item.scope)
    # Apply item effect
    for target in @target_battlers
      if target.protected?
        protector = target.select_protector
        @target_battlers.delete(target)
        $game_temp.message_text = (protector.name + " protected " + target.name)
      end
    end
    for target in @target_battlers
      target.item_effect(@item)
    end
  end
end

#==============================================================================
# ** Window_Base
#==============================================================================

class Window_Base < Window
  #--------------------------------------------------------------------------
  # * Make State Text String for Drawing
  #     actor       : actor
  #     width       : draw spot width
  #     need_normal : Whether or not [normal] is needed (true / false)
  #--------------------------------------------------------------------------
  def make_battler_state_text(battler, width, need_normal)
    # Get width of brackets
    brackets_width = self.contents.text_size("[]").width
    # Make text string for state names
    text = ""
    for i in battler.states
      if $data_states[i].rating >= 1 and !$data_states[i].name.include?("Protection") and
        !$data_states[i].name.include?("Protected")
        if text == ""
          text = $data_states[i].name
        else
          new_text = text + "/" + $data_states[i].name
          text_width = self.contents.text_size(new_text).width
          if text_width > width - brackets_width
            break
          end
          text = new_text
        end
      end
    end
    # If text string for state names is empty, make it [normal]
    if text == ""
      if need_normal
        text = "[Normal]"
      end
    else
      # Attach brackets
      text = "[" + text + "]"
    end
    # Return completed text string
    return text
  end
end

How does it work ?
 

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