Main Menu
  • Welcome to The RPG Maker Resource Kit.

Colour Coded Items

Started by modern algebra, January 28, 2009, 02:48:13 AM

0 Members and 1 Guest are viewing this topic.

modern algebra

Colour Coded Items/Weapons/Armors
Version: 2.0
Author: modern algebra
Date: September 17, 2011

Version History




  • <Version 2.0> 2011.09.17 - More efficient, support for hex, and built-in capacity for some YEM scripts
  • <Version 1.0> 2009.01.27 - Original Release

Description



This script allows you to set a special colour to any item, weapon or armor in the party's possession (also works for skills). SO, in scenes like Item, Equip, or Skill, these items/weapons/armors/skills would be drawn in whatever colour you specify.

Features


  • Can set an individual colour for any item, weapon, or armor in the database
  • Can set it either by windowskin palette, through RGB, or by hex code
  • Easy configuration.

Screenshots



Instructions

See header of the script

Script




#==============================================================================
#  Colour Coded Items/Weapons/Armors/Skills
#  Version: 2.0
#  Author: modern algebra (rmrk.net)
#  Date: September 17, 2011
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Description:
#    This script allows you to set a special colour to any item, weapon or
#   armor in the party's possession. SO, in scenes like Item or Equip, these
#   items/weapons/armors would be drawn in whatever colour you specify
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Instructions:
#    Place this above Main and below Materials in the Script Editor (F11)

#   To set a colour to an item, put any of the following codes into the notes
#  box of the item, weapon or armour:
#
#      \color[x]
#      \colour[x]
#
#    where x is an integer from 0-31 : this will set it to the colour
#   that corresponds to the square in the Windowskin palette. Or you can use
#   the code:
#
#      \color[r, g, b]
#      \colour[r, g, b]
#
#    where r is red, g is green, and b is blue. All of them must be between
#   0 and 255. Any colour you want can be made out of a combination of these
#   colours. [0, 0, 0] is BLACK, and [255, 255, 255] is WHITE, [255, 0, 0] is
#   RED, and etc... If you use this, the best way is to find the exact shade
#   you want in a picture editor program like MS Paint, and then check the
#   RGB of that colour.
#
#    You can also use hex, like so:
#
#      \color[#RRGGBB]
#      \colour[#RRGGBB]
#
#    RR is red, GG is the green, and BB is the blue. It accepts values from
#   0 (00) to 255 (FF) for each element. For a guide to hex and a converter,
#   you can go to:
#      http://www.statman.info/conversions/hexadecimal.html
#==============================================================================

$imported = {} unless $imported
$imported["MAColourCodedItems2"] = true

#==============================================================================
# ** RPG::BaseItem
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    new method - ma_colour
#==============================================================================

