Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

[script] Weapons by ranks

Weapons by ranks Script

Version - 1.1
Author - uresk or 332211 (me)
Release Date - 21/July/08
Requires -Tagnote 2.0 (or above) by Queex


Introduction
With this script then weapons one character can equip depend on their ranking of that type of weapon rather than the character's class.
Note: It can be customized to depend on both.

Features
- weapons depend on rankings
- any number of ranks can be set
- can be changed so that weapons depend both on the calss and rank of the characte
- inserted menu option "Rankings" (changable), to access the rankings easily

Script
################################################################################
#  Script: Weapons by ranks                                                   
#  Version: 1.1                                                             
#  Author: uresk (AKA 332211)                                               
#  Requires: Tagnote 2.0+ (by Queex)                                         
################################################################################
#                                                                             
# Customize: RANKS                                                           
# RANKS = [lowest to highest]                                                 
# RANKS = ["None","Rookie","Master"]                                         
#
#Customize: $exp_ranks                                                       
# $exp_ranks = [0, exp needed for rank 1, exp for rank 2...]                 
# $exp_ranks = [0,100,5000,10000]                                             
#                                                                             
# Customize: EXP_rate                                                         
# regular experience multiplier:                                             
# Ex: You kill Rat and win 13 exp, exp for ranks will be 13 * EXP_rate       
# EXP_rate = number                                                               
#                                                                             
# Customize: $weapon_skills                                                   
# names of your skills in weapons; must be one word                           
# $weapon_skills = ["Swords","Bows","Staffs"]                                 
#                                                                             
# Customize: Class_Limit                                                     
# True: a hero can only equip weapons assigned for his class                 
# False: a hero can equip every weapon, regardless of his class               
#                                                                             
################################################################################
#                                                                             
# Database                                                                   
# In the notes field of a weapon write down <mastery Swords> or <mastery Bows> #
# to determine weapon 'type' and <rank None>,<rank Rookie> to choose the rank  #
# needed to equip that weapon.                                                #
#                                                                              #
################################################################################
#==============================================================================#
#  ** Configuration                                                            #
#==============================================================================#

module Vocab
  Rank_Up = "%s is a %s using %s." #message for when rank goes up
  #%s - actor name; new rank; rank type
  Show_in_Menu = true #true: rankings can be show in the Menu
                      #false: rankings are not shown in the menu
                      #and must be called with '$scene = Scene_weapon_by_ranks.new'
  Menu_Ranks = "Rankings" #word that shows up in the menu
end


module Ranks
  RANKS = ["None","Rookie","Master"]  #ranks from lowest to highest
  $exp_ranks = [0,10,50]              #defines experience
                                      #needed for each rank
  EXP_rate = 2                        #experience multiplier
  $weapon_skills = ["Swords", "Bows", "Staffs"]
  Class_Limit = true  #if true: can only equip weapons checked in the class
                      #Equippable Weapons list.
                      #false: can equip every weapon, only depending on the rank
end
# unless you know what you're doing, don't change the script from here on!
#==============================================================================
# ** Game_Actor
#------------------------------------------------------------------------------
#  This class handles actors. It's used within the Game_Actors class
# ($game_actors) and referenced by the Game_Party class ($game_party).
#==============================================================================

