The RPG Maker Resource Kit

RMRK RPG Maker Creation => XP => XP Scripts Database => Topic started by: tSwitch on April 06, 2008, 06:58:05 PM

Title: Weapon Training System v1.00
Post by: tSwitch on April 06, 2008, 06:58:05 PM
Weapon Training System
Version: 1.00
Author: NAMKCOR
Date: April 06, 2008

Version History




Planned Future Versions


Description



Think FF2 with this one.  Characters all have 'skill levels' with types of weapons that grant them bonuses with those types of weapons.  They gain experience every time they attack with the weapon, and each weapon skill level gives them bonus skill in determining attack damage, the accuracy, and the critical rate of that weapon type

Features


Screenshots

N/A for this type of script

Instructions

Comments and instructions for the individual customizations will be given right where they are located.  Only real skills needed are reading, typing, and copy&paste

Script




#=================================================================
#   Weapon Training System                                                     
#---------------------------------------------------------------------------------------------------------------------
#   Created By: NAMKCOR                                                                                                     
#   Created for the Websites: Chaos Project, RPG Maker Resource Kit
#                                                  (www.chaosproject.co.nr; www.rmrk.net)                       
#   If this script is hosted on any other website, then it is stolen, please contact           
#   me at the address given below                                                                                         
#--------------------------------------------------------------------------------------------------------------------
#   If you find any Bugs/Incompatability issues with this script, please contact me at   
#   the following e-mail address: Rockman922@aol.com, and please be descriptive   
#   with your e-mail subject, as I delete spam on sight.                                                                                                             
#--------------------------------------------------------------------------------------------------------------------
#   Function:                                                                                                                             
#    Think FF2 with this one.  Characters all have 'skill levels' with types of weapons that
#    grant them bonuses with those types of weapons.  They gain experience every time
#    they attack with the weapon, and each weapon skill level gives them bonus skill in
#     determining attack damage, the accuracy, and the critical rate of that weapon type
#                                                                         
#    Compatability:                                                                                                                   
#     100% compatability with SDK (some things may conflict I dunno SDK well)
#      80% compatability with exotic CBSes
#      uses own damage calculations that might cause errors in some cases (merge required)
#      0% compatibility with RTAB
#      Unknown as of yet, but high possibility of corrupting old save files
#
#     Instructions:                                                                                                                     
#      Comments and instructions for the individual customizations will be given           
#       right where they are located.  Only real skills needed are reading, typing,             
#       and copy&paste
#--------------------------------------------------------------------------------------------------------------------
#     Version History:
#     1.0 - completed system
#=================================================================
    #how much experience is given per attack
    $WTSexp_rate = 5
   
    #bonus rate formula is weapon level * bonus amount
    $WTSattack_bonus = 10
    $WTSaccuracy_bonus = 10
    $WTScritical_bonus = 10
   
    #==============================================================
    # @exp_levels : how much experience is needed to reach the next level
    #----------------------------------------------------------------------------------------------------------------
    # this array functions quite simply, each element is a level, and the value in that
    # element is the amount of experience needed to reach that level.
    # so an array with values [15, 30, 45] would have 3 levels, level 1 needing 15xp
    # level 2 needing 30xp and level 3 needing 45xp
    #==============================================================
    $WTSexp_levels = [10, 30, 60, 100, 150, 210, 280]
   
    #==============================================================
    # @elements : which elements are used to store weapon types
    #----------------------------------------------------------------------------------------------------------------
    # simply place the indexes of the elements you plan on using in the array below
    # a REMINDER that only the first numerical value of an element will be taken
    # into consideration.  So if you make a weapon with elements 17 and 20, only
    # element 17 will be taken into consideration.
    # ALSO a weapon type -must- be set, or else you will get a range error
    #==============================================================
    $WTSelements = [17, 18, 19, 20]
   


