The_Sarah - [v1.2.1] Final Fantasy style Throw Script

The_Sarah

Let's make great games together!
Veteran
Joined
Jul 18, 2020
Messages
100
Reaction score
79
First Language
English
Primarily Uses
RMVXA
Well folks, here it is!

This one took quite a bit of extra effort but I was right in thinking it'd be in my wheelhouse after learning about making Sub Commands for my main game project.


FFIX Style Throw Script
version 1.2.1

by The_Sarah

Introduction
A final fantasy styled Throw script!
The user can create their Throw skill in the Database (with whatever Damage Formula they want to use) and then use Notetags to decide who has the skill and how much damage individual items will do when thrown.

---------------------
Patch Notes
- Update 2-
Version 1.2 is done!
i) This one fixes a bug that would happen if you had two characters throwing the same item in a turn.
ii) This one also finishes aliasing all methods so the script should hopefully work with any number of other scripts.
iii) This one also removes the bug to do with empty enemy names.
iv) This is (hopefully) that last bug-fixing/neat-making script update, any future updates should either be me adding additional Damage Related Notetags (or other requests) or adding in planned features (like ally-targeting and chance of item pick-up).
v) Version 1.1 has been removed and replaced with Version 1.2.
vi) Pastebin Link removed as site seems to be having issues, future code drops will be done with this Forum's code and spoiler insertion methods.
vii) Updated to 1.2.1, some finishing touches made on aliasing and some if and case statements rephrased.

-Update 1-
Version 1.1 is done!
i) This one makes it easier to assign characters the Throw skill (via notetags now) and cleans up a lot of the code.
ii) It also adds in some aliases and fixes a couple bugs.
iii) It also adds some people to the special thanks section :)
iv) As there were a few bugs in the original 1.0 version of the script, I will remove that version and only have version 1.1 available on this thread from now on.

---------------------

Script Features
.
With this script, you can make any number of characters (who are Game Actors in the Database) able to use the "Throw" skill.

The Throw skill (by default) is found underneath any chosen character's SPECIAL/MAGIC command and above that character's GUARD command when in battle.

The skill will open a unique Throwable Object Window.
- This window will then show the player a list of any Items, Weapons or Armour that they have in their inventory that you (the game maker) have decided can be thrown in your game.

The player can then pick from this list and throw the object at an enemy.

The object thrown will decrease in the party's inventory by 1.

Any damage a thrown object does is calculated based on whatever YOU wrote in your "Throw" Skill's damage formula (in the Database), as well as whatever Notetag you have assigned to the Item/Weapon/Armour thrown.


How to Use
Copy and paste the Script into a slot above Main Process and below Materials in your Script Editor.
.​
Then follow these 5 steps:

Step 1) Create a "Throw" skill in your Database like you normally would for any custom skill.

Step 2) In the Editable Region in the script (just below the Script Intro), change the number 185 to the number of your Throw skill's id in the Database.

Step 3) For any character you want to be able to use the Throw skill, simply add a notetag saying (without the speech marks) "<Throw>" .
- Add this <Throw> notetag in the relevant character's Note Box (in the Game Actors section of the Database).

Step 4) For any items, weapons or armour in your game that you would like to be throwable:

i ) You must write a Notetag in their Note Box sections in the Database.

ii ) A full list of the notetags you can write, as well as information on what they each do, can be found below "Features" in the Script Intro section of the Script.

iii) This list is found in the section named "~ NOTETAGS KEY ~".

Step 5) Enjoy the script! Maybe leave a like on this forum thread post? :p


The Script
(click the spoiler button and copy paste this section)​

Ruby:
#------------------------------------------------------------------------------#
=begin

                          "FFIX Style" Throw Script

                                by The_Sarah
                                  (v1.2.1)
                 
--                                                                            --

                             ~~~ REQUIREMENTS ~~~
                     
                                    None
                           
--                                                                            --

                              ~~~ HOW TO USE ~~~

Step 1) Create a "Throw" skill in your Database like you normally would.


Step 2) In the Editable Region below, change the number 185 to the number
         of your Throw skill's id in the Database.
 
 
Step 3) For any character you want to be able to use the Throw skill, simply
         add a notetag saying "<Throw>" (without the speechmarks).
          - Add this <Throw> notetag in the relevant character's Note Box (in
            the Game Actors section of the Database).
 
 
