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.

Level Requirements - Display Variable?

Alright, I am getting frustrated with this and so I would like to ask for help. I don't know how I would take this piece and use it to display a requirement on a menu screen.

Here is the level requirements:
Code:
#==============================================================================

#   Equipment Requirement System v2.10

#------------------------------------------------------------------------------

#   Created By: NAMKCOR

#   Created for the Websites: Chaos Project, RPG Maker Resource Kit

#                                        (www.chaosproject.co.nr; [url=http://www.rmrk.net)]http://www.rmrk.net)[/url]

#   If this script is hosted on any other website, then it is stolen,

#   please contact me at the address given below

#   Requested by: SirMagus (RMRK)

#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=

# - code reviewed, optimized and integrated into Tons of Add-ons by Blizzard

# - this add-on is part of Tons of Add-ons with full permission of the original

#   author(s)

#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=

#   If you find any Bugs/Incompatability issues with this script, please

#   contact me at the following e-mail address: [email=Rockman922@aol.com]Rockman922@aol.com[/email], and 

#   please be descriptive with your e-mail subject, as I delete spam on sight.

#------------------------------------------------------------------------------

#   Function:

#    sets prerequisites for armor and weapons, based on level and statistics

#    i.e. they are unequippable until the requirements are met

#    like in Diablo II

#   

#   Compatability:

#    most likely compatible with SDK (untested)

#    no known issues at the moment

#   

#   Instructions to modify:

#    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

#   

#   Instructions for use:

#    simply fill in the case sets instructed and the script will do the rest

#   

#------------------------------------------------------------------------------

#   Version History:

#   1.0 - completed system

#   2.0 - Major overhaul of the code, easier to configure, more efficient

#   2.1 - more efficient code (thanks for the help Blizz)

#==============================================================================

 

module NAMKCOR

 

  #============================================================================

  # to configure weapons' requirements you simply need to add a "when"

  # to the case of either weapons or armors, and then fill in the array

  # of requirements in the proper order

  #----------------------------------------------------------------------------

  # template:

  #   when (id) return [(level), (str), (dex), (agi), (int)]

  #============================================================================

  def self.ers_config(item)

    # weapon configuration

    if item.is_a?(RPG::Weapon)

      case item.id

      # START Weapon Configuration

      when 1 then return [1,0,0,0,0]

      when 2 then return [1,0,0,0,0]

      # END Weapon Configuration

      end

    elsif item.is_a?(RPG::Armor)

      case item.id

      # START Armor Configuration

      when 2 then return [1,0,0,0,0]

      # END Armor Configuration

      end

    end

    return [1,0,0,0,0]

  end

 

end

  

#==============================================================================

# DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING

#==============================================================================

 

class Scene_Equip

 

  alias update_item_ers_later update_item

  def update_item

    if $game_system.EQUIPMENT_REQUIREMENT

      itemstats = NAMKCOR.ers_config(@item_window.item)

      $game_variables[494] = itemstats[0]

      if Input.trigger?(Input::C) && (@actor.level < itemstats[0] ||

          @actor.str < itemstats[1] || @actor.dex < itemstats[2] ||

          @actor.agi < itemstats[3] || @actor.int < itemstats[4])

        $game_system.se_play($data_system.buzzer_se) 

        return 

      end

    end

    update_item_ers_later

  end

  

end

And here is code displaying the level requirement, but I have no idea how I can use it in my own equip menu to display the level requirement where I want it.
Code:
#-------------------------------------------------------------------------------

# Scene_Equip: Has : Equip Left/Item, Scene_Equip

#-------------------------------------------------------------------------------