class Game_Actor < Game_Battler
 
  include TAGNOTE                          #include TagNote
  include Ranks                            #get custom defenitions
 
  attr_accessor :weapon_skill_rank          #set object

    alias initialize_with_ranks initialize    #reset actor initialize def

  def initialize(actor_id)
    initialize_with_ranks(actor_id)        #do regular initialize
    @weapon_skill_rank = []                #clear weapon_skill_rank
    for i in 0...$weapon_skills.size do    #sets starting rank
      @weapon_skill_rank = RANKS[0]      #as the 1st Rank
    end
    @ws_exp = []                            #clear ws_exp
  end
 
    alias gain_w_exp gain_exp                #redefining gain_exp
 
  def gain_exp(exp, show)
    gain_w_exp(exp, show)                  # do regular exp_gain
    unless @weapon_id == 0                # if weilding a weapon
      then if has_tag?($data_weapons[@weapon_id].note,"mastery") == true #checks for weapon tag
      then ws = get_tag($data_weapons[@weapon_id].note,"mastery") 
        @ws_i = $weapon_skills.index(ws)      #turn weapon type into index
        if @ws_exp[@ws_i] != nil             
          then $exp_temp = @ws_exp[@ws_i] + exp * EXP_rate #calcs experience
        else                                  #if it's the first time
          $exp_temp.to_i                      #calcs experience
          $exp_temp = exp * EXP_rate
        end
        @ws_exp.delete_at(@ws_i)              #deletes old experience
        @ws_exp.insert @ws_i,$exp_temp        #replaces with new experience value
        rank_index = RANKS.index(@weapon_skill_rank[@ws_i]) #weapon rank --> rank index
        for i in 1...$exp_ranks.size do # compares experience with exp need to the next rank
          if $exp_ranks <= $exp_temp # if exp needed < current exp
          then if rank_index >= i    # and the rank index is not lower
              then next              # goes to the next rank
              else @weapon_skill_rank[@ws_i] = RANKS #else assigns new rank
              end
              text = sprintf(Vocab::Rank_Up,actor.name,RANKS,ws) #prints
              $game_message.texts.push('\.' + text)          #rank up message
          end
        end
      end
    end
  end

    alias can_equip? equippable? #redefining equippable

  def equippable?(item)
    if item.is_a?(RPG::Weapon)                    # if it is a weapon
      can_equip = []                              # hero can be unarmed
      if has_tag?(item.note,"rank")                # gets weapon rank from
        then rank = get_tag(item.note,"rank") end  # the notes field
      rank_num = RANKS.index(rank)                # rank into index
      if has_tag?(item.note,"mastery")            # checks if has mastery tag
        then ws = get_tag(item.note,"mastery")    # gets rank type
        @ws_i = $weapon_skills.index(ws)          # rank type index
        actor_rank = @weapon_skill_rank[@ws_i]    # gets actor rank on that type
        rank_id = RANKS.index(actor_rank)          # turn actor rank into index
        if rank_id != nil and rank_num != nil      # if both index aren't nil
          then if rank_id >= rank_num              # compares them
                then can_equip.push(item.id) end  # if actor rank higher (or nil)
        end                                        # then can be equipped
      else can_equip.push(item.id)                # or weapon has no mastery
      end                                          # then can be equipped
      if Ranks::Class_Limit == true                #extra: if Class Limit is true
        then can_equip = can_equip & self.class.weapon_set end
    return can_equip.include?(item.id)

    elsif item.is_a?(RPG::Armor)                #regular equip method for armors
      return false if two_swords_style and item.kind == 0
      return self.class.armor_set.include?(item.id)
    end
    return false
  end
end

class Scene_weapon_by_ranks < Scene_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #    actor_index : actor index
  #--------------------------------------------------------------------------
  def initialize(actor_index = 0)
    @actor_index = actor_index
  end
  #--------------------------------------------------------------------------
  # * Start processing
  #--------------------------------------------------------------------------
  def start
    super
    create_menu_background
    @actor = $game_party.members[@actor_index]
    @status_window = Window_Ranks.new(@actor)
  end
  #--------------------------------------------------------------------------
  # * Termination Processing
  #--------------------------------------------------------------------------
  def terminate
    super
    dispose_menu_background
    @status_window.dispose
  end
  #--------------------------------------------------------------------------
  # * Return to Original Screen
  #--------------------------------------------------------------------------
  def return_scene
    $scene = Scene_Menu.new(3)
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    update_menu_background
    @status_window.update
    if Input.trigger?(Input::B)
      Sound.play_cancel
      return_scene
    elsif Input.trigger?(Input::R)
      Sound.play_cursor
      next_actor
    elsif Input.trigger?(Input::L)
      Sound.play_cursor
      prev_actor
    end
    super
  end
  #--------------------------------------------------------------------------
  # * Next Actor
  #--------------------------------------------------------------------------
  def next_actor
    @actor_index += 1
    @actor_index %= $game_party.members.size
    $scene = Scene_weapon_by_ranks.new(@actor_index)
  end
  #--------------------------------------------------------------------------
  # * Previous Actor
  #--------------------------------------------------------------------------
  def prev_actor
    @actor_index += $game_party.members.size - 1
    @actor_index %= $game_party.members.size
    $scene = Scene_weapon_by_ranks.new(@actor_index)
  end
end


class Window_Ranks < Window_Base

  include TAGNOTE #includes tagnote
  #--------------------------------------------------------------------------
  # * Object Initialization
  #    actor : actor
  #--------------------------------------------------------------------------
  def initialize(actor)
    super(0, 0, 544, 416)
    @actor = actor
    refresh
  end

  def refresh
    self.contents.clear
    draw_actor_name(@actor, 4, 0)
    draw_actor_face(@actor, 8, 32)
    draw_actor_level(@actor, 8, 136)
    draw_weapons(8, 160)
    draw_weapon_skills(222, 40)
  end
 
  #--------------------------------------------------------------------------
  # * Draw Weapon(s)
  #    x : Draw spot X coordinate
  #    y : Draw spot Y coordinate
  #--------------------------------------------------------------------------
  def draw_weapons(x, y)
    self.contents.font.color = system_color
    self.contents.draw_text(x, y + WLH, 120, WLH, "Weapon")
      draw_item_name(@actor.equips[0], x, y + WLH * 2)
    self.contents.font.color = system_color
    self.contents.draw_text(x, y + WLH * 3, 120, WLH, "Type:")
    self.contents.font.color = normal_color
    if @actor.equips[0] != nil
      then if has_tag?(@actor.equips[0].note,"mastery") == true
          then @skill = get_tag(@actor.equips[0].note,"mastery")
          self.contents.draw_text( x, y + WLH * 4, 120, WLH, @skill)
        end
    end
    self.contents.font.color = system_color
    self.contents.draw_text(x, y + WLH * 5, 120, WLH, "Rank:")
    self.contents.font.color = normal_color
    if @actor.equips[0] != nil
      then if has_tag?(@actor.equips[0].note,"rank") == true
          then rank = get_tag(@actor.equips[0].note,"rank")
          self.contents.draw_text( x, y + WLH * 6, 120, WLH, rank)
        end
    end
  end
 
  #attr_reader :weapon_skill_rank

  #--------------------------------------------------------------------------
  # * Draw Weapon Skills
  #    x : Draw spot X coordinate
  #    y : Draw spot Y coordinate
  #--------------------------------------------------------------------------
def draw_weapon_skills(x, y)
    for i in 0...$weapon_skills.size do
      if $weapon_skills == @skill                    #goes through weapon types
        then self.contents.font.color = system_color    #if matches the current weapon type
        else self.contents.font.color = normal_color    #has a different color
      end
      self.contents.draw_text( x, y, 200, 2 * WLH * (i + 1), $weapon_skills)                  #draws weapon types
      self.contents.draw_text( x + 200, y, 50, 2 * WLH * (i + 1), @actor.weapon_skill_rank)  #draws weapon ranks
    end
  end
end

#this is the menu redefinitions, if you're sure you are not going to use it, you can delete it.

