RMRK is retiring.
Server is paid up for the rest of 2026, but the forum may go after that. See here for more information. Please archive or save anything you would like to keep before 2027.
Main Menu
  • Welcome to The RPG Maker Resource Kit.

Rarity Assistance

Started by b14d3r11, December 18, 2009, 06:52:42 PM

0 Members and 1 Guest are viewing this topic.

b14d3r11

I downloaded a Script and i was wondering how to implement my own twist to it. It works 100% like i want it to except #======================================#
# RARITYNAME = "Rarity name here" # word you want to call the rarity/rating
#======================================#
ICONNAME = "low"
RARITYNAME = "Rating"

module RPG
  class Item
    def rarity
      case id
      #======================================#
      # BEGIN CONFIG
      #======================================#
      when 1 then return 1
      when 2,3 then return 3
      when 32 then return 5
      when 8 then return 2
      #======================================#
      # END CONFIG
      #======================================#
      end
      return 1
    end
  end
  class Weapon
    def rarity
      case id
      #======================================#
      # BEGIN CONFIG
      #======================================#
      when 1 then return 1
      when 2 then return 3
      when 32 then return 5
      when 8 then return 2
      #======================================#
      # END CONFIG
      #======================================#
      end
      return 1
    end
  end
  class Armor
    def rarity
      case id
      #======================================#
      # BEGIN CONFIG
      #======================================#
      when 1 then return 1
      when 2 then return 3
      when 32 then return 5
      when 8 then return 2
      #======================================#
      # END CONFIG
      #======================================#
      end
      return 1
    end
  end
