Battle Item Count VX + ACE
#1
Battle Item Count VX + ACE

by Kyonides

Introduction

Thinking Do you need to update the number of potions or elixirs currently available for the next couple of actors during battle?
Confused Or were you in need of canceling your previous actor's action to change the item the actor is going to consume next?
Then this scriptlet is for you! Grinning

VX Script

Code:
# * Battle Item Count VX * #
#   Plug & Play Script
#   Scripter : Kyonides Arkanthes
#   v1.0.4 - 2024-02-03

# The scriptlet updates the number of available items every single time you pick
# one or go back to the prior actor in battle.

class Game_Actor
  def clear_battle_item
    @battle_item_id = nil
  end
  attr_accessor :battle_item_id
end

class Game_Party
  def clear_battle_items
    members.each {|m| m.clear_battle_item }
  end

  def members_battle_items
    members.map {|m| m.battle_item_id }
  end

  def battle_item_number(item)
    return item_number(item) unless $game_temp.in_battle
    item_id = item.id
    battle_items = members_battle_items.select {|bit_id| item_id == bit_id }
    item_number(item) - battle_items.size
  end
end

class Window_Item
  alias :kyon_btl_itm_cnt_win_ref :refresh
  def refresh
    @battle_items = {}
    @battle_items.default = 99
    kyon_btl_itm_cnt_win_ref
  end

  def enable?(item)
    $game_party.item_can_use?(item) and @battle_items[item.id] > 0
  end

  def draw_item(index)
    rect = item_rect(index)
    self.contents.clear_rect(rect)
    item = @data[index]
    return unless item
    number = $game_party.battle_item_number(item)
    @battle_items[item.id] = number
    enabled = enable?(item)
    rect.width -= 4
    draw_item_name(item, rect.x, rect.y, enabled)
    self.contents.draw_text(rect, sprintf(":%2d", number), 2)
  end

  def battle_item_none?
    @battle_items[@data[@index].id] == 0
  end
end

class Scene_Battle
  alias :kyon_btl_itm_cnt_scn_btl_term :terminate
  alias :kyon_btl_itm_cnt_scn_btl_st_pty_cmd_sel :start_party_command_selection
  alias :kyon_btl_itm_cnt_scn_btl_prr_act :prior_actor
  alias :kyon_btl_itm_cnt_scn_btl_end_trgt_act_sel :end_target_actor_selection
  def terminate
    kyon_btl_itm_cnt_scn_btl_term
    $game_party.clear_battle_items
  end

  def start_party_command_selection
    $game_party.clear_battle_items
    kyon_btl_itm_cnt_scn_btl_st_pty_cmd_sel
  end

  def turn_decrease_item_count
    @active_battler.clear_battle_item if @active_battler
  end

  def prior_actor
    turn_decrease_item_count
    kyon_btl_itm_cnt_scn_btl_prr_act
    turn_decrease_item_count
  end

  def update_target_actor_selection
    @target_actor_window.update
    if Input.trigger?(Input::B)
      Sound.play_cancel
      end_target_actor_selection
    elsif Input.trigger?(Input::C)
      Sound.play_decision
      @active_battler.action.target_index = @target_actor_window.index
      @active_battler.battle_item_id = @item.id if @item
      @item = nil
      end_target_actor_selection
      end_skill_selection
      end_item_selection
      next_actor
    end
  end

  def update_item_selection
    @item_window.active = true
    @item_window.update
    @help_window.update
    if Input.trigger?(Input::B)
      Sound.play_cancel
      end_item_selection
    elsif Input.trigger?(Input::C)
      @item = @item_window.item
      $game_party.last_item_id = @item.id if @item
      return Sound.play_buzzer unless $game_party.item_can_use?(@item)
      return Sound.play_buzzer if @item_window.battle_item_none?
      Sound.play_decision
      determine_item
    end
  end
end


VX ACE Script

Code:
# * Battle Item Count ACE * #
#   Plug & Play Script
#   Scripter : Kyonides Arkanthes
#   v1.0.4 - 2024-02-03

# The scriptlet updates the number of available items every single time you pick
# one or go back to the prior actor in battle.

class Game_Actor
  def clear_battle_item
    @battle_item_id = nil
  end
  attr_accessor :battle_item_id
