Custom Bushes

This simple script allows changing how the "bush" effect is displayed in both the player and events. It's very easy to use, paste it above the script Main and follow the instructions I'll give below.

Author: Wecoc
First Release: September 2016
Last Version: October 2016

Terms of use
- Giving credits (Wecoc) for using this script is optional, but appreciated.
- You can repost this code.
- You can edit this code freely, and distribute the edits as well.
- This code can be used on commercial games.

Ruby:
#==============================================================================
# ** Custom Bush v1.2
#------------------------------------------------------------------------------
#  Author: Wecoc (credits are optional)
#==============================================================================

module Custom_Bush
  DEPTH = 12                    # Default depth
  COLOR = Color.new(0, 0, 0, 0) # Default color
  OPACITY = 160                 # Default opacity
  TEMPLATE = ''                 # Template
end

#==============================================================================
# ** Game_Character
#==============================================================================

class Game_Character
 
  attr_writer  :bush_depth
 
  attr_accessor :bush_color
  attr_accessor :bush_opacity
  attr_accessor :bush_template
 
  alias custom_bush_ini initialize unless $@
  def initialize
    custom_bush_ini
    @bush_depth = Custom_Bush::DEPTH
    @bush_color = Custom_Bush::COLOR
    @bush_opacity = Custom_Bush::OPACITY
    @bush_template = Custom_Bush::TEMPLATE
  end
 
  def bush_depth
    return 0 if @tile_id > 0 or @always_on_top
    if @jump_count == 0 and $game_map.bush?(@x, @y)
      return @bush_depth
    else
      return 0
    end
  end
end

#==============================================================================
# ** Sprite_Character
#==============================================================================

class Sprite_Character < RPG::Sprite
 
  attr_accessor :bush_color
  attr_accessor :bush_opacity
  attr_accessor :bush_template
 
  def initialize(viewport, character = nil)
    super(viewport)
    @character = character
    @bush_depth = 0
    @bush_color = Custom_Bush::COLOR
    @bush_opacity = Custom_Bush::OPACITY
    @bush_template = Custom_Bush::TEMPLATE
    update
  end
 
  def bush_depth
    @bush_depth
  end
 
  def bush_depth=(bush_depth)
    @bush_depth = bush_depth
  end
 
  def refresh_bush
    return if @bush_depth == 0
    bush_depth = @bush_depth
    if @template_bitmap != nil
      bush_depth += @template_bitmap.height / 2
    end
    for iy in 0...bush_depth
      for ix in 0...bitmap.width
        for dy in 0..4
          x = ix
          y = (@ch * dy) - bush_depth + iy
          bitmap_color = self.bitmap.get_pixel(x, y)
          if @template_bitmap != nil && iy < @template_bitmap.height
            tx = ix % (bitmap.width / 4)
            tx = tx % @template_bitmap.width
            ty = iy
            template_color = @template_bitmap.get_pixel(tx, ty)
            next if template_color.alpha == 0
            next if template_color == Color.new(0,0,0)
          end
          next if bitmap_color.alpha == 0
          r = bitmap_color.red
          g = bitmap_color.green
          b = bitmap_color.blue
          bc = @bush_color
          r = (r * (255 - bc.alpha) + (bc.red  * bc.alpha)) / 255
          g = (g * (255 - bc.alpha) + (bc.green * bc.alpha)) / 255
          b = (b * (255 - bc.alpha) + (bc.blue  * bc.alpha)) / 255
          a = (bitmap_color.alpha * @bush_opacity) / 255
          self.bitmap.set_pixel(x, y, Color.new(r,g,b,a))
        end
      end
    end
  end
 
  def update
    super
    if @bush_template != @character.bush_template or @template_bitmap.nil?
      bush_template = @character.bush_template
      if bush_template != ''
        @template_bitmap = RPG::Cache.picture(bush_template) rescue nil
      else
        @template_bitmap = nil
      end
    end
    if @tile_id != @character.tile_id or
      @character_name != @character.character_name or
      @character_hue != @character.character_hue or
      @bush_depth != @character.bush_depth or
      @bush_color != @character.bush_color or
      @bush_opacity != @character.bush_opacity or
      @bush_template != @character.bush_template
      @tile_id = @character.tile_id
      @character_name = @character.character_name
      @character_hue = @character.character_hue
      if @tile_id >= 384
        self.bitmap = RPG::Cache.tile($game_map.tileset_name,
          @tile_id, @character.character_hue).clone
        self.src_rect.set(0, 0, 32, 32)
        self.ox = 16
        self.oy = 32
      else
        self.bitmap = RPG::Cache.character(@character.character_name,
          @character.character_hue).clone
        @cw = bitmap.width / 4
        @ch = bitmap.height / 4
        self.ox = @cw / 2
        self.oy = @ch
        self.bush_depth = @character.bush_depth
        self.bush_color = @character.bush_color
        self.bush_opacity = @character.bush_opacity
        self.bush_template = @character.bush_template
        refresh_bush
      end
    end
    self.visible = (not @character.transparent)
    if @tile_id == 0
      sx = @character.pattern * @cw
      sy = (@character.direction - 2) / 2 * @ch
      self.src_rect.set(sx, sy, @cw, @ch)
    end
    self.x = @character.screen_x
    self.y = @character.screen_y
    self.z = @character.screen_z(@ch)
    self.opacity = @character.opacity
    self.blend_type = @character.blend_type
    if @character.animation_id != 0
      animation = $data_animations[@character.animation_id]
      animation(animation, true)
      @character.animation_id = 0
    end
  end
end

Instructions
On the very beginning of the code you can change the default bush depth, color and opacity. You can also define Picture as a template.

You can change that from an event as well, here's how you would change the bush depth on the player or a certain event:
$game_player.bush_depth = VALUE
$game_map.events[1].bush_depth = VALUE

By default it's 12, if you change it to 0 that would mean the bush effect would never effect that event.

Similarly, this changes the color of the sprite part inside the bush. Eatch RGBA value goes from 0 to 255.
$game_player.bush_color = Color.new(R, G, B, A)
By default on XP only the opacity is changed, but changing the color is a nice touch in my opinion.

To change the opacity use this:
$game_player.bush_opacity = VALUE

Finally, you can define a template like this, and using a width higher than the character's will work like an animated template, like this.
$game_player.bush_template = 'PICTURE NAME'

Spoiler: Screen
bush_muestra.png

Here I defined that second template example on all those events and the player. I also changed the opacity to 0 and the depth on some of the events.

I hope you like it :ahappy:
I am liking all the scripts you've been releasing for XP.
I'm trying to have a mine cart event and have a player ride in it. Can I use this bush effect to hide half of the player's body? I'm not seeing any option to give an event a bush effect to hide the player's body and only show the head by normal means. If I can use this, how would I go about doing that? Where would I plug the code in, etc? I tried adding the plugin and then copying the code into the NOTE part of the event, the map itself, a plugin command in the event, and a script command in the event, and I couldn't seem to get it to work. Please advise!

EDIT: Just noticed this may be for a different version. I am using MV.

Original thread: https://forums.rpgmakerweb.com/threads/custom-bushes.138663/