end
class Window_Item < Window_Selectable
  def initialize
    super(0, 64, 640, 352)
    @column_max = 1
    refresh
    self.index = 0
    if $game_temp.in_battle
      self.y = 64
      self.height = 256
      self.back_opacity = 160
    end
  end
  def draw_item(index)
    item = @data[index]
    case item
    when RPG::Item
      number = $game_party.item_number(item.id)
    when RPG::Weapon
      number = $game_party.weapon_number(item.id)
    when RPG::Armor
      number = $game_party.armor_number(item.id)
    end
    if item.is_a?(RPG::Item) and
       $game_party.item_can_use?(item.id)
      self.contents.font.color = normal_color
    else
      self.contents.font.color = disabled_color
    end
    x = 4 + index % 1 * (288 + 32)
    y = index / 1 * 32
    rect = Rect.new(x, y, self.width / @column_max - 32, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    bitmap = RPG::Cache.icon(item.icon_name)
    opacity = self.contents.font.color == normal_color ? 255 : 128
    item.rarity.times do |i|
      src_rect = Rect.new(0, 0, 24, 24)
      self.contents.blt(300 + 32 * i + 16, y + 3, RPG::Cache.icon(ICONNAME.to_s), src_rect)
    end
    self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
    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 Window_ItemName < Window_Base
  def initialize
    super(0, 0, 320, 64)
    self.contents = Bitmap.new(width - 32, height - 32)
    refresh
  end
  def refresh
    self.contents.clear
    self.contents.font.color = system_color
    self.contents.draw_text(4, 0, 640, 32, "Item Name", 0)
  end
end
class Window_Rating < Window_Base
  def initialize
    super(320, 0, 320, 64)
    self.contents = Bitmap.new(width - 32, height - 32)
    refresh
  end
  def refresh
    self.contents.clear
    self.contents.font.color = system_color
    self.contents.draw_text(4, 0, 640, 32, RARITYNAME, 0)
  end
end
class Scene_Item
  def main
    @help_window = Window_Help.new
    @help_window.y = 416
    @xtrinfo = Window_ItemName.new
    @rare = Window_Rating.new
    @item_window = Window_Item.new
    @item_window.help_window = @help_window
    @target_window = Window_Target.new
    @target_window.visible = false
    @target_window.active = false
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
    Graphics.freeze
    @help_window.dispose
    @rare.dispose
    @xtrinfo.dispose
    @item_window.dispose
    @target_window.dispose
  end
end

That code works 100% fine i just want to make it so if the rarity is from 1-3 its "low" from 4-6 its "med" and from 7-9 its "high", i have all three icons in the folder i just dont know how to make it so that it changes the icon depending on what the rarity is, cause when i go to do it, it says rarity is undefined. Any assistance would be much appreciated. And from what i've learned
ICONNAME = if rarity < 4 then
ICONNAME = "low"
else if
rarity >3 && rarity <7 then
ICONNAME = "med"
else
ICONNAME = "high"
end
end

that works in terms of Syntax and everything, just doesnt work in the bigger script.

shaz

where have you put your script - have you repleced ICONNAME = "low" with what you've got in the second script?

I would do this in your draw_item script (I'm using a new variable icon_name, as ICONNAME in upper case usually signifies a constant that you don't want to change, and it's over the whole class, not a different value for each item - I'm not changing the original just in case it's used elsewhere):


icon_name = (item.rarity < 4 ? "low" : (item.rarity < 7 ? "med" : "high"))
item.rarity.times do |i|
  src_rect = Rect.new(0, 0, 24, 24)
  self.contents.blt(300 + 32 * i + 16, y + 3, RPG::Cache.icon(icon_name.to_s), src_rect)
end
Always remember you're unique.
Just like everybody else.

b14d3r11

Uh idk where thats supposed to go. and i tried in 3 or 4 places.

shaz

these two lines are exactly the same as two you've already got in the script:


item.rarity.times do |i|
  src_rect = Rect.new(0, 0, 24, 24)


Just search for that, and replace those 4 lines (those two, plus the two after them) with the 5 lines I provided.
Always remember you're unique.
Just like everybody else.

shaz

Actually, I just realised icon_name is also a property of item, so I'm going to redo that snippet of script, and use something other than icon_name, just so you and anyone else doesn't get confused between the two down the track.  The logic is exactly the same - I just call the variable something else.


rarity_icon = (item.rarity < 4 ? "low" : (item.rarity < 7 ? "med" : "high"))
item.rarity.times do |i|
  src_rect = Rect.new(0, 0, 24, 24)
  self.contents.blt(300 + 32 * i + 16, y + 3, RPG::Cache.icon(rarity_icon.to_s), src_rect)
end
Always remember you're unique.
Just like everybody else.

b14d3r11

i fixd it somehow, heres my code #======================================#
# RARITYNAME = "Rarity name here" # word you want to call the rarity/rating
#======================================#
RARITYNAME = "Rating"

module RPG
  class Item
    def rarity
      case id
      #======================================#
      # BEGIN CONFIG
      #======================================#
      when 1 then return 5
      when 2 then return 3
    when 3 then return 8
      when 32 then return 5
      when 8 then return 2
      #======================================#
      # END CONFIG
      #======================================#
      end
      return 1
    end
  end
  class Weapon
    def rarity
      case id
      #======================================#
      # BEGIN CONFIG
      #======================================#
      when 1 then return 1
      when 2 then return 3
      when 32 then return 5
      when 8 then return 2
      #======================================#
      # END CONFIG
      #======================================#
      end
      return 1
    end
  end
  class Armor
    def rarity
      case id
      #======================================#
      # BEGIN CONFIG
      #======================================#
      when 1 then return 1
      when 2 then return 3
      when 32 then return 5
      when 8 then return 2
      #======================================#
      # END CONFIG
      #======================================#
      end
      return 1
    end
  end
end
class Window_Item < Window_Selectable
  def initialize
    super(0, 64, 640, 352)
    @column_max = 1
    refresh
    self.index = 0
    if $game_temp.in_battle
      self.y = 64
      self.height = 256
      self.back_opacity = 160
    end
  end
  def draw_item(index)
    item = @data[index]
    case item
    when RPG::Item
      number = $game_party.item_number(item.id)
    when RPG::Weapon
      number = $game_party.weapon_number(item.id)
    when RPG::Armor
      number = $game_party.armor_number(item.id)
    end
    if item.is_a?(RPG::Item) and
       $game_party.item_can_use?(item.id)
      self.contents.font.color = normal_color
    else
      self.contents.font.color = disabled_color
    end
    x = 4 + index % 1 * (288 + 32)
    y = index / 1 * 32
    rect = Rect.new(x, y, self.width / @column_max - 32, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    bitmap = RPG::Cache.icon(item.icon_name)
    opacity = self.contents.font.color == normal_color ? 255 : 128
icon_name = (item.rarity < 4 ? "low" : (item.rarity < 7 ? "med" : "high"))
    item.rarity.times do |i|
      src_rect = Rect.new(0, 0, 24, 24)
      self.contents.blt(300 + 32 * i + 16, y + 3, RPG::Cache.icon(icon_name.to_s), src_rect)
    end
    self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
    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 Window_ItemName < Window_Base
  def initialize
    super(0, 0, 320, 64)
    self.contents = Bitmap.new(width - 32, height - 32)
    refresh
  end
  def refresh
    self.contents.clear
    self.contents.font.color = system_color
    self.contents.draw_text(4, 0, 640, 32, "Item Name", 0)
  end
end
class Window_Rating < Window_Base
  def initialize
    super(320, 0, 320, 64)
    self.contents = Bitmap.new(width - 32, height - 32)
    refresh
  end
  def refresh
    self.contents.clear
    self.contents.font.color = system_color
    self.contents.draw_text(4, 0, 640, 32, RARITYNAME, 0)
  end
end
class Scene_Item
  def main
    @help_window = Window_Help.new
    @help_window.y = 416
    @xtrinfo = Window_ItemName.new
    @rare = Window_Rating.new
    @item_window = Window_Item.new
    @item_window.help_window = @help_window
    @target_window = Window_Target.new
    @target_window.visible = false
    @target_window.active = false
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
    Graphics.freeze
    @help_window.dispose
    @rare.dispose
    @xtrinfo.dispose
    @item_window.dispose
    @target_window.dispose
  end
end

shaz

Always remember you're unique.
Just like everybody else.

b14d3r11

hehe, now that it works wanna help with something else?

shaz

lol - post it (in a new topic) and we'll see how difficult it is...  if I can't figure it out in the time available, I'm sure someone else will stop by before long.
Always remember you're unique.
Just like everybody else.