The RPG Maker Resource Kit

RMRK RPG Maker Creation => VX => VX Scripts Database => Topic started by: modern algebra on January 28, 2009, 02:48:13 AM

Title: Colour Coded Items
Post by: modern algebra on January 28, 2009, 02:48:13 AM
Colour Coded Items/Weapons/Armors
Version: 2.0
Author: modern algebra
Date: September 17, 2011

Version History



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


Screenshots

(https://rmrk.net/proxy.php?request=http%3A%2F%2Fimg132.imageshack.us%2Fimg132%2F9739%2Fitemcolourcodesee7.png&hash=df3c5643fcb029b8f7152abf8218c0c80ccc25e0)

Instructions

See header of the script

Script


Code: [Select]
#==============================================================================
#  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



Thanks


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.
Title: Re: Colour Coded Items
Post by: Revo on January 28, 2009, 03:08:10 AM
Wait a minute... I'm a bit confused. Where exactly do you put the
Code: [Select]
\macolor[x]
My apologies if this sounds stupid. Do you put it directly into the item's name..?
Title: Re: Colour Coded Items
Post by: modern algebra on January 28, 2009, 04:37:39 AM
No, in the notes box - I should've specificied that - thanks for letting me know I haven't.
Title: Re: Colour Coded Items
Post by: Revo on January 28, 2009, 04:51:18 AM
Ah, okay. Thanks. This is a pretty nice little add-on. Good job.
Title: Re: Colour Coded Items
Post by: worale on February 18, 2009, 01:35:10 AM
Nice :D

I like the way you wrote this script.
Title: Re: Colour Coded Items
Post by: modern algebra on February 18, 2009, 02:18:39 AM
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 :)
Title: Re: Colour Coded Items
Post by: worale on February 18, 2009, 02:18:03 PM
There are a lot of good scripts from you (and other scripters) here. I can't leave this place. >_>"
Title: Re: Colour Coded Items
Post by: modern algebra on February 18, 2009, 04:50:36 PM
 :lol:
Title: Re: Colour Coded Items
Post by: the_mantic on February 18, 2009, 11:12:49 PM
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. 
Title: Re: Colour Coded Items
Post by: rpgmakerman on September 17, 2011, 12:43:56 AM
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!
Title: Re: Colour Coded Items
Post by: modern algebra on September 17, 2011, 01:18:36 AM
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?
Title: Re: Colour Coded Items
Post by: rpgmakerman on September 17, 2011, 01:49:31 AM
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!

Title: Re: Colour Coded Items
Post by: modern algebra on September 17, 2011, 02:34:55 AM
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:

Code: [Select]
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
Title: Re: Colour Coded Items
Post by: rpgmakerman on September 17, 2011, 02:45:33 AM
@modern algebra, you're a genius!!!
It all works great now, Thank you so much!! :)
Title: Re: Colour Coded Items
Post by: pacdiggity on September 17, 2011, 11:55:17 AM
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:
Code: [Select]
@ma_drawing_item.note[/\\MACOLOU*R\[([,\d\s]*?)\]/i]
should be this:
Code: [Select]
@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
Code: [Select]
[/\\(MACOLOUR|MACOLOR)\[([,\d\s]*?)\]/i]
[/\\MACOL(OU|O)R\[([,\d\s]*?)\]/i]
Or am I being silly?
Title: Re: Colour Coded Items
Post by: modern algebra on September 17, 2011, 12:43:55 PM
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.
Title: Re: Colour Coded Items
Post by: pacdiggity on September 17, 2011, 01:00:13 PM
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.
Title: Re: Colour Coded Items
Post by: modern algebra on September 17, 2011, 02:36:10 PM
Alright, rewrote the script to support hex and be more efficient.
Title: Re: Colour Coded Items
Post by: rpgmakerman on September 18, 2011, 01:15:21 AM
oh nice, :) do i still need that other little fix script you made, if i use this new rewritten one? Thanks!
Title: Re: Colour Coded Items
Post by: digdarkevil on November 17, 2011, 03:23:43 PM
Cool But..Isnt That Already Possible by Doing This

EX: /c(10)LongSword/c(0)
Title: Re: Colour Coded Items
Post by: modern algebra on November 17, 2011, 10:23:46 PM
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.
Title: Re: Colour Coded Items
Post by: digdarkevil on November 18, 2011, 01:22:09 AM
Oh..
Ok then