Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Battle Item Count
#1
Battle Item Count
XP + 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

XP Script

Code:
# * Battle Item Count XP * #
#  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.

# Warning: Overwritten Method Window_Item#draw_item

class Game_Party
  def clear_battle_items
    @actors.each {|m| m.current_action.clear }
  end

  def actors_battle_items
    @actors.map {|m| m.current_action.item_id }
  end

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

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

  def find_number(item_id)
    case item
    when RPG::Item
      $game_party.battle_item_number(item_id)
    when RPG::Weapon
      $game_party.weapon_number(item_id)
    when RPG::Armor
      $game_party.armor_number(item_id)
    end
  end

  def enable?(item)
    return unless item.is_a?(RPG::Item)
    $game_party.item_can_use?(item.id) and @battle_items[item.id] > 0
  end
 
  def draw_item(index)
    item = @data[index]
    number = find_number(item.id)
    @battle_items[item.id] = number
    enabled = enable?(item)
    self.contents.font.color = enabled ? normal_color : disabled_color
    x = 4 + index % 2 * (288 + 32)
    y = index / 2 * 32
    rect = Rect.new(x, y, self.width / @column_max - 32, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    bitmap = RPG::Cache.icon(item.icon_name)
    opacity = enabled ? 255 : 128
    self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
    self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
    self.contents.draw_text(x + 240, y, 16, 32, ":", 1)
    self.contents.draw_text(x + 256, y, 24, 32, number.to_s, 2)
  end

  def battle_item_none?
    @battle_items[self.item.id] == 0
  end
end

class Scene_Battle
  alias :kyon_btl_itm_cnt_scn_btl_ph3_prr_act :phase3_prior_actor
  alias :kyon_btl_itm_cnt_scn_btl_up_ph3_itm_sel :update_phase3_item_select
  def turn_decrease_item_count
    @active_battler.current_action.clear if @active_battler
  end

  def phase3_prior_actor
    turn_decrease_item_count
    kyon_btl_itm_cnt_scn_btl_ph3_prr_act
    turn_decrease_item_count
  end

  def update_phase3_item_select
    if Input.trigger?(Input::C) and @item_window.battle_item_none?
      return $game_system.se_play($data_system.buzzer_se)
    end
    kyon_btl_itm_cnt_scn_btl_up_ph3_itm_sel
  end
end


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
Bug Fix Available!

After receiving a weird report concerning the item selection process, I started working on the issue described there and found out that I just needed to move the cancellation of the item counter to another method. Now it works as first intended. Winking
"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 }
#3
Second Bug Fix Available!

I had to revisit my code a second time and I noticed that I might have skipped an actor when clearing the item count. Who could it be? Happy with a sweat Well, it'd be the last actor selected by the player for sure.

Now it should only trigger the buzzer SE when you truly picked the last available item in your party's bag. Winking
"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 }
#4
VX ACE, You Have Not Been Forgotten!

From now on, all VX ACE users can take advantage of this easy-to-use battle item count script.
Grinning Yes guys, it's fully Cylon automated just like its elder sibling.
"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 }
#5
Minor Bug Fix Has Arrived!

I had not noticed before how heroes could easily select any given item even after the item counter had hit the 0 limit. Version 1.0.4 gets rid of this exploitable bug for good. Winking

By the way, my fellow RMXP users, the script has been ported to RGSS1 as well! Two Thumbs Up!
"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 212 03-22-2024, 05:49 PM
Last Post: kyonides
   Skill Item Kost ACE kyonides 0 356 01-03-2024, 12:07 AM
Last Post: kyonides
   Fast Item Grouping DerVVulfman 1 2,471 06-12-2023, 05:28 PM
Last Post: DerVVulfman
   Dalissa's Battle Cry DerVVulfman 2 6,620 05-09-2023, 03:07 AM
Last Post: DerVVulfman
   Zenith Tactical Battle System Plus (ZTBS+) DerVVulfman 0 2,008 05-10-2022, 10:42 PM
Last Post: DerVVulfman
   DoubleX RMMZ Skill Item Cooldown DoubleX 4 5,104 02-07-2021, 04:11 PM
Last Post: DoubleX
   DoubleX RMMZ Skill Item Triggers DoubleX 3 4,654 12-26-2020, 04:00 PM
Last Post: DoubleX
   Actor Battle Items DerVVulfman 4 4,914 11-08-2020, 12:36 PM
Last Post: Melana
   Centi-Second Wait Count DerVVulfman 5 5,606 09-12-2020, 04:07 AM
Last Post: DerVVulfman
   Battle Report Raziel 1 6,222 05-29-2020, 02:27 AM
Last Post: Whisper



Users browsing this thread: