The_Sarah - [v2.4] Multi-Hits based on Agility

The_Sarah

Let's make great games together!
Veteran
Joined
Jul 18, 2020
Messages
100
Reaction score
79
First Language
English
Primarily Uses
RMVXA
Heyoo!
This is my first ever public script! :o

Hits Times Agility v2.4
by The_Sarah

Introduction
This script ties the amount of times a skill is activated in a turn to the difference in Game Actor's agility to the Game Troop Member's agility.

---------------------
Patch Notes
- Update 6 -
Version 2.4 is released!
i) Code stuff:
This version gets rid of the item_hits_generator instance variable and makes it so skill hits are based directly on the random number generated plus any additional numbers required.
- So, for example, "item.repeats = rand(2) + 1" gives us 50% chance to hit once or twice, as rand(2) generates a 0 or a 1 and 0 + 1 is 1 and 1 + 1 is 2... at least according to my old Maths teacher.

ii) The Advanced Tutorial Tips have been updated accordingly.

iii) This version also cuts out some of the fat in the code of version 2.3.1

iv) Please remember, since Update 5, the Notetag for this script is no longer <sarahrepeats> and is instead <multihits>

- Update 5 -
Version 2.3 is released!
i) This version changes the Notetag from "<sarahrepeats>" to "<multihits>"
ii) This version allows the player to put the Notetag "<multihits>" in a skill that BOTH the Enemy Unit and the Player Party Member can use without any problems.
iii) This version adds a small Module to the Script.
iv) This version includes some Tutorial Tips on Scripting and reverts the Script to a more direct approach for altering the amount of hits done (rather than using Variables like previous versions did).
v) This version is awesome.
vi) Updated to 2.3.1 to fix a slight oversight that would break the game. This is now fixed. Everything is perfect.
vii) This version is perfect.

- Update 4 -
Version 2.2 is released!
i) This version is just a simple aliasing update, but now you can use this script with as many other scripts as you like and there shouldn't be any coding conflictions.
ii) I have erased versions 2.1 and 1.0 as they do not have aliased methods and thus can conflict with other scripts.
iii) I have changed to using this Forum's Code and Spoiler box systems for sharing the code, rather than an external Pastebin link.
iv) Updated to v2.2.1 to fix an oversight on the speedcheck of being between 1* and 1.5* the speed of enemy.

- Update 3 -
i) I have made a version 2.1 and renamed it a little.
ii) I'll leave the original Pastebin link for version 1.0 below (the simplest version of this script), but will now tweak the rest of this post so it's relevant to version 2.1.
-Update 2-
i) Version 2.0 was a bit over the top. So see update 3 as I have now streamlined this more detailed version into something more readable and hopefully less intimidating.

-Update 1 -
i) Turns out there's a required format to submitting scripts, so I have filled mine out.
---------------------


Features
Original script made by me (The_Sarah).
Initially requested by Oddball.
Further edits done by me (The_Sarah) but after reading tips from Kyonides and Trihan

The Script by default makes it so:
If actor agi is 2* enemy agi or higher the skill hits 3 times.
If actor agi is equal to or greater than 1.5* enemy agi (but less than 2*) the skill has a 50% chance to hit twice and a 50% chance to hit thrice.
If actor agi is equal to enemy agi it has a 1/3 chance to hit once, twice, or thrice.
If actor agi is equal to or greater than 0.5* enemy agi (but less than 1*) it has a 50% chance to hit once and a 50% chance to hit twice.
Any lower than the last example, and it only hits once .


How to Use
Place script below materials and above main in the Script Editor.​

Basic Use -

i) Write the "<multihits>" Notetag in the Notes Box section of any skill you want to have this script's effects.

ii) The Notes Box section of skills are found under Skills in the Database.

iii) The Notetag is written without the speech marks.

iv) Notetag: "<multihits>"


Advanced Use -

You can alter the amount of times a skill hits (within a Speed Check) by editing the number that comes after the "item.repeats = " part of the Editable Method in the Script.

Information on how rand() works has also been included in the Tutorial Tips of this script.

Expert Use -

Additional Agility Times (Speed Checks) can be created, but will require some coding/scripting on your part to create (tutorial tips are included in the Script).


Script
Hits Times Agility v2.4 by The_Sarah
Ruby:
#------------------------------------------------------------------------------#
=begin

                           Multi Hits x Agility
                     
                              (version 2.4)

                              by The_Sarah

                           
--                                                                            --
                           
                           
                             ~ REQUIREMENTS ~
                                  None

                               
--                                                                            --


                              ~ HOW TO USE ~

                               -Basic Use-
                            
   Write the "<multihits>" Notetag in the Notes Box section of any skill
   you want to have this script's effects.

   The Notes Box section of skills are found under Skills in the Database.

   The Notetag is written without the speech marks.

   Notetag: "<multihits>"

                               
--                                                                            --


                               ~ FEATURES ~

   By default, this script makes it so skills cast by the Player Party Members
   (aka the Game Actors) will hit multiple times depending on the difference
   in that Actor's Agility score compared to the Enemy's Agility score.

   The following Speed Checks make the chosen skills hit the following amount
   of times:

-

100% chance to use: 3 times if Player Agility (Plyr Agi) is 2* the Enemy's
                            Agility (Eny Agi).
                            Or if Plyr Agi is greater than 2* Eny Agi.

-

50%  chance to use: 2 times if Plyr Agi is equal to 1.5* Eny Agi.
                            Or if Plyr Agi is higher than 1.5* Eny Agi while
                            still being lower than 2* Eny Agi.

50%  chance to use: 3 times if Plyr Agi is equal to 1.5* Eny Agi.
                            Or if Plyr Agi is higher than 1.5* Eny Agi while
                            still being lower than 2* Eny Agi.

-

33%  chance to use: 1 time  if Plyr Agi is exactly equal to Eny Agi.
                            Or if Plyr Agi is higher than 1* Eny Agi while
                            still being lower than 1.5* Eny Agi.

33%  chance to use: 2 times if Plyr Agi is exactly equal to Eny Agi.
                            Or if Plyr Agi is higher than 1* Eny Agi while
                            still being lower than 1.5* Eny Agi.
                         
33%  chance to use: 3 times if Plyr Agi is exactly equal to Eny Agi.
                            Or if Plyr Agi is higher than 1* Eny Agi while
                            still being lower than 1.5* Eny Agi.

-

50%  chance to use: 1 time  if Plyr Agi is equal to 0.5* Eny Agi.
                            Or if Plyr Agi is higher than 0.5* Eny Agi while
                            still being lower than 1* Eny Agi.
                         
50%  chance to use: 2 times if Plyr Agi is equal to 0.5* Eny Agi.
                            Or if Plyr Agi is higher than 0.5* Eny Agi while
                            still being lower than 1* Eny Agi.
                 
-

100% chance to use: 1 time if Plyr Agi is less than 0.5* Eny Agi.


--                                                                            --


                              ~ HOW TO USE ~
                               (continued)
                           
                              -Advanced Use-

   You can alter the amount of times a skill hits (within a Speed Check) by
   editing the number that comes after the "item.repeats = rand()" part of
   the Editable Method below.
  
   For full information on how to write those lines, look in the Scripting Tips
   section below.
  
   Here are some examples:
   item.repeats = rand(2)       means 50% chance to hit 0 times or 1 time
   item.repeats = rand(2) + 1   means 50% chance to hit 1 time or 2 times
   item.repeats = rand(3) + 1   means 33% chance to hit 1 time, 2 times or 3 times
   item.repeats = rand(3) + 2   means 33% chance to hit 2 times, 3 times or 4 times
   item.repeats = rand(2) + 2   means 50% chance to hit 2 times or 3 times
   item.repeats = rand(2) + 3   means 50% chance to hit 3 times or 4 times
   item.repeats = 3             means 100% chance to hit 3 times
                           
--                                                                            --
                           
                           
                            ~ AUTHOR'S NOTES ~                            
                           
   This is the first public script I've made to share, so sorry if it's a
   little messy.

   However, it should do everything that RPG Maker Forum user Oddball has
   requested (as well as a little bit extra) :).

   Also, as it is a short script, I have decided to include some tutorial
   information on how to alter scripts within this intro.


--                                                                            --


                              ~ HOW TO USE ~
                               (Scripting)
                            
                               -Expert Use-
                            
   Additional Agility Times (Speed Checks) can be created, but will require
   some coding/scripting on your part to create.


   In the appropriate location, I have left the comment
   "# *Additional Speed Checks go here* #" for you to add any
   Speed Checks you wish to include.

  
   I have also added a Scripting Tips section (the one after this one) for
   any people with limited to no scripting experience in the hopes that it
   will help. :)


   Simply ignore it if it does not apply to or interest you.


--                                                                            --


                            ~ SCRIPTING TIPS ~
                           
   >   checks if something "is greater than" something else.
   <   checks if something "is less than" something else.
   ==  checks if something "is equal to" something else.
   >=  checks if something "is greater than OR equal to" something else.
   <=  checks if something "is less than OR equal to" something else.

   =   sets something AS something else

   So      "dinner = cooked"    means that dinner is NOW equal to cooked.
   Whereas "dinner == cooked"   ASKS you if dinner is cooked yet.

   rand(2) generates a random number between 0 and 2 but not including 2.
   rand(3) generates a random number between 0 and 3 but not including 3.
   rand(4) generates a random number between 0 and 4 but not including 4.

   So rand(3) can generate the numbers 0, 1 and 2 for example.

   item.repeats = 1 means the skill will hit 1 time.
   item.repeats = 2 means the skill will hit 2 times.
   item.repeats = 5 means the skill will hit 5 times.

-                                                                              -  
   Combining item.repeats and rand() gives us something like this:
   item.repeats = rand(2) + 1 

           This will make item.repeats equal to 0 + 1 or 1 + 1
           Meaning the skill will hit either 1 time or 2 times.
  
   Another example:
   item.repeats = rand(3) + 2
  
           This will make item.repeats equal to 0 + 2, 1 + 2 or 2 + 2
           Meaning the skill will hit either 2 times, 3 times or 4 times.
-                                                                              -     

                                So then!

   If you would like to create an additional Speed Check, you format it
   like this:
  
                                Example
                             
        # 5th Speed Check: >= 3* speed but < 3.5* speed
     elsif self.agi >= 3 * $game_troop.agi && self.agi < 3.5 * $game_troop.agi
          item.repeats = rand(2) + 3
       
         
   This will make it so if Player Speed is equal to or greater than three
   times the Enemy Speed, but less than 3.5 times the enemy speed...
  
   ... The skill will hit either for 3 or 4 times (0 + 3 or 1 + 3).
         

  
   Simple enough, no?


--                                                                            --


                              ~ TERMS OF USE ~
                           
   This script is free to use or edit in any game, however, if you then
   end up sharing your game with others (freely OR commercially)...
       
   ... I'd appreciate you including me in the credits somewhere.

   - Ideally like this: "Hits Times Agility script by The_Sarah"

   - Or, if you Edited it: "Original Hits Times Agility script by The_Sarah"


--                                                                            --
                           

                                ~ Outro ~

                          And that's basically it!
                             Hope this helps!
                       Wish you all... all the best!
                    Let's make wonderful games together!
                              - The_Sarah
                           

P.S - If you have any scripting questions about this Script, feel free to
      write a reply in the original RPG Maker Forum Thread this script is
      hosted in.
   
      I will reply when I have the time :)
                       
=end   
#------------------------------------------------------------------------------#


#------------------------------------------------------------------------------#
#                                The Script                                    #
#==============================================================================
# ** New Module: TheSarahMultiHits
#==============================================================================
module TheSarahMultiHits
  class << self
    attr_accessor   :original_item_repeats
    attr_accessor   :was_game_actor
  end
end # End of TheSarahMultiHits module
#------------------------------------------------------------------------------
# * Existing Class
# ** Game_Battler
#------------------------------------------------------------------------------
class Game_Battler < Game_BattlerBase
#--------------------------------------------------------------------------
# * Existing Method
# ** Calculate Damage (aliased)
#--------------------------------------------------------------------------
  alias thesarah_multihits_gamebattler_makedamageval    make_damage_value
  def make_damage_value(user, item)
    thesarah_multihits_gamebattler_makedamageval(user, item)
    if TheSarahMultiHits::was_game_actor == true
    item.repeats = TheSarahMultiHits::original_item_repeats
    TheSarahMultiHits::was_game_actor = false
    end
  end
end # End of Game_Battler class



#==============================================================================
# * Existing Class
# ** Game_Actor < Game_Battler
#------------------------------------------------------------------------------
#                      The Editable Method is in this class.
#==============================================================================
class Game_Actor < Game_Battler
#------------------------------------------------------------------------------#
#      * Existing Method             (originally from Game_Battler class)      #
#==========~~~~~                                                ~~~~~==========#
#                            ~~ EDITABLE METHOD ~~                             #
#                                                                              #
#                               -Advanced Use-                                 #
#                                                                              #
#   This method (below) is where you will find the various "item.repeats = "   #
#   you can edit the numbers of.                                               #
#                                                                              #
#                               -Expert Use-                                   #
#                                                                              #
#   This method (below) is where you will find the section provided for you    #
#   to add any aditional Speed Checks you wish to create.                      #
#                                                                              #
#   Simply follow the same format as the previous Speed Checks and you         #
#   should be fine.                                                            #
#                                                                              #
#   If you wish to make additional Speed Checks higher than 2* speed:          #
#                                                                              #
#   It may be wise to delete the "#" in the second half of the line for        #
#   the current 2* Speed Check.                                                #
#   This will help limit the range of the 2* speed Speed Check.                #
#                                                                              #
#==========~~~~~                                                ~~~~~==========#
#      ** Use Skill/Item             (aliased)                                 #
#------------------------------------------------------------------------------#
  alias thesarah_multihits_gameactor_use_item        use_item
  def use_item(item)
    if self.is_a?(Game_Actor) && item.is_a?(RPG::Skill) && item.note[/<multihits>/i]
        TheSarahMultiHits::original_item_repeats = item.repeats
        TheSarahMultiHits::was_game_actor = true

        # 1st Speed Check: >= 0.5* speed but < 1* speed
        if self.agi >= 0.5 * $game_troop.agi && self.agi < 1 * $game_troop.agi
          item.repeats = rand(2) + 1
       
        # 2nd Speed Check: >= 1* speed but < 1.5* speed
     elsif self.agi >= 1 * $game_troop.agi && self.agi < 1.5 * $game_troop.agi
          item.repeats = rand(3) + 1
       
        # 3rd Speed Check: >= 1.5* speed but < 2* speed
     elsif self.agi >= 1.5 * $game_troop.agi && self.agi < 2 * $game_troop.agi
          item.repeats = rand(2) + 2
       
        # 4th Speed Check: >= 2* speed (with optional < 2.5* speed)
     elsif self.agi >= 2 * $game_troop.agi # && self.agi < 2.5* $game_troop.agi
          item.repeats = 3
     
        # *Additional Speed Checks go here* #
           
        end
    end
    thesarah_multihits_gameactor_use_item(item)
  end # end of method
 
end # End of Game_Actor class

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


Credit and Thanks
Me, aka The_Sarah for making the script.
Oddball for the idea.
Kyonides and Trihan for ideas on how to improve it.


Terms of use
1) Users must link to this forum post when sharing the script elsewhere.​
2) Users must provide credit to The_Sarah when using the script in free games & sharing those games with others.​
3) Users must provide credit to The_Sarah when using the script in a game selling commercially.​
4) If Users have edited the script, credit must still be provided to The_Sarah for the original script.​
5) Other than that, there is no cost and it is free to use wherever.​
 
Last edited:

kyonides

Reforged is laughable
Veteran
Joined
Nov 17, 2019
Messages
285
Reaction score
70
First Language
English
Primarily Uses
RMXP
I'm just leaving you a couple of recommendations to let you improve your code.

Don't repeat this line of code at all. There's no need for it.

Code:
if item.is_a?(RPG::Skill) && item.note[/<sarahrepeats>/im]
Just let it encapsule the rest of your custom code.

Code:
if item.is_a?(RPG::Skill) && item.note[/<sarahrepeats>/im]
  if  self.agi >= 2* $game_troop.agi
    # code
  elsif self.agi.between(1.5* $game_troop.agi, 2* $game_troop.agi)
    # code
  end