Step 4) For any items, weapons or armour in your inventory that you would
         like to be throwable:
 
         i) You must write a Notetag in their Note Box sections in the Database.

        ii) A FULL LIST of the notetags you can write, as well as information
            on what they each do, can be found below.
   
       iii) This list is found under the "~ NOTETAGS KEY ~" section of this
            script intro (just below FEATURES).
 
   
Step 5) Enjoy the script!
         Maybe leave a like on my RPG Maker Forum Thread page? :P

 
--                                                                            --


                              ~~~ FEATURES ~~~
                       
   With this script, you can make any number of characters (who are Game Actors)
   in your game able to use the "Throw" skill.

   The Throw skill is a skill that (by default) is found underneath any chosen
   character's SKILL command and above that character's GUARD command when in
   battle.

   This skill will open a unique Throwable Item Window.
    - This window will then show the player a list of any Items, Weapons or
      Armour that they have in their inventory that you (the game maker) have
      decided are throwable in your game.

   The player can then pick from this list and throw the object at an enemy.

   The object thrown will decrease in the party's inventory by 1.

   Any damage a thrown object does is calculated on whatever you wrote in
   your "Throw" skill's damage formula (in the Database), as well as whatever
   Notetag you have assigned to the Item/Weapon/Armour thrown.


--                                                                            --


                            ~~~ NOTETAGS KEY ~~~

   The following section is a list of every Notetag you can put into the Note
   Box of an Item, Weapon or Armour in the game's Database to make them
   throwable.

   The list also includes information on what each Notetag does to the damage
   of your Throw skill.


   Please note, each variant on the Notetag applies a different effect to
   YOUR existing Throw skill's Damage Formula.

   So make sure to have already created a Throw Skill in the Database as well :)
________________________________________________________________________________

   Notetag             Effect           |    Notetag             Effect

  <throwheal>  = Throws for 1x healing  | <throwhalf>   = Throws for half damage

  <throwdmg0>  = Throws for 0   damage  | <throwdmg>    = Throws for 1x  damage
  <throwdmg1>  = Throws for 1x  damage  | <throwdmg2>   = Throws for 2x  damage
  <throwdmg3>  = Throws for 3x  damage  | <throwdmg4>   = Throws for 4x  damage
  <throwdmg5>  = Throws for 5x  damage  | <throwdmg6>   = Throws for 6x  damage
  <throwdmg7>  = Throws for 7x  damage  | <throwdmg8>   = Throws for 8x  damage
  <throwdmg9>  = Throws for 9x  damage  | <throwdmg10>  = Throws for 10x damage
  <throwdmg11> = Throws for 11x damage  | <throwdmg12>  = Throws for 12x damage
  <throwdmg13> = Throws for 13x damage  | <throwdmg14>  = Throws for 14x damage
  <throwdmg15> = Throws for 15x damage  | <throwdmg16>  = Throws for 16x damage
  <throwdmg17> = Throws for 17x damage  | <throwdmg18>  = Throws for 18x damage
  <throwdmg19> = Throws for 19x damage  | <throwdmg20>  = Throws for 20x damage
  <throwdmg21> = Throws for 21x damage  | <throwdmg22>  = Throws for 22x damage
  <throwdmg23> = Throws for 23x damage  | <throwdmg24>  = Throws for 24x damage
  <throwdmg25> = Throws for 25x damage  | <throwdmg50>  = Throws for 50x damage
  <throwdmg75> = Throws for 75x damage  | <throwdmg100> = Throws for 100x damage
  <throwdmg250> = Throws for 250x damage| <throwdmg500> = Throws for 500x damage
  <throwdmg750> = Throws for 750x damage|

  <throwdmg1000> = Throws for 1000x damage
  <throwdmg2500> = Throws for 2500x damage
  <throwdmg5000> = Throws for 5000x damage
  <throwdmg7500> = Throws for 7500x damage
  <throwdmg10000> = Throws for 10000x damage

________________________________________________________________________________


--                                                                            --


                            ~~~ TERMS OF USE ~~~
                   
    If you share a game with this script in it (freely OR commercially), you
                         MUST credit me in the game.

               Ideally like this: "Throw Script by The_Sarah"

    Or like this if you edited the script: "Original Throw Script by The_Sarah"


    Other than that, this script is free to download and use or edit in any
                    game or project (free or commercial).

                   
--                                                                            --


                              ~~~ REQUESTS ~~~

   If you would like me to add more damage variants via additional notetags,
   please request so in the RPG Maker Forum Thread I made to originally host
   this Script.

   I will reply to all requests when I have the time (which shouldn't be too
   long to be honest) and do my best to accomodate them.