class Window_EquipLeft < Window_Base

  def initialize(actor)

    super(0, 152, 272, 328)

    self.contents = Bitmap.new(width - 32, height - 32)

    self.contents.font.name = $fontface

    self.contents.font.size = $fontsize

    @actor = actor

    refresh

  end

  def refresh

    self.contents.clear

    draw_actor_name(@actor, 4, 0)

    draw_actor_level(@actor, 160, 0)

    draw_actor_hp(@actor, 4, 49)

    draw_actor_sp(@actor, 4, 74)

    draw_actor_graphic(@actor, 185, 110)

    draw_actor_parameter(@actor, 4, 128, 0)

    draw_actor_parameter(@actor, 4, 148, 1)

    draw_actor_parameter(@actor, 4, 168, 2)

    draw_actor_parameter(@actor, 4, 188, 3)

    draw_actor_parameter(@actor, 4, 208, 4)

    draw_actor_parameter(@actor, 4, 228, 5)

    draw_actor_parameter(@actor, 4, 248, 6)

    if @new_atk != nil

      self.contents.font.color = system_color

      self.contents.draw_text(160, 128, 40, 32, " ---", 1)

      self.contents.font.color = normal_color

      self.contents.draw_text(200, 128, 36, 32, @new_atk.to_s, 2)

    end

    if @new_pdef != nil

      self.contents.font.color = system_color

      self.contents.draw_text(160, 148, 40, 32, " ---", 1)

      self.contents.font.color = normal_color

      self.contents.draw_text(200, 148, 36, 32, @new_pdef.to_s, 2)

    end

    if @new_mdef != nil

      self.contents.font.color = system_color

      self.contents.draw_text(160, 168, 40, 32, " ---", 1)

      self.contents.font.color = normal_color

      self.contents.draw_text(200, 168, 36, 32, @new_mdef.to_s, 2)

    end

    if @new_str != nil

      self.contents.font.color = system_color

      self.contents.draw_text(160, 188, 40, 32, " ---", 1)

      self.contents.font.color = normal_color

      self.contents.draw_text(200, 188, 36, 32, @new_str.to_s, 2)

    end

    if @new_dex != nil

      self.contents.font.color = system_color

      self.contents.draw_text(160, 208, 40, 32, " ---", 1)

      self.contents.font.color = normal_color

      self.contents.draw_text(200, 208, 36, 32, @new_dex.to_s, 2)

    end

    if @new_agi != nil

      self.contents.font.color = system_color

      self.contents.draw_text(160, 228, 40, 32, " ---", 1)

      self.contents.font.color = normal_color

      self.contents.draw_text(200, 228, 36, 32, @new_agi.to_s, 2)

    end

    if @new_int != nil

      self.contents.font.color = system_color

      self.contents.draw_text(160, 248, 40, 32, " ---", 1)

      self.contents.font.color = normal_color

      self.contents.draw_text(200, 248, 36, 32, @new_int.to_s, 2)

    end

  end

  def set_new_parameters(new_atk, new_pdef, new_mdef, new_str, new_dex,

    new_agi, new_int)

    if @new_atk != new_atk or @new_pdef != new_pdef or @new_mdef != new_mdef or

      @new_str != new_str or @new_dex != new_dex or @new_agi != new_agi or

      @new_int != new_int

      @new_atk = new_atk

      @new_pdef = new_pdef

      @new_mdef = new_mdef

      @new_str = new_str

      @new_dex = new_dex

      @new_agi = new_agi

      @new_int = new_int

      refresh

    end

  end

end

 

class Window_EquipItem < Window_Selectable

  def initialize(actor, equip_type)

    super(272, 256, 368, 224)

    @actor = actor

    @equip_type = equip_type

    @column_max = 1

    refresh

    self.active = false

    self.index = -1

  end

  def draw_item(index)

    item = @data[index]

    x = 4

    y = index * 32

    case item

    when RPG::Weapon

      number = $game_party.weapon_number(item.id)

    when RPG::Armor

      number = $game_party.armor_number(item.id)

    end

    bitmap = RPG::Cache.icon(item.icon_name)

    self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24))

    self.contents.font.color = normal_color

    self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)

    self.contents.draw_text(x + 240, y, 16, 32, ":", 1)

    self.contents.draw_text(x + 256, y, 24, 32, number.to_s, 2)

  end

end

 

 