# and so on
end
And you don't need to leave a p(@thesarahrepeats) line in a finished script...

Plus you're free to pick any name for a variable or method name or for a note tag but you really picked a weird one indeed. XD

Code:
item.repeats = 2 if @thesarahrepeats == 0
item.repeats = 3 if @thesarahrepeats == 1
# And repeats and repeats :P
Those lines can be simplified as...

Code:
item.repeats = @thesarahrepeats == 0 ? 2 : 3
It worries me a bit how you set its initial value...

Code:
@thesarahrepeats = 0
It will always be 0 then...

This is how it should look like to make sure you won't make your script ignore the game developer's plans to modify its value at any given time.

Code:
@thesarahrepeats ||= 0
Or instead of including it in use_item, you might define a getter method like this:

Code:
def thesarahrepeats
  @thesarahrepeats ||= 0
end
This way it won't fail if anybody else uses it expecting to get a number. It would get a return value of nil if they've never called use_item before, which isn't a great idea at all...
 

Oddball

Veteran
Veteran
Joined
Sep 4, 2014
Messages
1,888
Reaction score
521
First Language
English
Primarily Uses
N/A
thanks. I'll test it out
 

The_Sarah

Let's make great games together!
Veteran
Joined
Jul 18, 2020
Messages
100
Reaction score
79
First Language
English
Primarily Uses
RMVXA
I'm just leaving you a couple of recommendations to let you improve your code.

Don't repeat this line of code at all. There's no need for it.

Code:
if item.is_a?(RPG::Skill) && item.note[/<sarahrepeats>/im]
Just let it encapsule the rest of your custom code.

Code:
if item.is_a?(RPG::Skill) && item.note[/<sarahrepeats>/im]
  if  self.agi >= 2* $game_troop.agi
    # code
  elsif self.agi.between(1.5* $game_troop.agi, 2* $game_troop.agi)
    # code
  end
# and so on
end
Good tip, thanks.

And you don't need to leave a p(@thesarahrepeats) line in a finished script...

Plus you're free to pick any name for a variable or method name or for a note tag but you really picked a weird one indeed. XD
I left the p lines in there just in case others wanted to break down the script and see how it works themselves, I suppose I can leave them in there but commented out if leaving them active is considered a bad thing.

Wait, what's weird about my variable name? Rude.

Code:
item.repeats = 2 if @thesarahrepeats == 0
item.repeats = 3 if @thesarahrepeats == 1
# And repeats and repeats :P
Those lines can be simplified as...

Code:
item.repeats = @thesarahrepeats == 0 ? 2 : 3
Oh that's cool, I've read (and understood) the ? : in RGSS3 before but never written one myself. So it didn't cross my mind. But you're right I think and that's pretty neat. Thanks.

It worries me a bit how you set its initial value...

Code:
@thesarahrepeats = 0
It will always be 0 then...
I just didn't want it to always be nil first, as returning things as nil can often muck things up.
Also I don't know what you mean by it always being 0, the script works fine for changing that value and doing different things as a result.

This is how it should look like to make sure you won't make your script ignore the game developer's plans to modify its value at any given time.

Code:
@thesarahrepeats ||= 0
Or instead of including it in use_item, you might define a getter method like this:

Code:
def thesarahrepeats
  @thesarahrepeats ||= 0
end
This way it won't fail if anybody else uses it expecting to get a number. It would get a return value of nil if they've never called use_item before, which isn't a great idea at all...
I figured no-one else would be using it, as it's only set up for this script, honestly probably one of the reasons I made the variable name a little long too, to avoid accidental reuses of it elsewhere.

That being said, haven't seen ||= before, might have to look that one up.
 

kyonides

Reforged is laughable
Veteran
Joined
Nov 17, 2019
Messages
285
Reaction score
70
First Language
English
Primarily Uses
RMXP
That operator means set it to that value if equal to nil or ignore value assignment completely.

I didn't wanna bother you but it's weird to include your own nickname in an instance variable's name. Let's say we only tend to include it in aliased method names and leave variable's with descriptive names without nicknames. Thus @repeat_max or @total_repeats and the like would be useful names indeed.
 

The_Sarah

Let's make great games together!
Veteran
Joined
Jul 18, 2020
Messages
100
Reaction score
79
First Language
English
Primarily Uses
RMVXA
That operator means set it to that value if equal to nil or ignore value assignment completely.

I didn't wanna bother you but it's weird to include your own nickname in an instance variable's name. Let's say we only tend to include it in aliased method names and leave variable's with descriptive names without nicknames. Thus @repeat_max or @total_repeats and the like would be useful names indeed.
I see! Thanks for the knowledge :)
 

Oddball

Veteran
Veteran
Joined
Sep 4, 2014
Messages
1,888
Reaction score
521
First Language
English
Primarily Uses
N/A
I didn't wanna bother you but it's weird to include your own nickname in an instance variable's name. Let's say we only tend to include it in aliased method names and leave variable's with descriptive names without nicknames. Thus @repeat_max or @total_repeats and the like would be useful names indeed.
I think the tag could be easily changed. I may not be very good with scripting, but i'm confiedent i can change it to something else
 

The_Sarah

Let's make great games together!
Veteran
Joined
Jul 18, 2020
Messages
100
Reaction score
79
First Language
English
Primarily Uses
RMVXA
I think the tag could be easily changed. I may not be very good with scripting, but i'm confiedent i can change it to something else
Yeah it's not hard to change it, feel free (but credit rules still apply! :p).
Script going well for you then?
I'm planning on uploading a version 2 that has more non-scripter usability in it within the next couple days.
 

Oddball

Veteran
Veteran
Joined
Sep 4, 2014
Messages
1,888
Reaction score
521
First Language
English
Primarily Uses
N/A
Yeah it's not hard to change it, feel free (but credit rules still apply! :p).
Script going well for you then?
I'm planning on uploading a version 2 that has more non-scripter usability in it within the next couple days.
I actually haven't tested it yet. It would be easy to test though, cause the starting charecter has a multi-hit basic attack, and you can choose at the beginning wether DEX (AGI) is your boon(Starts out higher, increases easier), and with some boons you can pick it as a bane (starts out lower, harder to increase). But, both boons and banes choosen come with uniqe skills.. and ive gone off on a tangent

Edit: Works as intended. Thank you!
 
Last edited:

The_Sarah

Let's make great games together!
Veteran
Joined
Jul 18, 2020
Messages
100
Reaction score
79
First Language
English
Primarily Uses
RMVXA
Hey Kyonides!

I've made a version 2.0 that SHOULD address all your problems with it (and allow for more advanced use rather than just the specific use it was originally designed for).

It's certainly a lot wordier now lol.
-Edit-
Oh boy, it certainly DID get wordier lol. Messier too.

I've now released version 2.1 which should hopefully have all the helpful information of version 2.0 but also be a lot more readable and less intimidating.

Feel free to leave comments anyone who is into giving tips on scripts.
 
Last edited:

Oddball

Veteran
Veteran
Joined
Sep 4, 2014
Messages
1,888
Reaction score
521
First Language
English
Primarily Uses
N/A
I ran into a problem. If the attackers AGI is 5 and the deffenders AGI is 4, it only hits once. But if the deffenders AGI is 3 or 5 it works fine
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,602
Reaction score
1,933
First Language
English
Primarily Uses
RMMV
Hi The_Sarah! As we discussed, here's how I would have approached this:

Code:
#------------------------------------------------------------------------------#
#                                The Script                                    #
#==============================================================================
# * Existing Class
# ** Game_Actor
#==============================================================================
Game_Actor.class_eval do
#---------------------------------------------------------------------------
# * Public Instance Variables
#---------------------------------------------------------------------------
attr_accessor :repeat_chances_1 # >= 0.5* enemy agi
attr_accessor :repeat_chances_2 # >= 1.5* enemy agi
attr_accessor :repeat_chances_3 # >= 2* enemy agi


                  # To make any additional Speed Checks #
                    # your additional code goes here #
                  # See examples section 1 for tips how #
                      
                      
                      