class Scene_Menu < Scene_Base

  if Vocab::Show_in_Menu == true then
   
  alias old_create_command_window create_command_window
 
  def create_command_window
    s1 = Vocab::item
    s2 = Vocab::skill
    s3 = Vocab::equip
    s4 = Vocab::Menu_Ranks
    s5 = Vocab::status
    s6 = Vocab::save
    s7 = Vocab::game_end
    @command_window = Window_Command.new(160, [s1, s2, s3, s4, s5, s6, s7])
    @command_window.index = @menu_index
    if $game_party.members.size == 0          # If number of party members is 0
      @command_window.draw_item(0, false)    # Disable item
      @command_window.draw_item(1, false)    # Disable skill
      @command_window.draw_item(2, false)    # Disable equipment
      @command_window.draw_item(3, false)    # Disable status
      @command_window.draw_item(4, false)    # Disable rankings
    end
    if $game_system.save_disabled            # If save is forbidden
      @command_window.draw_item(5, false)    # Disable save
    end
  end
 
  alias old_update_command_selection update_command_selection
 
  def update_command_selection
    if Input.trigger?(Input::B)
      Sound.play_cancel
      $scene = Scene_Map.new
    elsif Input.trigger?(Input::C)
      if $game_party.members.size == 0 and @command_window.index < 5
        Sound.play_buzzer
        return
      elsif $game_system.save_disabled and @command_window.index == 5
        Sound.play_buzzer
        return
      end
      Sound.play_decision
      case @command_window.index
      when 0      # Item
        $scene = Scene_Item.new
      when 1,2,3,4  # Skill, equipment, rankings, status
        start_actor_selection
      when 5      # Save
        $scene = Scene_File.new(true, false, false)
      when 6      # End Game
        $scene = Scene_End.new
      end
    end
  end
 
  alias old_update_actor_selection update_actor_selection

  def update_actor_selection
    if Input.trigger?(Input::B)
      Sound.play_cancel
      end_actor_selection
    elsif Input.trigger?(Input::C)
      $game_party.last_actor_index = @status_window.index
      Sound.play_decision
      case @command_window.index
      when 1  # skill
        $scene = Scene_Skill.new(@status_window.index)
      when 2  # equipment
        $scene = Scene_Equip.new(@status_window.index)
      when 4  # status
        $scene = Scene_Status.new(@status_window.index)
      when 3 # weapons and ranks
        $scene = Scene_weapon_by_ranks.new(@status_window.index)
      end
    end
  end
  end
end


class Scene_Status < Scene_Base
    if Vocab::Show_in_Menu == true then

  alias old_return_scene return_scene

  def return_scene
    $scene = Scene_Menu.new(4)
  end
  end
end


class Scene_File < Scene_Base
   
  if Vocab::Show_in_Menu == true then

  alias old_return_scene return_scene

  def return_scene
    if @from_title
      $scene = Scene_Title.new
    elsif @from_event
      $scene = Scene_Map.new
    else
      $scene = Scene_Menu.new(5)
    end
  end
  end
end


class Scene_End < Scene_Base
   
  if Vocab::Show_in_Menu == true then

  alias old_return_scene return_scene

  def return_scene
    $scene = Scene_Menu.new(6)
  end
  end
end


Customization
# Customize: RANKS                                                           
# RANKS = [lowest to highest]                                               
# RANKS = ["None","Rookie","Master"]                                   
#                                                                             
# Customize: $exp_ranks                                     
# $exp_ranks = [0, exp needed for rank 1, exp for rank 2 not including exp needed for rank 1...]                 
#Example  $exp_ranks = [0,100,5000,10000]                                             
#                                                                             
# Customize: EXP_rate                                           
# regular experience multiplier:                             
# Ex: You kill Rat and win 13 exp, exp for ranks will be 13 * EXP_rate       
#      EXP_rate = number
#                                                                             
# Customize: $weapon_skills                               
# names of your skills in weapons; must be one word                           
# example: $weapon_skills = ["Swords","Bows","Staffs"]
#
#Customize: Rank_Up
#message for when rank goes up
#Rank_Up = "%s is a %s using %s." 
#%s - actor name; new rank; rank type
#Ex: Ralph(%s) is a Rookie (%s) using Swords (%s)
#
#Customize: Show_in_Menu
#Show_in_Menu = true or false
#true: rankings can be show in the Menu
#false: rankings are not shown in the menu
#and must be called with '$scene = Scene_weapon_by_ranks.new'
#
#Customize: Show_in_Menu
#word that shows up in the menu
# Example: Menu_Ranks = "Rankings"                                 

Compatibility
So far everything seems to work with all scripts.
Warn me if it isn't compatible.

Screenshot
http://img380.imageshack.us/img380/2294/weaponsbyranksnx6.th.png[/img]


Demo 1.0
http://rapidshare.com/files/131420640/E ... s.exe.html


Demo 1.1
http://www.zshare.net/download/15771759f47ebac3/


Installation
insert Above main and below Tagnote (2.0 +)

FAQ


Q: How to use the script?

A: Copy & paste in a new script page below material section and below Tagnote 2.0 or more and above main.


Credits


- me, for doing the script
- Queex for creating Tagnote - saved me a lot of trouble

Terms and Conditions


Credit me when using the script, don't make questions about what's already written in the configuration (I won't answer those)
Give credit to Queex too.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top