Help - Search - Members - Calendar
Full Version: Replacing "Attack" command with weapon name & item value
RPG RPG Revolution Forums > Scripting > Script Development and Support > Script Requests
richardpilbeam
I'm currently working on an RMXP game that uses ammunition requirements for some weapons, using the Syn's Ammo Requirements script. That part's working fine.

What I'm looking to do is replace the in-game "Attack" command with the name of the character's equipped weapon, followed by how much of the associated ammunition is remaining.

Eg. if the currently selected character had the Bronze Bow equipped and there were 16 Arrows in the inventory, instead of:

Attack
Skill
Defend
Item

It would display:

Bronze Bow [16]
Skill
Defend
Item

So, if I'm right (and I might not be) I'd just need to replace the word "Attack" with a string that displayed the actor's weapon name followed by the remaining associated ammo, then make the command window wider to accommodate the longer string, yes? How would I go about doing that?

Thanks in advance
Night_Runner
That sounds like a pretty cool idea happy.gif

CODE
#==============================================================================
# ** XP: Night_Runner's Replacing "Attack" with weapon name & ammo
#------------------------------------------------------------------------------
# History:
#  Date Created: 19/Mar/2012
#  Created for: richardpilbeam
#   @> http://www.rpgrevolution.com/forums/index.php?showtopic=55775
#
# Description:
#  This script changes the "Attack" option in battle to the hero's weapon's
#  name, and it Syn's Ammo Requirements script is loaded, it will also
#  display the amount of attacks are left with the weapon.
#
# How to Install:
#  Copy this entire script. In your game editor select Tools >> Script
#  Editor. Along the left scroll to the bottom, right click on 'Main' and
#  select 'Insert'. Paste this code on the right.
#==============================================================================



#==============================================================================
# ** Window_Command
#------------------------------------------------------------------------------
#  Edited to allow replacing of commands
#==============================================================================

class Window_Command
  #--------------------------------------------------------------------------
  # * Replace
  #--------------------------------------------------------------------------
  def replace(index, new_command, selectable = true)
    # Change the command to the new one
    @commands[index] = new_command
    # Set the color
    color = selectable ? normal_color : disabled_color
    # Update the graphic.
    draw_item(index, color)
  end
end



#==============================================================================
# ** Scene_Battle
#------------------------------------------------------------------------------
#  Edited to change the attack name based on request.
#==============================================================================

class Scene_Battle
  #--------------------------------------------------------------------------
  # * Actor Command Window Setup
  #--------------------------------------------------------------------------
  alias nr_synAmmo_phase3_setup_command_window  phase3_setup_command_window
  #--------------------------------------------------------------------------
  # * Actor Command Window Setup
  #--------------------------------------------------------------------------
  def phase3_setup_command_window(*args)
    # Run the original phase3_setup_command_window
    nr_synAmmo_phase3_setup_command_window(*args)
    # Get the weapon's name
    weapon = $data_weapons[$game_party.actors[@actor_index].weapon_id]
    return if weapon.nil?
    string = weapon.name
    usable = true
    # Isolate this is a block that has a rescue condition, in case of failure
    begin
    # If the item is part of Syn's Ammo Requirements Script
      if Ammo::Range_weapons_id.keys.include?(weapon.id)
        # Get how many shots are left
        ammo_cost = Ammo::Range_weapons_id[weapon.id]
        ammo_id = Ammo::Range_ammo_id[weapon.id]
        ammo_avail = $game_party.item_number(ammo_id)
        shots_left = ammo_avail / ammo_cost
        # Update the string and usability appropriatly
        string += " [#{shots_left}]"
        usable = shots_left > 0
      end
    # In the rescue condition, do nothing
    rescue
      1 + 1
    end
    # Replace the attack option with the string and usability
    @actor_command_window.replace(0, string, usable)
  end
end



#==============================================================================
# ** End of Script.
#==============================================================================