#------------------------------------------------------------------------------#
#                         --- EDITABLE METHOD ---                              #
#  To change the amount of hits a skill does, based on agility difference,     #
#      SIMPLY CHANGE THE NUMBERS THAT APPEAR AFTER THE "=" SIGN                #
#             IN THE MIDDLE COLUMN OF THE METHOD BELOW:                        #
#------------------------------------------------------------------------------#
#----------------------------------------------------------------------------
# * Existing Method
# ** Initialize (aliased)
#----------------------------------------------------------------------------
  alias_method(:thesarah_hitsxagiscript_gameactor_initialize, :initialize)
  def initialize(actor_id)
    thesarah_hitsxagiscript_gameactor_initialize(actor_id)
    @repeat_chances_1 = [100, 50] # >= 0.5* enemy agi
    @repeat_chances_2 = [100, 100, 50] # >= 1.5* enemy agi
    @repeat_chances_3 = [100, 100, 100] # >= 2* enemy agi
  end



#---------------------------------------------------------------------------
# * Existing Method
# ** Use Skill/Item (aliased)
#---------------------------------------------------------------------------
  alias_method(:thesarah_hitsxagiscript_gameactor_use_item, :use_item)
  def use_item(item)      
    if item.is_a?(RPG::Skill) && item.note[/<sarahrepeats>/im]
      if self.agi >= 2 * $game_troop.agi # && self.agi < 2.5* $game_troop.agi
        repeat_chances = @repeat_chances_3
      elsif self.agi >= 1.5 * $game_troop.agi && self.agi < 2 * $game_troop.agi
        repeat_chances = @repeat_chances_2
      elsif self.agi == $game_troop.agi
      elsif self.agi >= 0.5 * $game_troop.agi && self.agi < $game_troop.agi
        repeat_chances = @repeat_chances_1 
      else
        repeats = 1
      
      
                  # To make any additional Speed Checks #
                    # your additional code goes here #
                  # See examples section 3 for tips how #                     


      
                
      end
      if repeat_chances
        repeat_chances.each do |chance|
          repeats += 1 if rand(101) <= chance
        end
      else
        if self.agi == $game_troop.agi
          repeats = rand(3) + 1
        else
          repeats = 1
        end
      end
      item.repeats = repeats
    end
          
    thesarah_hitsxagiscript_gameactor_use_item(item)    # Calls original method
  end


end # Game_Actor Class end
 

kyonides

Reforged is laughable
Veteran
Joined
Nov 17, 2019
Messages
285
Reaction score
70
First Language
English
Primarily Uses
RMXP
@The_Sarah Where's version 2.2? I can't find it here. The only one published here seems to be version 2.1...

@Trihan why do you keep evaluating classes and modules? o_O
Evaluations always are slower than straightforward definitions. So why do you prefer the evaluations? I wouldn't mind evaluating stuff during testing but for deployment!? That confuses me greatly.
Anyway, there's no need to post the answer here, it could be sent via DM if deemed necessary.

By the way, there's nothing wrong with using the typical alias instead of alias_method(new_name, old_name)
Plus in both cases parentheses aren't mandatory, just saying in case any reader ignored that fact.

Trihan's approach seems to be good and it doesn't create tones of @instance variables, but I wonder if there's an actual need to use a local variable like repeats or repeat_chances when one could just directly use item.repeats instead. Just saying.
 
Last edited:

The_Sarah

Let's make great games together!
Veteran
Joined
Jul 18, 2020
Messages
100
Reaction score
79
First Language
English
Primarily Uses
RMVXA
@kyonides My bad! I updated the aliasing but forgot to update the name of the version in the script lol. In short that IS 2.2 just called 2.1. I have since changed the name to 2.2 XD.

@Trihan thanks for the feedback, I'll look into it today.

@Oddball
I ran into a problem. If the attackers AGI is 5 and the deffenders AGI is 4, it only hits once. But if the deffenders AGI is 3 or 5 it works fine
Fixed it! Thanks for pointing that out!
I'd previously only included if it was equal to 1*, forgot to make it greater than or equal to 1* but less than 1.5*.
Solved now.
Please use versions 2.2.1 onward to fix this issue.
 
Last edited:

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,602
Reaction score
1,933
First Language
English
Primarily Uses
RMMV
@The_Sarah Where's version 2.2? I can't find it here. The only one published here seems to be version 2.1...