end

class Game_Party
  def clear_battle_items
    members.each {|m| m.clear_battle_item }
  end

  def members_battle_items
    members.map {|m| m.battle_item_id }
  end

  def battle_item_number(item)
    return item_number(item) unless @in_battle
    item_id = item.id
    battle_items = members_battle_items.select {|bit_id| item_id == bit_id }
    item_number(item) - battle_items.size
  end
end

class Window_ItemList
  alias :kyon_btl_itm_cnt_mk_itm_lst :make_item_list
  def enable?(item)
    $game_party.usable?(item) and @battle_items[item.id] > 0
  end

  def make_item_list
    @battle_items = {}
    @battle_items.default = 99
    kyon_btl_itm_cnt_mk_itm_lst
  end

  def draw_item_number(rect, item)
    number = $game_party.battle_item_number(item)
    @battle_items[item.id] = number
    contents.font.color.alpha = number > 0 ? 255 : translucent_alpha
    number = sprintf(":%2d", number)
    draw_text(rect, number, 2)
  end
end

class Scene_Battle
  alias :kyon_btl_itm_cnt_scn_btl_term :terminate
  alias :kyon_btl_itm_cnt_scn_btl_st_pty_cmd_sel :start_party_command_selection
  alias :kyon_btl_itm_cnt_scn_btl_st_act_cmd_sel :start_actor_command_selection
  alias :kyon_btl_itm_cnt_scn_btl_on_itm_ok :on_item_ok
  alias :kyon_btl_itm_cnt_scn_btl_on_itm_cncl :on_item_cancel
  def terminate
    kyon_btl_itm_cnt_scn_btl_term
    $game_party.clear_battle_items
  end

  def start_party_command_selection
    kyon_btl_itm_cnt_scn_btl_st_pty_cmd_sel
    $game_party.clear_battle_items
  end

  def start_actor_command_selection
    kyon_btl_itm_cnt_scn_btl_st_act_cmd_sel
    BattleManager.actor.clear_battle_item
  end

  def on_item_ok
    BattleManager.actor.battle_item_id = @item_window.item.id
    kyon_btl_itm_cnt_scn_btl_on_itm_ok
  end

  def on_item_cancel
    BattleManager.actor.clear_battle_item
    kyon_btl_itm_cnt_scn_btl_on_itm_cncl
  end
end

Terms & Conditions

Free for use in ANY game. Gamer
Due credit is mandatory. Serious
That's it! Tongue sticking out
"For God has not destined us for wrath, but for obtaining salvation through our Lord Jesus Christ," 1 Thessalonians 5:9

Maranatha!

The Internet might be either your friend or enemy. It just depends on whether or not she has a bad hair day.

[Image: SP1-Scripter.png]
[Image: SP1-Writer.png]
[Image: SP1-Poet.png]
[Image: SP1-PixelArtist.png]
[Image: SP1-Reporter.png]

My Original Stories (available in English and Spanish)

List of Compiled Binary Executables I have published...
HiddenChest & Roole

Give me a free copy of your completed game if you include at least 3 of my scripts! Laughing + Tongue sticking out

Just some scripts I've already published on the board...
KyoGemBoost XP VX & ACE, RandomEnkounters XP, KSkillShop XP, Kolloseum States XP, KEvents XP, KScenario XP & Gosu, KyoPrizeShop XP Mangostan, Kuests XP, KyoDiscounts XP VX, ACE & MV, KChest XP VX & ACE 2016, KTelePort XP, KSkillMax XP & VX & ACE, Gem Roulette XP VX & VX Ace, KRespawnPoint XP, VX & VX Ace, GiveAway XP VX & ACE, Klearance XP VX & ACE, KUnits XP VX, ACE & Gosu 2017, KLevel XP, KRumors XP & ACE, KMonsterPals XP VX & ACE, KStatsRefill XP VX & ACE, KLotto XP VX & ACE, KItemDesc XP & VX, KPocket XP & VX, OpenChest XP VX & ACE
Reply }
#2
Here Are Some Goodies for VX Users!

This script is incompatible with the Targetting Extended for Tankentai Non-ATB v1.1 by Crimsonseas. So you'd need to use this modified version of Crimsonseas' script and my custom patch to make it work as intended. Winking

Modified Version of Targetting Extended

Code:
=begin
################################################################################
Targetting Extended for Tankentai Non-ATB v1.1
by CrimsonSeas
################################################################################
Use with the base script to enable the targetting extended.


This script adds to the rewrites list of the base script


Rewrites:
+Scene_Battle
-start_target_selection
-select_member
################################################################################
=end

class Scene_Battle
  def start_target_selection(actor = false)
    members = actor ? $game_party.members : $game_troop.members
    action = @active_battler.action
    if action.kind == 1
      obj = action.skill
    elsif action.kind == 2
      obj = action.item
    end
    case obj
    when nil
      @target_any = TargetExt::ATTACK_ANY
    when RPG::Skill
      @target_any = !TargetExt::NO_TARGET_ANY_S.include?(action.skill.id)
    when RPG::Item
      @target_any = !TargetExt::NO_TARGET_ANY_I.include?(action.item.id)
    end
    if obj != nil && obj.extension.include?("TARGETALL")
      members = $game_party.members + $game_troop.members
    end
    # �‚��ƒ��‚��ƒ��‚��ƒ—�ƒ��‚��ƒˆの�œ�ˆ�
    @all = false
    if obj != nil
      scope_all = [2, 4, 5, 6, 8, 10].include?(obj.scope)
      @all = (scope_all || obj.extension.include?("TARGETALL"))
    end
    @cursor = Sprite.new
    @cursor.bitmap = Cache.character("cursor")
    @cursor.src_rect.set(0, 0, 32, 32)
    @cursor_flame = 0
    @cursor.x = -200
    @cursor.y = -200
    @cursor.ox = @cursor.width
    @cursor.oy = @cursor.height
    @cursor.visible = !@all
    # �‚��ƒ��‚��ƒƒ�ƒˆ名�‚’表示�™�‚‹�ƒ˜�ƒ��ƒ—�‚��‚��ƒ��ƒ‰�‚��‚’�œ�ˆ�
    @help_window.visible = false if @help_window != nil
    @help_window2 = Window_Help.new if @help_window2 == nil
    # 不要な�‚��‚��ƒ��ƒ‰�‚��‚’�ˆ�™
    @actor_command_window.active = false
    @skill_window.visible = false if @skill_window != nil
    @item_window.visible = false if @item_window != nil
    # �˜�œ��—て�„�‚‹�‚��ƒ��‚��ƒƒ�ƒˆで�œ€�‚‚�•�号の�Ž�„対象�‚’�œ€�ˆ�に�Œ‡�™�‚ˆ�†に
    @index = 0
    @max_index = members.size - 1
    # �‚��‚��‚��ƒ�は�ˆ��—˜不�ƒ��€…で�‚‚�‚��ƒ��‚��ƒƒ�ƒˆでき�‚‹�‚ˆ�†に�‚��ƒ��ƒŸ�ƒ�と�Œ��ˆ�
    unless actor
      members.size.times do
        break if members[@index].exist?
        @index += 1
      end
    end
    @help_window2.set_text(members[@index].name, 1)
    if @all
      string, strings = TargetExt::TARGET_ALL_VOC
      string2 = actor ? strings[0] : strings[1]
      string += " " + string2 unless obj.extension.include?("TARGETALL")
      @help_window2.set_text(string, 1)
      make_cursor_all(members)
      cursor_all_visible(true)
      @cursor.visible = false
    else
      # Call New Method: Reset Single Cursor
      reset_single_cursor(actor)
    end
    select_member(members, actor)
  end
  #--------------------------------------------------------------------------
  # �—� �‚��ƒ��‚��ƒƒ�ƒˆ選�Šž
  #--------------------------------------------------------------------------
  def select_member(targets, actor = true)
    members = targets
    action = @active_battler.action
    if action.kind == 1
      obj = action.skill
    elsif action.kind == 2
      obj = action.item
    end
    #rect = @cursor.src_rect
    #rect.set(0, 0, 32, 32)
    loop do
      update_basic
      @cursor_flame = 0 if @cursor_flame == 30
      #rect.y = 0 if @cursor_flame == 29
      #rect.y = 32 if @cursor_flame == 15
      point_x, point_y = @spriteset.set_cursor(actor, @index)
      @cursor.x = point_x
      @cursor.y = point_y
      @cursor_flame += 1
      if Input.trigger?(Input::B)
        select_member_cancel
        break
      elsif Input.trigger?(Input::C)
        select_member_ok
        break
      end
      if Input.repeat?(Input::LEFT) && !(@all || @active_battler.target_all)
        if actor
          $back_attack ? cursor_down(members, actor) : cursor_up(members, actor)
        else
          $back_attack ? cursor_up(members, actor) : cursor_down(members, actor)
        end
      end
      if Input.repeat?(Input::RIGHT) && !(@all || @active_battler.target_all)
        if actor
          $back_attack ? cursor_up(members, actor) : cursor_down(members, actor)
        else
          $back_attack ? cursor_down(members, actor) : cursor_up(members, actor)
        end
      end
      #if (Input.trigger?(Input::L) || Input.trigger?(Input::R)) && @target_any
      if (Input.trigger?(Input::L) || Input.trigger?(Input::R)) #&& nil
        if members == $game_party.members
          members = $game_troop.members
          actor = false
        elsif members == $game_troop.members
          members = $game_party.members
          actor = true
        end
        if @active_battler.inverse_target
          @active_battler.inverse_target = false
        else
          @active_battler.inverse_target = true
        end
        @index = 0 if @index >= members.size
        @max_index = members.size - 1
        # �‚��‚��‚��ƒ�は�ˆ��—˜不�ƒ��€…で�‚‚�‚��ƒ��‚��ƒƒ�ƒˆでき�‚‹�‚ˆ�†に�‚��ƒ��ƒŸ�ƒ�と�Œ��ˆ�
        unless actor
          members.size.times do
            break if members[@index].exist?
            @index += 1
          end
        end
        if @cursor != nil
          # Modified Process: Make Sure Any Kind of Cursor is Visible
          many_targets = (@active_battler.target_all || @all)
          if many_targets
            dispose_cursor_all
            make_cursor_all(members)
            cursor_all_visible(false)
            @cursor.visible = false
          else
            @cursor.visible = true
          end
        end
        if @active_battler.target_all || @all
          string1 = TargetExt::TARGET_ALL_VOC[0]
          string2 = actor ? TargetExt::TARGET_ALL_VOC[1][0] : TargetExt::TARGET_ALL_VOC[1][1]
          string1 += " " + string2 unless obj.extension.include?("TARGETALL")
          if TargetExt::SHOW_MP_ALTER && @active_battler.target_all && obj.is_a?(RPG::Skill)
            cost = @active_battler.calc_mp_cost(obj)
            string1 += ": " + cost.to_s + Vocab::mp
          end
          @help_window2.set_text(string1, 1)
        end
        @help_window2.set_text(members[@index].name, 1) if !@active_battler.target_all && !@all
        Sound.play_cursor
      end
      if Input.trigger?(Input::A) && !@all && obj != nil
        if obj.all_available
          Sound.play_cursor
          if @active_battler.target_all
            @active_battler.target_all = false
            @cursor.visible = true
            cursor_all_visible(false) if @cursor2 != nil
            @help_window2.set_text(members[@index].name, 1)
          else
            @active_battler.target_all = true
            @cursor.visible = false
            make_cursor_all(members) if @cursor2 == nil
            cursor_all_visible(true)
            string1 = TargetExt::TARGET_ALL_VOC[0]
            string2 = actor ? TargetExt::TARGET_ALL_VOC[1][0] : TargetExt::TARGET_ALL_VOC[1][1]
            string1 += " " + string2 unless obj.extension.include?("TARGETALL")
            if TargetExt::SHOW_MP_ALTER && @active_battler.target_all &&  obj.is_a?(RPG::Skill)
              cost = @active_battler.calc_mp_cost(obj)
              string1 += ": " + cost.to_s + Vocab::mp
            end
            @help_window2.set_text(string1 , 1)
          end
        end
      end
      many_targets = (@active_battler.target_all || @all)
      cursor_up(members, actor) if Input.repeat?(Input::UP) && !many_targets
      cursor_down(members, actor) if Input.repeat?(Input::DOWN) && !many_targets
    end
  end

  def select_member_cancel
    Sound.play_cancel
    @active_battler.target_all = false
    end_target_selection
  end

  def select_member_ok
    Sound.play_decision
    @active_battler.action.target_index = @index
    end_target_selection
    end_skill_selection
    end_item_selection
    next_actor
  end

  def make_cursor_all(members)
    @cursor2 = []
    for i in 0...members.size
      next if members == $game_troop.members && !members[i].exist?
      @cursor2[i] = Sprite.new
      @cursor2[i].bitmap = Cache.character("cursor")
      @cursor2[i].src_rect.set(0, 0, 32, 32)
      @cursor2[i].x = members[i].position_x - 48
      @cursor2[i].y = members[i].position_y - 48
    end
    @cursor2.compact!
  end
end

The Patch

Code:
# * Battle Item Count VX - Takentai Patch * #
#  Scripter : Kyonides Arkanthes
#  2024-10-17

class Scene_Battle
  alias :kyon_btl_itm_cnt_scn_btl_sel_mem_ok :select_member_ok
  def select_member_ok
    action = @active_battler.action
    item_id = action.kind == 2 ? action.item.id : nil
    @active_battler.battle_item_id = item_id if item_id
    kyon_btl_itm_cnt_scn_btl_sel_mem_ok
  end

  def reset_single_cursor(is_actor)
    point_x, point_y = @spriteset.set_cursor(is_actor, @index)
    @cursor.x = point_x
    @cursor.y = point_y
  end
end
"For God has not destined us for wrath, but for obtaining salvation through our Lord Jesus Christ," 1 Thessalonians 5:9

Maranatha!

The Internet might be either your friend or enemy. It just depends on whether or not she has a bad hair day.

[Image: SP1-Scripter.png]
[Image: SP1-Writer.png]
[Image: SP1-Poet.png]
[Image: SP1-PixelArtist.png]
[Image: SP1-Reporter.png]

My Original Stories (available in English and Spanish)

List of Compiled Binary Executables I have published...
HiddenChest & Roole

Give me a free copy of your completed game if you include at least 3 of my scripts! Laughing + Tongue sticking out