Oops, that last one didn't automatically update the with of the command window...... try this next script!
CODE
#==============================================================================
# ** XP: Night_Runner's Replacing "Attack" with weapon name & ammo
#------------------------------------------------------------------------------
# History:
#  Date Created: 19/Mar/2012
#  Created for: richardpilbeam
#   @> http://www.rpgrevolution.com/forums/index.php?showtopic=55775
#
# Description:
#  This script changes the "Attack" option in battle to the hero's weapon's
#  name, and it Syn's Ammo Requirements script is loaded, it will also
#  display the amount of attacks are left with the weapon.
#
# How to Install:
#  Copy this entire script. In your game editor select Tools >> Script
#  Editor. Along the left scroll to the bottom, right click on 'Main' and
#  select 'Insert'. Paste this code on the right.
#==============================================================================

#----------------------------------------------------------------------------
# Customization Section
#----------------------------------------------------------------------------
module Ammo
  # Format = {weapon_id => Ammo_cost}
  Range_weapons_id = {1 => 1}
  # Format = {weapon_id => Item_id
  Range_ammo_id = {1 => 33}
  # Format = {skill_id => Ammo_cost}
  Skill_ammo = {73 => 3}
  # Note on Skills: When using Skills the Current Ammo for the equipped
  # weapon will be used. So if Skill 73 is used and Weapon 17 is equipped
  # then Ammo #33 will be used.
end


#==============================================================================
# ** Window_Command
#------------------------------------------------------------------------------
#  Edited to allow replacing of commands
#==============================================================================

class Window_Command
  #--------------------------------------------------------------------------
  # * Replace
  #--------------------------------------------------------------------------
  def replace(index, new_command, selectable = true)
    # Change the command to the new one
    @commands[index] = new_command
    # Set the color
    color = selectable ? normal_color : disabled_color
    # Update the width
    text_width = contents.text_size(new_command).width
    self.width = [text_width + 48, 160].max
    self.contents.dispose
    self.contents = Bitmap.new(width - 32, height - 32)
    # Update the graphics
    refresh
    draw_item(index, color)
  end
end



#==============================================================================
# ** Scene_Battle
#------------------------------------------------------------------------------
#  Edited to change the attack name based on request.
#==============================================================================

class Scene_Battle
  #--------------------------------------------------------------------------
  # * Actor Command Window Setup
  #--------------------------------------------------------------------------
  alias nr_synAmmo_phase3_setup_command_window  phase3_setup_command_window
  #--------------------------------------------------------------------------
  # * Actor Command Window Setup
  #--------------------------------------------------------------------------
  def phase3_setup_command_window(*args)
    # Run the original phase3_setup_command_window
    nr_synAmmo_phase3_setup_command_window(*args)
    # Get the weapon's name
    weapon = $data_weapons[$game_party.actors[@actor_index].weapon_id]
    return if weapon.nil?
    string = weapon.name
    usable = true
    # Isolate this is a block that has a rescue condition, in case of failure
    begin
    # If the item is part of Syn's Ammo Requirements Script
      if Ammo::Range_weapons_id.keys.include?(weapon.id)
        # Get how many shots are left
        ammo_cost = Ammo::Range_weapons_id[weapon.id]
        ammo_id = Ammo::Range_ammo_id[weapon.id]
        ammo_avail = $game_party.item_number(ammo_id)
        shots_left = ammo_avail / ammo_cost
        # Update the string and usability appropriatly
        string += " [#{shots_left}]"
        usable = shots_left > 0
      end
    # In the rescue condition, do nothing
    rescue
      1 + 1
    end
    # Replace the attack option with the string and usability
    @actor_command_window.replace(0, string, usable)
  end
end



#==============================================================================
# ** End of Script.
#==============================================================================

It automatically updates the width now happy.gif
richardpilbeam
Works perfectly, thanks!
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2013 Invision Power Services, Inc.