--                                                                            --


                                ~~~ BUGS ~~~

                           No current known issues.

       
--                                                                            --


                           ~~~ SPECIAL THANKS ~~~

     * The_Sarah (aka me) for being awesome and making this script :O

     * TheoAllen (RPG Maker Forum user) for initially helping me with
       figuring out the make_damage_value method.

     * Kyonides  (RPG Maker Forum user) for helping with Module Instance
       variables and Regex.

     * A-Moonless-Night (RPG Maker Forum user) for Aliasing help as well as
       helping me to finally understand how to grab specific parts within a
       Regex string.

     * LockeZ Ninja Throw (Script) for helping me figure out how to decrease
       items when thrown.


--                                                                            --

                                ~~~ OUTRO ~~~

   And that's it!

   This is my second ever public script (and definitely the biggest public one
   I've made so far) and as a result it has many areas I'm sure can be cleaned
   up (looking at you "include?").

   But the community on the RPG Maker Forum has been mostly friendly so far, so
   I'm happy to allow anyone who wants to look at it and give me tips to do so
   (if they feel so kind).

   Have wonderful lives everyone.
   Be kind to eachother.
   Don't be ____ist or ___phobic towards others, remember we're all human!

                    Let's make wonderful games together!

                                                            - The_Sarah

=end
#------------------------------------------------------------------------------#
#=begin


module TheSarahThrow
#=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~#

#                 ~~~~----# - EDITABLE REGION - #----~~~~                      #
#                               IMPORTANT                                      #

# Change the number in this section to the number of your Throw skill in the
# Database (default 185):

                THROW_SKILL_ID      =      185         # Your Throw skill ID


#                    ~~# - END OF EDITABLE REGION - #~~                        #
             
#=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~#
end # End of TheSarahThrow module




#------------------------------------------------------------------------------#
#                                The Script                                    #
#------------------------------------------------------------------------------#

#------------------------------------------------------------------------------#
#                               Game Classes                                   #
#==============================================================================
# * Exisiting Class
# ** Game_Action
#------------------------------------------------------------------------------
#  This class handles battle actions. This class is used within the
#  Game_Battler class.
#==============================================================================
class Game_Action
  #--------------------------------------------------------------------------
  # * New Method
  # ** Set Throw action
  #--------------------------------------------------------------------------
  def set_throw_action
    if BattleManager.actor.thrown_item != 0
      set_skill(subject.throw_skill_id)
      self
    else
      next_action
    end
  end

end # End of Game_Action class


#==============================================================================
# * Existing Class
# ** Game_BattlerBase
#------------------------------------------------------------------------------
#  This base class handles battlers. It mainly contains methods for calculating
#  parameters. It is used as a super class of the Game_Battler class.
#==============================================================================
class Game_BattlerBase
  #--------------------------------------------------------------------------
  # * New Method
  # ** Set Throw Skill ID
  #--------------------------------------------------------------------------
  def throw_skill_id
    return TheSarahThrow::THROW_SKILL_ID
  end

end # End of Game_BattlerBase class


#==============================================================================
# * Existing Class
# ** Game_Battler
#------------------------------------------------------------------------------
#  A battler class with methods for sprites and actions added. This class
# is used as a super class of the Game_Actor class and Game_Enemy class.
#==============================================================================
class Game_Battler < Game_BattlerBase
  #--------------------------------------------------------------------------
  # * Existing Method
  # ** Calculate Damage (aliased)
  #--------------------------------------------------------------------------
  alias thesarah_throwscript_gamebattler_makedmgval        make_damage_value
  def make_damage_value(user, item)
    if item.id == TheSarahThrow::THROW_SKILL_ID && user.is_a?(Game_Actor) && user.has_throw
      return thesarah_custom_damage_method(user, item)
    end
    thesarah_throwscript_gamebattler_makedmgval(user, item)
  end
  #--------------------------------------------------------------------------
  # * New Method
  # ** Calculate Damage when Throw is used
  #--------------------------------------------------------------------------
  def thesarah_custom_damage_method(user, item)
    value = item.damage.eval(user, self, $game_variables)

    case user.thrown_item_notetag
    when /<throwdmg\s*(\d+)>/i
        value *= $1.to_i
    end

    if user.thrown_item_category == "Nothing to throw"
      value *= 0
      Audio.se_play("Audio/SE/Miss", 80, 100)
    end

    value *= 0.5 if user.thrown_item_notetag[/throwhalf/i]
    value *= -1  if user.thrown_item_notetag[/throwheal/i]
    user.reset_thrown_item()
    value *= item_element_rate(user, item)
    value *= pdr if item.physical?
    value *= mdr if item.magical?
    value *= rec if item.damage.recover?
    value = apply_critical(value) if @result.critical
    value = apply_variance(value, item.damage.variance)
    value = apply_guard(value)
    @result.make_damage(value.to_i, item)
  end

end # End of Game_Battler class


#==============================================================================
# * Existing Class
# ** Game_Actor
#------------------------------------------------------------------------------
#  This class handles actors. It is used within the Game_Actors class
# ($game_actors) and is also referenced from the Game_Party class ($game_party).
#==============================================================================
class Game_Actor < Game_Battler
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :has_throw              # Checks if Actor has Throw command
  attr_accessor :thrown_item            # Checks Thrown Item ID
  attr_accessor :thrown_item_notetag    # Checks Thrown Item Notetag
  attr_accessor :thrown_item_category   # Checks Thrown Item Type/Category
  #--------------------------------------------------------------------------
  # * New Method
  # ** Reset Thrown Item
  #--------------------------------------------------------------------------
  def reset_thrown_item
    @thrown_item = 0
    @thrown_item_notetag = ""
    @thrown_item_category = ""
  end
  #--------------------------------------------------------------------------
  # * Existing Method
  # ** Setup (aliased)
  #--------------------------------------------------------------------------
  alias thesarah_throwscript_gameactor_setup          setup
  def setup(actor_id)
    thesarah_throwscript_gameactor_setup(actor_id)  # Calls original Method
    @has_throw = true if actor.note[/<Throw>/i];    # p(actor.note)
  end
  #--------------------------------------------------------------------------
  # * Existing Method (from Game_Battler)
  # ** Use Skill/Item (aliased)
  #--------------------------------------------------------------------------
  alias thesarah_throwscript_gameactor_useitem              use_item
  def use_item(item)
    case @thrown_item_category
    when "Armour"
      if $game_party.has_item?($data_armors[@thrown_item])
          $game_party.lose_item($data_armors[@thrown_item], 1)
      else
          @thrown_item_category = "Nothing to throw"
      end
    when "Weapon"
      if $game_party.has_item?($data_weapons[@thrown_item])
          $game_party.lose_item($data_weapons[@thrown_item], 1)
      else
          @thrown_item_category = "Nothing to throw"
      end
    when  "Item"
      if $game_party.has_item?($data_items[@thrown_item])
          $game_party.lose_item($data_items[@thrown_item], 1)
      else
          @thrown_item_category = "Nothing to throw"
      end
    end
 
    thesarah_throwscript_gameactor_useitem(item)    # calls original method
  end

end # End of Game_Actor class


#------------------------------------------------------------------------------#
#                              Window Classes                                  #
#==============================================================================
# * Existing Class
# ** Window_ActorCommand
#------------------------------------------------------------------------------
#  This window is for selecting an actor's action on the battle screen.
#==============================================================================
class Window_ActorCommand < Window_Command
  #--------------------------------------------------------------------------
  # * Existing Method  
  # ** Create Command List (aliased)  
  #--------------------------------------------------------------------------
  alias thesarah_throwscript_winactorcmd_makecmdlist      make_command_list
  def make_command_list
    return unless @actor
    if BattleManager.actor.has_throw == true
      return thesarah_throwadded_make_command_list
    end
    thesarah_throwscript_winactorcmd_makecmdlist
  end
  #--------------------------------------------------------------------------
  # * New Method                        | To change skill order, edit where the
  # ** Create Command List with [Throw] | "add_throw_command" goes below.
  #--------------------------------------------------------------------------
  def thesarah_throwadded_make_command_list
    return unless @actor
    add_attack_command
    add_skill_commands
    add_throw_command
    add_guard_command
    add_item_command
  end
  #--------------------------------------------------------------------------
  # * New Method
  # ** Add defined Throw Command to List
  #--------------------------------------------------------------------------
  def add_throw_command
  add_command("Throw", :throw)
  end

end # End of Window_ActorCommand class


#==============================================================================
# * New Class
# ** Window_BattleEnemy_Throw         (alternate version of Window_BattleEnemy)
#------------------------------------------------------------------------------
#  Window for selecting the enemy who is the action target on the battle
#  screen (after selecting item to throw).
#==============================================================================
class Window_BattleEnemy_Throw < Window_Selectable
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize(info_viewport)
    super(0, info_viewport.rect.y, window_width, fitting_height(4))
    refresh
    self.visible = false
    @info_viewport = info_viewport
  end
  #--------------------------------------------------------------------------
  # * Get Window Width
  #--------------------------------------------------------------------------
  def window_width
    Graphics.width - 128
  end
  #--------------------------------------------------------------------------
  # * Get Digit Count
  #--------------------------------------------------------------------------
  def col_max
    return 2
  end
  #--------------------------------------------------------------------------
  # * Get Number of Items
  #--------------------------------------------------------------------------
  def item_max
    $game_troop.alive_members.size
  end
  #--------------------------------------------------------------------------
  # * Get Enemy Object
  #--------------------------------------------------------------------------
  def enemy
    $game_troop.alive_members[@index]
  end
  #--------------------------------------------------------------------------
  # * Draw Item
  #--------------------------------------------------------------------------
  def draw_item(index)
    change_color(normal_color)
    name = $game_troop.alive_members[index].name
    draw_text(item_rect_for_text(index), name)
  end
  #--------------------------------------------------------------------------
  # * Show Window
  #--------------------------------------------------------------------------
  def show
    if @info_viewport
      width_remain = Graphics.width - width
      self.x = width_remain
      @info_viewport.rect.width = width_remain
      select(0)
    end
    super
  end
  #--------------------------------------------------------------------------
  # * Hide Window
  #--------------------------------------------------------------------------
  def hide
    @info_viewport.rect.width = Graphics.width if @info_viewport
    super
  end

end # End of Window_BattleEnemy_Throw class


#==============================================================================
# * New Class
# ** Window_ThrowItem                 (alternate version of Window_BattleItem)
#------------------------------------------------------------------------------
#  This class is for selecting items to use in the "Throw Item" Window.
#==============================================================================
class Window_ThrowItem < Window_ItemList
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize(help_window, info_viewport)
    y = help_window.height
    super(0, y, Graphics.width, info_viewport.rect.y - y)
    self.visible = false
    @help_window = help_window
    @info_viewport = info_viewport
  end
  #--------------------------------------------------------------------------
  # * Include in Item List?
  # Note to Refractors - You wouldn't believe what this used to look like.
  #--------------------------------------------------------------------------
  def include?(item)
    return true if item.is_a?(RPG::Item) && item.note[/<throwheal>/i]
    return true if item.is_a?(RPG::Item) && item.note[/<throwhalf>/i]
    return true if item.is_a?(RPG::Item) && item.note[/throwdmg/i]

    return true if item.is_a?(RPG::Weapon) && item.note[/<throwheal>/i]
    return true if item.is_a?(RPG::Weapon) && item.note[/<throwhalf>/i]
    return true if item.is_a?(RPG::Weapon) && item.note[/throwdmg/i]

    return true if item.is_a?(RPG::Armor) && item.note[/<throwheal>/i]
    return true if item.is_a?(RPG::Armor) && item.note[/<throwhalf>/i]
    return true if item.is_a?(RPG::Armor) && item.note[/throwdmg/i]
  end
  #--------------------------------------------------------------------------
  # * Display in Enabled State?
  #--------------------------------------------------------------------------
  def enable?(item)
    true
  end
  #--------------------------------------------------------------------------
  # * Show Window
  #--------------------------------------------------------------------------
  def show
    select_last
    @help_window.show
    super
  end
  #--------------------------------------------------------------------------
  # * Hide Window
  #--------------------------------------------------------------------------
  def hide
    @help_window.hide
    super
  end

end # End of Window_ThrowItem class


#------------------------------------------------------------------------------#
#                               Scene Classes                                  #
#==============================================================================
# * Existing Class
# ** Scene_Battle
#------------------------------------------------------------------------------
#  This class performs battle screen processing.
#  Basically it manages what happens in a battle.
#==============================================================================
class Scene_Battle < Scene_Base
  #--------------------------------------------------------------------------
  # * Existing Method
  # ** Create All Windows (aliased)
  #--------------------------------------------------------------------------
  alias thesarah_throwscript_scenebattle_createallwinds     create_all_windows
  def create_all_windows
    thesarah_throwscript_scenebattle_createallwinds
    create_throwitem_window      
    create_enemy_throw_window    
  end
  #--------------------------------------------------------------------------
  # * Existing Method
  # ** Create Actor Commands Window (aliased)
  #--------------------------------------------------------------------------
  alias thesarah_throwscript_scenebattle_createactorcmdwin  create_actor_command_window
  def create_actor_command_window
    thesarah_throwscript_scenebattle_createactorcmdwin
    @actor_command_window.set_handler(:throw,  method(:command_throwitem))
  end
  #--------------------------------------------------------------------------
  # * New Method
  # ** [Throw Item] Command
  #--------------------------------------------------------------------------
  def command_throwitem
    @throwitem_window.refresh
    @throwitem_window.show.activate
  end
  #--------------------------------------------------------------------------
  # * New Method
  # ** Create Throw Item Window
  #--------------------------------------------------------------------------
  def create_throwitem_window
    @throwitem_window = Window_ThrowItem.new(@help_window, @info_viewport)
    @throwitem_window.set_handler(:ok,     method(:on_throwitem_ok))
    @throwitem_window.set_handler(:cancel, method(:on_throwitem_cancel))
  end
  #--------------------------------------------------------------------------
  # * New Method
  # ** Throw Item [OK]
  #--------------------------------------------------------------------------
  def on_throwitem_ok
    @throwitem = @throwitem_window.item
    if @throwitem == nil
      @throwitem_window.hide
      Audio.se_play("Audio/SE/Buzzer1", 80, 100)
      @actor_command_window.activate
    else
        BattleManager.actor.input.set_item(@throwitem.id)
        BattleManager.actor.thrown_item          = @throwitem.id
        BattleManager.actor.thrown_item_notetag  = @throwitem.note
        if @throwitem.is_a?(RPG::Armor)
             BattleManager.actor.thrown_item_category = "Armour"
     elsif @throwitem.is_a?(RPG::Weapon)
             BattleManager.actor.thrown_item_category = "Weapon"
     elsif @throwitem.is_a?(RPG::Item)
             BattleManager.actor.thrown_item_category = "Item"
        end
        @throwitem_window.hide
        select_throw_enemy_selection
    end
    $game_party.last_item.object = @throwitem
  end
  #--------------------------------------------------------------------------
  # * New Method
  # ** Throw Item [Cancel]
  #--------------------------------------------------------------------------
  def on_throwitem_cancel
    @throwitem_window.hide
    @actor_command_window.activate
  end
  #--------------------------------------------------------------------------
  # * New Method
  # ** Create Enemy Throw Window
  #--------------------------------------------------------------------------
  def create_enemy_throw_window
    @enemy_window_throw = Window_BattleEnemy_Throw.new(@info_viewport)
    @enemy_window_throw.set_handler(:ok,     method(:on_enemy_throw_ok))
    @enemy_window_throw.set_handler(:cancel, method(:on_enemy_throw_cancel))
  end
  #--------------------------------------------------------------------------
  # * New Method
  # ** Start Throw Enemy Selection
  #--------------------------------------------------------------------------
  def select_throw_enemy_selection
    @enemy_window_throw.refresh
    @enemy_window_throw.show.activate
  end
  #--------------------------------------------------------------------------
  # * New Method
  # ** Enemy [OK] (after picking an item to throw)
  #--------------------------------------------------------------------------
  def on_enemy_throw_ok
    BattleManager.actor.input.target_index = @enemy_window_throw.enemy.index
    @skill_window.hide
    @item_window.hide
    @enemy_window_throw.hide
    @throwitem_window.hide
    BattleManager.actor.input.set_throw_action
    next_command
  end
  #--------------------------------------------------------------------------
  # * New Method
  # ** Enemy [Cancel] (after picking an item to throw)
  #--------------------------------------------------------------------------
  def on_enemy_throw_cancel
    @enemy_window_throw.hide
    BattleManager.actor.reset_thrown_item
    case @actor_command_window.current_symbol
    when :throw
      @throwitem_window.show.activate
    end
  end
  #--------------------------------------------------------------------------
  # * Existing Method
  # ** Actor [OK] (aliased)
  #--------------------------------------------------------------------------
  alias thesarah_throwscript_scenebattle_onactorok        on_actor_ok
  def on_actor_ok
    thesarah_throwscript_scenebattle_onactorok
    @throwitem_window.hide
  end
  #--------------------------------------------------------------------------
  # * Existing Method
  # ** Actor [Cancel] (aliased)
  #--------------------------------------------------------------------------
  alias thesarah_throwscript_scenebattle_onactorcancel    on_actor_cancel
  def on_actor_cancel
    thesarah_throwscript_scenebattle_onactorcancel
      case @actor_command_window.current_symbol
      when :throwitem              
        @throwitem_window.show.activate
      end
  end

end # End of Scene_Battle class




#------------------------------------------------------------------------------#
                              # End of Script #
#------------------------------------------------------------------------------#
#------------------------------------------------------------------------------#
#------------------------------------------------------------------------------#


#=end


Screenshots
.​
1) Successful Throw 1.png 2) Successful Throw 2.png
3) Successful Throw 3.png 4) Successful Throw 4.png
5) Successful Throw 5.png