@Trihan why do you keep evaluating classes and modules? o_O
Evaluations always are slower than straightforward definitions. So why do you prefer the evaluations? I wouldn't mind evaluating stuff during testing but for deployment!? That confuses me greatly.
Anyway, there's no need to post the answer here, it could be sent via DM if deemed necessary.

By the way, there's nothing wrong with using the typical alias instead of alias_method(new_name, old_name)
Plus in both cases parentheses aren't mandatory, just saying in case any reader ignored that fact.

Trihan's approach seems to be good and it doesn't create tones of @instance variables, but I wonder if there's an actual need to use a local variable like repeats or repeat_chances when one could just directly use item.repeats instead. Just saying.
I prefer class_eval because it doesn't require knowledge of which class you're expanding and the slowdown is negligible to the point of irrelevance. It's just personal preference and habit I guess.

Same thing with alias_method, I just prefer using that to the alias keyword. The important part is using symbols instead of strings either way.

You probably could just use item.repeats directly instead of variables, but using an array for the repeat chances means it's easy to add more if you want to later. And for something this small, you can get away with it.
 

The_Sarah

Let's make great games together!
Veteran
Joined
Jul 18, 2020
Messages
100
Reaction score
79
First Language
English
Primarily Uses
RMVXA
You probably could just use item.repeats directly instead of variables, but using an array for the repeat chances means it's easy to add more if you want to later. And for something this small, you can get away with it.
Version 1.0 was just doing it directly but, to make it easier for non-scripters to make changes to the amount of hits each speed-check provides, I tried changing it to variables.

I'm currently deconstructing your version now to understand it, am I right in thinking it works like this?:
[100, 100, 50] means 100% chance to hit at least twice 50% chance to hit thrice?

And if so, then making one that's 33% chance to hit once, twice or thrice would be..:
[100, 50, 50]
Right?

And then if you wanted to make it 25% chance to hit once, twice, thrice or four times, it would be:
[100, 33, 33, 33]
Right?

Basically you just have to rewind one odd % (so 25% becomes 33% for example) because you're starting at 100% so it always hits at least once and then you have one less odd % to calculate... right?
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,602
Reaction score
1,933
First Language
English
Primarily Uses
RMMV
Version 1.0 was just doing it directly but, to make it easier for non-scripters to make changes to the amount of hits each speed-check provides, I tried changing it to variables.

I'm currently deconstructing your version now to understand it, am I right in thinking it works like this?:
[100, 100, 50] means 100% chance to hit at least twice 50% chance to hit thrice?

And if so, then making one that's 33% chance to hit once, twice or thrice would be..:
[100, 50, 50]
Right?

And then if you wanted to make it 25% chance to hit once, twice, thrice or four times, it would be:
[100, 33, 33, 33]
Right?

Basically you just have to rewind one odd % (so 25% becomes 33% for example) because you're starting at 100% so it always hits at least once and then you have one less odd % to calculate... right?
That's basically it, yeah. In retrospect, you could cut the array down by an element and just start repeats at 1.
 

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 for all the feedback everyone!

I've reverted the script to a more direct approach after seeing all the suggestions and I've refined my tutorial tips and #notes down so they're not overflowing.

I appreciate some people don't like tutorial tips in a script, but when the script is this short and additions can only be made via requests or further scripting, I kind of feel like I should leave in tutorial tips for those who are like I was 3 or 4 months ago and don't know what's what when it comes to code.

Hopeful this version (2.3.1) should be the last version barring any future requests.

Update - Made a version 2.4 to make the script a bit neater and trim the fat. All is good.
 
Last edited:

BCj

Veteran
Veteran
Joined
Jun 19, 2014
Messages
1,731
Reaction score
928
First Language
Dutch
Primarily Uses
N/A
Going to test this one out, thanks :D
 

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

Latest Threads

Latest Posts

Latest Profile Posts

Hey, uh...refresh my memory. What do i do if I want a thread I made deleted?
I made a cool pixel render of my protagonist!
I think it looks neat.
RCXDan wrote on Leporine's profile.
Your avatar is adorable. Where is it from? :LZSproud:

Forum statistics

Threads
103,186
Messages
997,879
Members
134,661
Latest member
kietemoi
Top