class Game_Actor < Game_Battler

  attr_accessor  :WTSweapon_experience
  attr_accessor  :WTSweapon_levels
 
  alias WTS_setup_after setup
  def setup(actor_id)
    WTS_setup_after(actor_id)
    #==============================================================
    # @WTSweapon_experience
    #----------------------------------------------------------------------------------------------------------------
    # by modifying the case-when, adding whens for every actor, you are able to
    # set what amount of experience with a given weapon type teh character has
    # at the start of your game.  That way a swordsman could be good with swords
    # or a sniper with rifles etc...
    #----------------------------------------------------------------------------------------------------------------
    # default: @WTSweapon_experience = [0,0,0,0]
    #                @WTSweapon_levels = [0,0,0,0]
    # template when [actor_id] then
    #                             @WTSweapon_experience = [0,0,0,...]
    #                             @WTSweapon_levels = [0,0,0,...]
    #                 end
    # !!! WARNING !!! be sure to add an element to these arrays for every weapon
    # element type used, or you may encounter bugs later on; and try to line up
    # weapon levels with the appropriate amount of experience, or when it
    # auto-corrects, it will appear very buggy
    #==============================================================
    case actor_id
      when 1 then
        @WTSweapon_experience = [0,0,0,0]
        @WTSweapon_levels = [0,0,0,0]
      when 2 then
        @WTSweapon_experience = [0,0,0,0]
        @WTSweapon_levels = [0,0,0,0]
      end
    end
   
    #===================================================================
    # DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING
    #===================================================================
   
    def attack_bonus
      @temp_element = $data_weapons[self.weapon_id].element_set
      for i in 0...@temp_element.size
          for j in 0...$WTSelements.size
            if $WTSelements[j] == @temp_element[i]
              return $WTSattack_bonus * @WTSweapon_levels[j]
            end
          end
        end
      end
     
      def accuracy_bonus
      @temp_element = $data_weapons[self.weapon_id].element_set
      for i in 0...@temp_element.size
          for j in 0...$WTSelements.size
            if $WTSelements[j] == @temp_element[i]
              return $WTSaccuracy_bonus * @WTSweapon_levels[j]
            end
          end
        end
      end
     
      def critical_bonus
      @temp_element = $data_weapons[self.weapon_id].element_set
      for i in 0...@temp_element.size
          for j in 0...$WTSelements.size
            if $WTSelements[j] == @temp_element[i]
              return $WTScritical_bonus * @WTSweapon_levels[j]
            end
          end
        end
      end
  end

class Scene_Battle
 
  alias make_basic_action_result_first make_basic_action_result
  def make_basic_action_result
    make_basic_action_result_first
    if !$game_troop.enemies.include?(@active_battler)
      @temp_element = $data_weapons[@active_battler.weapon_id].element_set
      if @active_battler.current_action.basic == 0
        for i in 0...@temp_element.size
          for j in 0...$WTSelements.size
            if $WTSelements[j] == @temp_element[i]
              @active_battler.WTSweapon_experience[j] += $WTSexp_rate
              if $WTSexp_levels[@active_battler.WTSweapon_levels[j]] != nil
                while @active_battler.WTSweapon_experience[j] >=
                  $WTSexp_levels[@active_battler.WTSweapon_levels[j]]
                  @active_battler.WTSweapon_levels[j] += 1
                end
              end
            end
          end
        end
      end
    end
  end
 
end

class Game_Battler
 
  alias attack_effect_old attack_effect
  def attack_effect(attacker)
    self.critical = false
    if !$game_troop.enemies.include?(attacker)
    hit_result = (rand(100) < (attacker.hit + attacker.accuracy_bonus))
    if hit_result == true
      atk = [(attacker.atk + attacker.attack_bonus) - self.pdef / 2, 0].max
      self.damage = atk * (20 + attacker.str) / 20
      self.damage *= elements_correct(attacker.element_set)
      self.damage /= 100
      if self.damage > 0
        if rand(100) < 4 * (attacker.dex + attacker.critical_bonus) / self.agi
          self.damage *= 2
          self.critical = true
        end
        if self.guarding?
          self.damage /= 2
        end
      end
      if self.damage.abs > 0
        amp = [self.damage.abs * 15 / 100, 1].max
        self.damage += rand(amp+1) + rand(amp+1) - amp
      end
      eva = 8 * self.agi / attacker.dex + self.eva
      hit = self.damage < 0 ? 100 : 100 - eva
      hit = self.cant_evade? ? 100 : hit
      hit_result = (rand(100) < hit)
    end
    if hit_result == true
      remove_states_shock
      self.hp -= self.damage
      @state_changed = false
      states_plus(attacker.plus_state_set)
      states_minus(attacker.minus_state_set)
    else
      self.damage = "Miss"
      self.critical = false
    end
    return true
    end
    attack_effect_old(attacker)
  end