Just some scripts I've already published on the board...
KyoGemBoost XP VX & ACE, RandomEnkounters XP, KSkillShop XP, Kolloseum States XP, KEvents XP, KScenario XP & Gosu, KyoPrizeShop XP Mangostan, Kuests XP, KyoDiscounts XP VX, ACE & MV, KChest XP VX & ACE 2016, KTelePort XP, KSkillMax XP & VX & ACE, Gem Roulette XP VX & VX Ace, KRespawnPoint XP, VX & VX Ace, GiveAway XP VX & ACE, Klearance XP VX & ACE, KUnits XP VX, ACE & Gosu 2017, KLevel XP, KRumors XP & ACE, KMonsterPals XP VX & ACE, KStatsRefill XP VX & ACE, KLotto XP VX & ACE, KItemDesc XP & VX, KPocket XP & VX, OpenChest XP VX & ACE
Reply }


Possibly Related Threads…
Thread Author Replies Views Last Post
   Select Key Item ACE kyonides 0 915 03-22-2024, 05:49 PM
Last Post: kyonides
   Skill Item Kost ACE kyonides 0 985 01-03-2024, 12:07 AM
Last Post: kyonides
   DoubleX RMVXA Item Triggers DoubleX 2 6,598 02-27-2016, 03:02 AM
Last Post: DoubleX
   Theolized Sideview Battle System TheoAllen 5 14,674 09-15-2014, 04:30 AM
Last Post: TheoAllen
   Yanfly Battle Status Helladen 3 8,342 04-20-2013, 04:40 AM
Last Post: Helladen
   Victor Engine - Active Time Battle Victor Sant 0 5,511 12-16-2012, 08:17 PM
Last Post: Victor Sant
   Skip Battle Messages Helladen 1 6,032 08-06-2012, 01:34 AM
Last Post: Helladen
   Victor Engine - Item Command Victor Sant 0 4,476 08-05-2012, 10:36 PM
Last Post: Victor Sant
   Skip Battle Log Helladen 0 4,798 08-02-2012, 10:49 AM
Last Post: Helladen
   Debug Battle Add-on Helladen 0 4,110 07-27-2012, 06:41 AM
Last Post: Helladen



Users browsing this thread: 1 Guest(s)