FAQ
.
Q: Can you add more notetag damage options?

A: Yes I can! Simply ask on this forum thread for what you'd like and I'll do what I can when I have the time (which honestly shouldn't be too long a wait lol).


Credit and Thanks
.
The_Sarah (aka me) for being awesome and writing this script :p
.
Also:​

* TheoAllen (RPG Maker Forum user) for initially helping me with figuring out the make_damage_value method.

* Kyonides (RPG Maker Forum user) for helping with Module Instance Variables and Regex.

* A-Moonless-Night (RPG Maker Forum user) for helping me with Aliasing and to finally understand how to grab specific parts within a Regex string.

* LockeZ Ninja Throw (Script) for helping me figure out how to decrease items when thrown.

* Any future refractors or nice people who give me tips on future versions of the script

* And all of you who download the script and use it! Because sharing is fun :)


Author's Notes
.
Future versions will come out on the same page as this one.
Planned additions to the script include ally-targeting and adding in a random chance of picking up items you've thrown at the end of each battle.
Any requests for extra Note Tag options will also be realised in future versions.


Terms of Use
.
(1) When sharing this script online, please link to this original Forum Thread page.​
..
(2) If you share a game with this script in it (freely or commercially), you MUST credit me in the game.
i ) Ideally like this: "Throw Script by The_Sarah"
ii ) If you edited it then like this: "Original Throw Script by The_Sarah"​
..
(3) Other than that, this script is free to download and use or edit in any game or project (free or commercial).


Love and Peace everyone!
Love AND Peace!​
 
Last edited:
  • Like
Reactions: BCj

kyonides

Reforged is laughable
Veteran
Joined
Nov 17, 2019
Messages
285
Reaction score
70
First Language
English
Primarily Uses
RMXP
@The_Sarah
You better start using the regular expression \d+ in your script. You'd save LOTS of lines if you did. Really, it'd make make_damage_value method run faster for it wouldn't be running dozens of tests in a row. Such a script behavior is undesirable for you can easily parse the actual value once and multiply the value variable by that other value.
Other regex like throwhalf or throwheal look fine, there's no number to parse anyway. XD
You can replace lots of global variables with instance variables that would be stored in the module you wisely created.

Code:
module AModule
  class << self
    attr_reader :var1
    attr_accessor :var2, :var3
  end
end
Then you could call them like this:

Code:
AModule.var1
AModule.var2 = value
They're available pretty much anywhere but aren't as resource hungry as $globals. They're good for temporary values.
There's also the Game_Temp class that can hold even more @instance variables if deemed necessary. You'd call its new methods via $game_temp.some_new_method

Well, I haven't tested it so I can't provide further feedback but I hope it'd be fine.
 

The_Sarah

Let's make great games together!
Veteran
Joined
Jul 18, 2020
Messages
100
Reaction score
79
First Language
English
Primarily Uses
RMVXA
@The_Sarah
You better start using the regular expression \d+ in your script. You'd save LOTS of lines if you did. Really, it'd make make_damage_value method run faster for it wouldn't be running dozens of tests in a row. Such a script behavior is undesirable for you can easily parse the actual value once and multiply the value variable by that other value.
Other regex like throwhalf or throwheal look fine, there's no number to parse anyway. XD
You can replace lots of global variables with instance variables that would be stored in the module you wisely created.