class Scene_Equip

  alias older_main main

  def main

    @wrequirements = Window_DisplayRequirements.new

    older_main

    @wrequirements.dispose

  end

  def refresh

    @wrequirements.clear

    @item_window1.visible = (@right_window.index == 0)

    @item_window2.visible = (@right_window.index == 1)

    @item_window3.visible = (@right_window.index == 2)

    @item_window4.visible = (@right_window.index == 3)

    @item_window5.visible = (@right_window.index == 4)

    item1 = @right_window.item

    case @right_window.index

    when 0

      @item_window = @item_window1

    when 1

      @item_window = @item_window2

    when 2

      @item_window = @item_window3

    when 3

      @item_window = @item_window4

    when 4

      @item_window = @item_window5

    end

    if @right_window.active

      @left_window.set_new_parameters(nil, nil, nil, nil, nil, nil, nil)

    end

    if @item_window.active

      item2 = @item_window.item

      last_hp = @actor.hp

      last_sp = @actor.sp

      @actor.equip(@right_window.index, item2 == nil ? 0 : item2.id)

      new_atk = @actor.atk

      new_pdef = @actor.pdef

      new_mdef = @actor.mdef

      new_str = @actor.str

      new_dex = @actor.dex

      new_agi = @actor.agi

      new_int = @actor.int

      @actor.equip(@right_window.index, item1 == nil ? 0 : item1.id)

      @actor.hp = last_hp

      @actor.sp = last_sp

      @left_window.set_new_parameters(new_atk, new_pdef, new_mdef, new_str,

                                      new_dex, new_agi, new_int)

    end

  end

  alias update_item_old update_item

  def update_item

    item2 = @item_window.item

    @wrequirements.refresh(NAMKCOR.ers_config(@item_window.item))                                   

    update_item_old

  end

end

So, that last part is its own scene_equip...how can I make it so I can display the level requirement in my own menu.

I need to put it in this code, here:
Code:
def refresh(item1 = nil, item2 = nil)

    self.contents.clear

    words = [$data_system.words.atk, $data_system.words.pdef,

             $data_system.words.mdef, $data_system.words.str,

             $data_system.words.int, $data_system.words.dex,

             $data_system.words.agi, Zer0_CMS::Evasion_Word, "Lvl Req."]

    stats = [@actor.base_atk, @actor.base_pdef, @actor.base_mdef, @actor.base_str,

             @actor.base_int, @actor.base_dex, @actor.base_agi, @actor.base_eva]

    stats.each_index {|i|

      self.contents.font.color = system_color

      self.contents.draw_text(4, i*15, 160, 15, words[i])

      self.contents.font.color = normal_color

      self.contents.draw_text(0, i*15, 110, 15, stats[i].to_s, 2)}

    values = []

    if item1 != nil && item2 != nil 

      atk = 0

      if item1.is_a?(RPG::Weapon) && item2.is_a?(RPG::Weapon)

        atk = item2.atk - item1.atk

      end

      pdef = item2.pdef - item1.pdef

      mdef = item2.mdef - item1.mdef

      str_p = item2.str_plus - item1.str_plus

      int_p = item2.int_plus - item1.int_plus

      dex_p = item2.dex_plus - item1.dex_plus

      agi_p = item2.agi_plus - item1.agi_plus

      eva = item1.is_a?(RPG::Armor) ? item2.eva - item1.eva : 0

      last_hp = @actor.hp

      last_sp = @actor.sp

      values = [atk, pdef, mdef, str_p, int_p, dex_p, agi_p, eva]

    elsif item1 != nil && item2 == nil

      values = [item1.is_a?(RPG::Weapon) ? -item1.atk : 0, -item1.pdef, -item1.mdef,

                -item1.str_plus, -item1.int_plus, -item1.dex_plus, -item1.agi_plus, 

                item1.is_a?(RPG::Armor) ? -item1.eva : 0]

    elsif item1 == nil && item2 != nil

      values = [item2.is_a?(RPG::Weapon) ? item2.atk : 0, item2.pdef, item2.mdef,

                item2.str_plus, item2.int_plus, item2.dex_plus, item2.agi_plus, 

                item2.is_a?(RPG::Armor) ? item2.eva : 0]   

    end

    values.each_index {|i|

      if values[i] > 0 

        self.contents.font.color = Zer0_CMS::Plus_Color

        self.contents.draw_text(0, i*15, 160, 15, "+#{values[i]}", 2)

      elsif values[i] < 0

        self.contents.font.color = Zer0_CMS::Minus_Color

        self.contents.draw_text(0, i*15, 160, 15, "#{values[i]}", 2)

      end

    }

  end
 
Code:
itemstats = NAMKCOR.ers_config(@item_window.item)

self.contents.draw_text(x, y, 110, 15, stats[0].to_s)   # level

self.contents.draw_text(x, y, 110, 15, stats[1].to_s)    # str

self.contents.draw_text(x, y, 110, 15, stats[2].to_s)    #dex

self.contents.draw_text(x, y, 110, 15, stats[3].to_s)    #agi

self.contents.draw_text(x, y, 110, 15, stats[4].to_s)    #int

Edit the x and y values accordingly.
 

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