class RPG::BaseItem
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * MA Colour
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def ma_colour
    if !@ma_colour
      if self.note[/\\(MA)?COLOU?R\s*\[\s*\#?([\dA-F]{6,6})\s*\]/i] != nil # HEX
        # Convert hex code to 3 element array
        @ma_colour = []
        $2.scan (/../) { |hex| @ma_colour << hex.to_i (16) }
    elsif self.note[/\\(MA)?COLOU?R\s*\[([,\d\s]*)\]/i] != nil
        note, args = $2, []
        # Compose array of colours
        while args.size < 3 && note.sub! (/(\d+)/) { "" } do args << $1.to_i end
        @ma_colour = case args.size
        when 0, 2 then -1   # Use normal_color
        when 1 then args[0] # Use text_color
        when 3 then args    # Make colour out of the array
        end
      else
        @ma_colour = -1
      end
  end
  return (@ma_colour != -1) ? @ma_colour : nil
  end
end

#==============================================================================
# ** Window Base
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    aliased method - normal_color, draw_item_name
#==============================================================================

class Window_Base
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Normal Color
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias ma_cci_normcol_5tc1 normal_color
  def normal_color (*args)
    # If drawing an item name from Draw Item Name
    if @ma_drawing_item != nil
      case @ma_drawing_item.ma_colour
      when Fixnum
        colour = text_color (@ma_drawing_item.ma_colour)
        return colour if colour.alpha > 0 # Only use if color is visible
      when Array
        return Color.new (*@ma_drawing_item.ma_colour)
      end
    end
    return ma_cci_normcol_5tc1 (*args)
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Draw Item Name
  #     item    : Item (skill, weapon, armor are also possible)
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias malb_coloritm_drwnam_5tx1 draw_item_name
  def draw_item_name(item, *args)
    @ma_drawing_item = item
    malb_coloritm_drwnam_5tx1 (item, *args) # Run Original Method
    @ma_drawing_item = nil
  end
end

#==============================================================================
#  YEM Item Overhaul Compatibility Patch
#==============================================================================

if $imported["ItemOverhaul"]

class Window_ItemData
  alias mayan_ioccipatch_drwname_7th1 draw_item_name
  def draw_item_name(*args)
    @ma_drawing_item = @item
    result = mayan_ioccipatch_drwname_7th1 (*args) # Run Original Method
    @ma_drawing_item = nil
    return result
  end
end

class Window_ItemList
  alias yflyma_ioccicomp_objnm_8yh2 draw_obj_name
  def draw_obj_name(obj, *args)
    @ma_drawing_item = obj
    yflyma_ioccicomp_objnm_8yh2 (obj, *args) # Run Original Method
    @ma_drawing_item = nil
  end
end

end

#==============================================================================
#  YEM Battle Engine Melody Compatibility Patch
#==============================================================================

if $imported["BattleEngineMelody"]
 
class Window_Item
  alias modyf_ioccocmpch_drwone_6gx4 draw_obj_name
  def draw_obj_name(obj, *args)
    @ma_drawing_item = obj
    modyf_ioccocmpch_drwone_6gx4 (obj, *args) # Run Original Method
    @ma_drawing_item = nil
  end
end

end

#==============================================================================
#  YEM Skill Overhaul Compatibility Patch
#==============================================================================

if $imported["SkillOverhaul"]
 
class Window_LearnSkill
  alias malb_cciyso_drwobjname_3fg1 draw_obj_name
  def draw_obj_name (obj, *args)
    @ma_drawing_item = obj
    malb_cciyso_drwobjname_3fg1 (obj, *args) # Run Original Method
    @ma_drawing_item = nil
  end
end

class Window_LearnData
  alias mayfly_colcodeitm_drwobjct_5th1 draw_obj_name
  def draw_obj_name (*args)
    @ma_drawing_item = @skill
    malb_cciyso_drwobjname_3fg1 (*args) # Run Original Method
    @ma_drawing_item = nil
  end
end

class Window_PassiveData
  alias yflma_socci_drwnm_6cx3 draw_obj_name
  def draw_obj_name (*args)
    @ma_drawing_item = @passive
    yflma_socci_drwnm_6cx3 (*args) # Run Original Method
    @ma_drawing_item = nil
  end
end
 
end


Credit




  • modern algebra

Thanks


  • sasofrass, for the request
  • Pacman, for making me ashamed of my past

Support



Please post here for the swiftest support

Known Compatibility Issues

Will not work with scripts that customize drawing item or skill names. It should work with YEM BEM, YEM Item Overhaul, and YEM Skill Overhaul however.

Revo

Wait a minute... I'm a bit confused. Where exactly do you put the \macolor[x]My apologies if this sounds stupid. Do you put it directly into the item's name..?

modern algebra

No, in the notes box - I should've specificied that - thanks for letting me know I haven't.

Revo

Ah, okay. Thanks. This is a pretty nice little add-on. Good job.

worale

Nice :D

I like the way you wrote this script.

modern algebra

Hey wora, good to see you again! :)

And thanks for the compliment. It's always fun to try and find ways to modify graphical elements of the game without either redrawing or replacement drawing them :)

worale

There are a lot of good scripts from you (and other scripters) here. I can't leave this place. >_>"

modern algebra


the_mantic

Great work, Modern. I've been here for maybe a week and I've come to recognize you for the scripting wizard you are. Mhmm. Very cool stuff. 

rpgmakerman

#9
Hello, I'd like to first say this is a great script and thank you for sharing it with us.

But do you know how to make it so it works with the shop scene too?

So when I Sell to a shop I see the different colored weapons/items etc...
It seems to show the colored name when I buy from shop but not when I sell.

I really need this for my game, thanks!

modern algebra

#10
Ermm, it should - in the default shop scene, the buy window uses the draw_item_name method and the sell window is a subclass of Window_Item and uses the same method as that.

Did you input the code correctly in the notebox for the items in question?

Otherwise, are you using another script which either modifies the shop scene or else affects the way items are drawn in any way?

rpgmakerman

Thanks for your response.

I did enter the code correctly... This is a bit strange.

I set the color to green...
The weapon color  is white when I see it in the "Sell Window" of a shop but when I  press the button to sell it, where you choose the quantity,  the color of the weapon changes back to green, so it only happens on that one window.

I'm using Yanfly's scripts, Item/Equipment overhaul, maybe this has something to do with it?

Thanks!


modern algebra

Yes. It definitely does, as would Battle Engine Melody. Add the following code into its own slot below the Item Overhaul script (and BEM, if you have it) but still somewhere above Main:


class Window_ItemData
  alias mayan_ioccipatch_drwname_7th1 draw_item_name
  def draw_item_name(*args)
    @ma_drawing_item = @item
    # Run Original Method
    result = mayan_ioccipatch_drwname_7th1 (*args)
    @ma_drawing_item = nil
    return result
  end
end

class Window_ItemList
  alias yflyma_ioccicomp_objnm_8yh2 draw_obj_name
  def draw_obj_name(obj, *args)
    @ma_drawing_item = obj
    # Run Original Method
    yflyma_ioccicomp_objnm_8yh2 (obj, *args)
    @ma_drawing_item = nil
  end
end

if Window_Item.method_defined? (:draw_obj_name)
 
class Window_Item
  alias modyf_ioccocmpch_drwone_6gx4 draw_obj_name
  def draw_obj_name(obj, *args)
    @ma_drawing_item = obj
    # Run Original Method
    modyf_ioccocmpch_drwone_6gx4 (obj, *args)
    @ma_drawing_item = nil
  end
end

end

rpgmakerman

@modern algebra, you're a genius!!!
It all works great now, Thank you so much!! :)

pacdiggity

Took a look at your code and noticed something odd in the REGEXP. Keeping in mind that I'm by far nowhere as experienced as you, at a glance I thought that this:
@ma_drawing_item.note[/\\MACOLOU*R\[([,\d\s]*?)\]/i]
should be this:
@ma_drawing_item.note[/\\MACOLOU?R\[([,\d\s]*?)\]/i]
And I figure that because I assume you put the asterisk there to suit both color and colour, whereas, to my knowledge, an asterisk denotes a character appearing once or more and a question mark denotes the character to appear either once or not at all.
"abc*" matches "abc", "abcc", "abccc", etc.
"abc?" matches "ab" or "abc".
But why am I telling you that, I'm sure it was either something missed by me or a simple overlooked mistake by you. I'm hoping for the former, and a lesson from you.
Alternatively, couldn't you also use
[/\\(MACOLOUR|MACOLOR)\[([,\d\s]*?)\]/i]
[/\\MACOL(OU|O)R\[([,\d\s]*?)\]/i]

Or am I being silly?
it's like a metaphor or something i don't know

modern algebra

#15
No, you're right that the ? is better than the *. I wrote the script a long time ago. However, you're wrong that the * means >= 1. It matches for zero or more. So /abc*/ matches ab, abc, abcc, abccc, etc. It's the + that would match only one or more. /abc+/ would only match abc, abcc, abccc, etc.

The question mark would have been better though.

And yes, both of the alternative formations you mention would work, though I generally wouldn't use them where it's just a case of a wildcard letter. Personally, I think some scripters overuse alternations, though I suppose it doesn't make much of a difference. There would be more ways to accomplish it as well. For instance: /abc{0, 1}/ would match ab or abc as well. But the ? would definitely have been the best to use in this case. I just didn't know much about RegExp when I wrote this script.

It was also bad practice to force it to redo the calculations every time. It would be far better just to have a lazy instantiation inside the item class itself.

pacdiggity

It's amazing that mistake hadn't been found yet. And I'll put that + and * ruling in my notes. I've taken up serious REGEXP, you see.
I'll return to my box now.
it's like a metaphor or something i don't know

modern algebra

Alright, rewrote the script to support hex and be more efficient.

rpgmakerman

#18
oh nice, :) do i still need that other little fix script you made, if i use this new rewritten one? Thanks!

digdarkevil

Cool But..Isnt That Already Possible by Doing This

EX: /c(10)LongSword/c(0)

modern algebra

Well, that code is actually \c[10]Long Sword\c[0] and yes, but it would only work in a message (unless you are using a script like my Global Text Codes, in which case it would work everywhere).

This script applies to other scenes also, however, so it would colour code the items or skills wherever they are drawn in the Menu scenes too.

digdarkevil