end


Credit




Thanks


Support



If you find any Bugs/Incompatability issues with this script, please contact me at the following e-mail addresses: Rockman922@aol.com and rockmanamkcor@yahoo.com, and please be descriptive with your e-mail subject, as I delete spam on sight.

Known Compatibility Issues

incompatible with RTAB, trying to figure out a merge or something

Demo



demo attached to bottom of post

Author's Notes



This is my first foray back into scripting for a while, I'm glad it finally worked, and I hope y'all like it \o/

Restrictions

Created for the Websites: Chaos Project, RPG Maker Resource Kit
(www.chaosproject.co.nr; www.rmrk.net)                     
If this script is hosted on any other website, then it is stolen, please contact me at either of the locations given

If you use this script in your game, please link me to the topic
I love to see what my work is used for

do NOT use this script in a commercial game unless you get my permission first
Title: Re: Weapon Training System v1.00
Post by: modern algebra on April 06, 2008, 07:29:18 PM
It looks very cool NAM, will try it out later.
Title: Re: Weapon Training System v1.00
Post by: tSwitch on April 06, 2008, 07:47:32 PM
crap, I forgot to remove the print lines in the script >.<
re-uploading now
Title: Re: Weapon Training System v1.00
Post by: modern algebra on April 06, 2008, 07:59:01 PM
By the way, I think you might need to update your links to chaos project. It's something like http://chaos-project.com/cpforum/index.php or something now.
Title: Re: Weapon Training System v1.00
Post by: tSwitch on April 06, 2008, 09:20:15 PM
the .co.nr still loaded for me the other day, I'll find the new link and update it

also, topic updated ;-;

edit: I'm working on making the system RTAB compatible, please bear with me :)
Title: Re: Weapon Training System v1.00
Post by: Claire the Fruitcake on April 18, 2008, 02:32:18 PM
-hammers down on +Rep button-
Title: Re: Weapon Training System v1.00
Post by: Shadow Eye on April 20, 2008, 04:39:28 PM
I've been searching for something like this for a while! And now, I have a question: Is there a way to make certain weapons require a certain level of mastery using this script? Like in Fire Emblem, fora swordsman to use certain swords, they need to have a certain level of mastery.
Title: Re: Weapon Training System v1.00
Post by: tSwitch on April 25, 2008, 04:56:09 PM
I'm working on a version of my equipment requirement system that allows for weapon level requirement, so I'll PM you when that's done and added
Title: Re: Weapon Training System v1.00
Post by: Nox on June 04, 2010, 10:03:46 AM
Sorry if this is considered necro-posting ._.

Quote
    #==============================================================
    # @elements : which elements are used to store weapon types
    #----------------------------------------------------------------------------------------------------------------
    # simply place the indexes of the elements you plan on using in the array below
    # a REMINDER that only the first numerical value of an element will be taken
    # into consideration.  So if you make a weapon with elements 17 and 20, only
    # element 17 will be taken into consideration.
    # ALSO a weapon type -must- be set, or else you will get a range error
    #==============================================================
    $WTSelements = [17, 18, 19, 20]

So if I get things right... The elements are the fire, water, vs beasts, etc, right? And there needs to be one element per weapon type, right? And they'd have to be the first elements, otherwise if I make a weapon that has both element fire (1) and sword (16), it wouldn't even register that it was a sword, and therefore not take the exp system into account?
Or have I misunderstood stuff?

Edit: I check in now and then, NAMKCOR ^^;  Thanks for answering my question =D You're made of awesomesauce!
*edits post to avoid necroposting with a thankyou*
Title: Re: Weapon Training System v1.00
Post by: tSwitch on June 20, 2010, 02:52:45 AM
wow, I don't think the person that asked is here to see this but, that explanation was about weapon types only.  If you try to make a sword/spear it won't work, but if you wanted to make a fire/sword it should, because fire isn't in the weapons type array.