Code:
module AModule
  class << self
    attr_reader :var1
    attr_accessor :var2, :var3
  end
end
Then you could call them like this:

Code:
AModule.var1
AModule.var2 = value
They're available pretty much anywhere but aren't as resource hungry as $globals. They're good for temporary values.
There's also the Game_Temp class that can hold even more @instance variables if deemed necessary. You'd call its new methods via $game_temp.some_new_method

Well, I haven't tested it so I can't provide further feedback but I hope it'd be fine.
I KNEW there'd be a way to do it without global variables! It was the first Module I made so I was having a hard time figuring out how to make Module Public Instance variables work. Thanks for the tip! Will update in next version.

As for REGEX, yeah, I was having a rough time figuring out how to get d to work, in my original version I was using it but then it kept activating both the damage result for 1 AND the damage result for 11 (for example) when the Item's note tag was 11 and that would result in it just doing NO DAMAGE as it couldn't figure out what was what.

Would definitely appreciate any REGEX tips for tidying that up.

And is that it? Those were the two main issues I had in my mind (and I'm pretty sure I wrote them in Notes somewhere) too!

Thanks for solving one for me already :D

Oh! And just for any onlookers who're reading this but don't know much about scripting, this is all just about making the script run better and look neater, the script works fine as is so if all you're interested in is a FF style Throw Script then have at it! :)
 

A-Moonless-Night

WINTER IS COMING
Veteran
Joined
Mar 17, 2012
Messages
659
Reaction score
427
First Language
English
Primarily Uses
RMVXA
If you're looking at a good regex resource for Ruby, try Rubular. Here's how you can tidy up the regex you're using for the damage modifier:
Ruby:
/<throw_damage\s*(\d+)>/i
This means that if someone writes <throw_damage5> or <throw_damage 100> or <throw_damage 50>, the regular expression will pick up the number. \d is used to check for a digit; \d+ checks for 1 or more digits. Enclosing it in the parentheses like so (\d+) means that it will capture that digit and you can use it in your code, like so:
Ruby:
case @item.note
when /<damage_value\s*(\d+)>/i
    result *= $1.to_i # $1 is a placeholder for the first captured value, $2 is for the second, etc.
    # .to_i turns the result into an integer
else
    result *= your_default_modifier_here
end
The \s looks for a whitespace character (e.g. spacebar) and \s* looks for 0 or more whitespace characters.

You'll also want to look into aliasing methods in order to make your scripts compatible with other scripts that touch the same methods. For example, if you make another script that overwrites one of those methods and place it below this one, you'll see that the bottom-most script with the overwritten method will take precedence and the stuff you've put in the earlier overwritten method won't even run.
A basic run-down on aliasing: you want to take the original method, store it in a new method name and then run it after (or before) your own stuff. You do something like so:
Ruby:
alias aliased_method_name original_method_name
def original_method_name
    run_new_methods_here
    aliased_method_name # call the original method and let it run
    run_other_new_methods_here
end
It's just a brief run-down, but I hope it helps! Have a look at others' scripts and see how they've done their aliasing. You just have to make sure that the aliased method name doesn't already exist somewhere in that class. I like to do this:
Ruby:
alias amn_projectname_classname_aliasedmethodname original_method_name
def original_method_name
    run_new_methods_here
    amn_classname_aliasedmethodname # call the original method and let it run
    run_other_new_methods_here
end
(e.g. if I was making a item stealing script, I might call the aliased method amn_itemsteal_classname_aliasedmethodname)

Others like to use their handle and the original method name (maybe just the first characters of each word) and a bunch of random numbers, e.g. amn_classname_almena_g7i8 (by bashing the keyboard and getting a random sequence of characters.

Hope this helps! Feel free to DM me if you want. :)
 
Last edited:

kyonides

Reforged is laughable
Veteran
Joined
Nov 17, 2019
Messages
285
Reaction score
70
First Language
English
Primarily Uses
RMXP
Yeah, parentheses are useful in regex. Actually that reminds me of /throw.(\d+)/I where the dot . means any character you don't care about but just one. Even so there's no actual need for . or \s if people are already used to leaving a space between the keyword and the numerical value imho.
For those that still ignore this, I at the end of a regex means it's case insensitive.
 

The_Sarah

Let's make great games together!
Veteran
Joined
Jul 18, 2020
Messages
100
Reaction score
79
First Language
English
Primarily Uses
RMVXA
Thanks again guys for the tips!
 
Last edited:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Hello I buyed RPG Maker VX Ace a long ago and I want to use it again but in the meantime I changed my pc but I lost the paper with my product key on so I can't use RPG maker again... someone can help me please ? or there is no hopes ?:'( ( I have a bad english I'm sorry )
I was away this days here in the forum but it was for a good cause!
The trailer of the demo of Luke Inn is on youtube and I am so happy!
I need to see the bugs of the game but I am happy that I have new content to show!

The last part of the modern interior will be ready soon. This will be a B-tile. With interior items for the kitchen, bathroom, toilet and storage room.
This frantic shooting ARPG plugin for MZ looks really great. Here is the link to a post from the official Japanese RPG Maker forum.

Forum statistics

Threads
102,941
Messages
996,123
Members
134,394
Latest member
tp0000
Top