[XP] Blinking Characters

Started by mad.array, March 28, 2013, 06:30:32 am

Previous topic - Next topic

mad.array

Blinking Characters
Authors: mad.array
Version: 1.1
Type: Game_Character Add-On
Key Term: Environment Add-on



Introduction

A script that automatically checks all Game_Events/Game_Characters to see if they have a blinking sprite and makes said events blink. Options can be changed to change blink rate and to force eyes open/closed.


Features


  • Make people blink

  • Control how often they blink

  • Make certain events not blink at all or have their eyes closed or open for however long you like.




Screenshots
Since when do I do screenshots?


Demo

Scripty goodness below.


Script

Place above Main, but below default scripts. To make characters blink you will need a graphic named the same as the normal character, but with the Suffix _Blink. So for Aluxes/Arshes/Default guy you would need the following:

001-Fighter01.png # The regular graphic.
001-Fighter_Blink.png # The blinking graphic.
Spoiler: ShowHide

#==============================================================================
# ** Game_Character (part 4)
#------------------------------------------------------------------------------
#  This class deals with characters. It's used as a superclass for the
#  Game_Player and Game_Event classes.
#
#   This section covers the main body of the blinking.
#   The only things you should need to change are the blink states and the blink
#   frames. The frames decides a rough guide for how long the eyes should be open
#   for. The blink states decide how the eyes act.
#     -1 = No blinking graphic
#      0 = Forced no blinking
#      1 = Normal blink(Eyes open)
#      2 = Normal blink(Eyes closed)
#      3 = Forced eyes closed
#==============================================================================

class Game_Character
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
 
  attr_accessor :base_character_name      #Base character file
  attr_accessor :end_base                 #New base sprite at end of animation
  attr_accessor :eye_sprite               #Current Eye sprite
  attr_accessor :blink_state              #Blink boolean
  attr_accessor :blink_frames             #Blink frame interval (average)
  attr_accessor :blink_count              #Current blink count
  attr_accessor :close_count              #Close rnd
  attr_accessor :open_count               #Open rnd
 
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  alias extinit initialize
  def initialize
    extinit
    @base_character_name = @character_name
    @end_base = ""
    @base_eye_sprite = ""
    @base_eye_hue = 0
    @eye_sprite = @base_eye_sprite
    @blink_state = 1
    @blink_frames = 80
    @blink_count = 0
    @close_count = 0
    @open_count = 0
  end
 
 
=begin

=end
 
  alias blinkupdate update
  def update
    blinkupdate
    update_blink
  end
 
  def update_blink
    cnb = sprintf("Graphics/Characters/%s_Blink.png", @character_name)
    suff = FileTest.exist?(cnb)
    if suff == false && @blink_state < 2
      @blink_state = -1
      return
    end
    bs = sprintf("%s_Blink", @character_name)
    if @blink_state == 1
      @blink_count += 1
      if @blink_count >= @open_count
        @base_character_name = @character_name
        @blink_count = 0
        @blink_state = 2
        @character_name = bs
        @close_count = (6 * (rand + 0.5))
      end
    end
    if @blink_state == 2
      @blink_count += 1
      if @blink_count >= @close_count
        @blink_count = 0
        @blink_state = 1
        @character_name = @base_character_name
        @open_count = @blink_frames * (rand + 0.5)
      end
    end
    if @blink_state == 3
      bs = sprintf("%s_Blink", @base_character_name)
      @blink_count =0
      if @character_name != bs
        @character_name = bs
      end
    end
  end
 
  def blink_reset_base
    @base_character_name = @character_name
  end

  def blink_refresh(frames)
    @blink_count = 0
    @blink_frames = frames
  end
 
  def blink_set_state(state)
    @blink_state = state
    case state
      when -1, 0, 1
        @blink_count = 0
        @character_name = @base_character_name
      when 2, 3
        @blink_count = 0
        bs = sprintf("%s_Blink", @base_character_name)
        if FileTest.exist?(bs)
          p("Apparently found!")
          @character_name = bs
        end
      end
  end

 
end

class Interpreter
 
  alias command_322_blink command_322
  def command_322
    $game_player.blink_state = 1 if $game_player.blink_state == -1
    command_322_blink
  end
 
  def blink_refresh(eventid, frames)
    # Branch by parameter
    case eventid
    when -1  # player
      $game_player.blink_refresh(frames)
    when 0  # this event
      events = $game_map.events
      events[@event_id].blink_refresh(frames)
    else  # specific event
      events = $game_map.events
      events[eventid].blink_refresh(frames)
    end
  end
 
  def blink_set_state(eventid, state)
    # Branch by parameter
    case eventid
    when -1  # player
      $game_player.blink_set_state(state)
    when 0  # this event
      events = $game_map.events
      events[@event_id].blink_set_state(state)
    else  # specific event
      events = $game_map.events
      events[eventid].blink_set_state(state)
    end
  end
 
end




Instructions
Again I'm using my favourite Event Control system, the Move Route. The blinking will work by default but if you want to refine the system then call a script command. You now have two options:

'blink_refresh(frames)'

Use this to change how often the character/event blinks. There is a random factor involved so it won't be exact. By default, this is set to 80 frames (4 seconds), but feel free to change this to whatever you want.

'blink_set_state(state)'

There are technically five options for state, but you should only ever need to use two.

0 = Forced eyes open
3 = Forced eyes closed

So if you set up a Move Route for the player and had a script call with 'blink_set_state(3)' your player would be running around with their eyes wide shut until you changed it.


Compatibility

Aliases update in Game_Character, so will probably have conflicts with systems that alter the player graphic.


Credits and Thanks


  • Mine... all mine!




Author's Notes

For your convenience, here are some blinking sprites for the RTP charsets. Just place them in Graphics/Characters.
http://www.filedropper.com/blinking
"To walk at speed, manage or oversee..."

"RUN!"

KK20

As raised up by Shrimpses, there's some potential bugs with the script. Posting a general fix here in case others happen to use this script.

#==============================================================================
# ** Game_Character (part 4)
#------------------------------------------------------------------------------
#  This class deals with characters. It's used as a superclass for the
#  Game_Player and Game_Event classes.
#
#   This section covers the main body of the blinking.
#   The only things you should need to change are the blink states and the blink
#   frames. The frames decides a rough guide for how long the eyes should be open
#   for. The blink states decide how the eyes act.
#     -1 = No blinking graphic
#      0 = Forced no blinking
#      1 = Normal blink(Eyes open)
#      2 = Normal blink(Eyes closed)
#      3 = Forced eyes closed
#==============================================================================

class Game_Character
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
 
  attr_accessor :base_character_name      #Base character file
  attr_accessor :blink_state              #Blink boolean
  attr_accessor :blink_frames             #Blink frame interval (average)
  attr_accessor :blink_count              #Current blink count
  attr_accessor :close_count              #Close rnd
  attr_accessor :open_count               #Open rnd
 
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  alias extinit initialize
  def initialize
    extinit
    @base_character_name = @character_name
    @has_blink = (RPG::Cache.character("#{@character_name}_Blink", 0) && true rescue false)
    @blink_state = 1
    @blink_frames = 80
    @blink_count = 0
    @close_count = 0
    @open_count = 0
  end
 
  alias blinkupdate update
  def update
    blinkupdate
    if @base_character_name != @character_name.chomp('_Blink')
      @base_character_name = @character_name
      @blink_count = 0 if @blink_state == -1
      @blink_state = 1
      @has_blink = (RPG::Cache.character("#{@character_name}_Blink", 0) && true rescue false)
    end
    update_blink
  end
 
  def update_blink
    if !@has_blink && @blink_state < 2
      @blink_state = -1
      return
    end
    bs = sprintf("%s_Blink", @character_name)
    if @blink_state == 1
      @blink_count += 1
      if @blink_count >= @open_count
        @base_character_name = @character_name
        @blink_count = 0
        @blink_state = 2
        @character_name = bs
        @close_count = (6 * (rand + 0.5))
      end
    end
    if @blink_state == 2
      @blink_count += 1
      if @blink_count >= @close_count
        @blink_count = 0
        @blink_state = 1
        @character_name = @base_character_name
        @open_count = @blink_frames * (rand + 0.5)
      end
    end
    if @blink_state == 3
      bs = sprintf("%s_Blink", @base_character_name)
      @blink_count = 0
      if @character_name != bs
        @character_name = bs
      end
    end
  end
 
  def blink_reset_base
    @base_character_name = @character_name
  end

  def blink_refresh(frames)
    @blink_count = 0
    @blink_frames = frames
  end
 
  def blink_set_state(state)
    return unless state.between?(-1, 3)
    @blink_state = state unless (state >= 2 && !@has_blink)
    @blink_count = 0
    @character_name = @base_character_name if state <= 1
  end
end

class Interpreter
 
  alias command_322_blink command_322
  def command_322
    $game_player.blink_state = 1 if $game_player.blink_state == -1
    command_322_blink
  end
 
  def blink_refresh(eventid, frames)
    # Branch by parameter
    case eventid
    when -1  # player
      $game_player.blink_refresh(frames)
    when 0  # this event
      events = $game_map.events
      events[@event_id].blink_refresh(frames)
    else  # specific event
      events = $game_map.events
      events[eventid].blink_refresh(frames)
    end
  end
 
  def blink_set_state(eventid, state)
    # Branch by parameter
    case eventid
    when -1  # player
      $game_player.blink_set_state(state)
    when 0  # this event
      events = $game_map.events
      events[@event_id].blink_set_state(state)
    else  # specific event
      events = $game_map.events
      events[eventid].blink_set_state(state)
    end
  end
 
end





   


   
   


   
   

Other Projects
RPG Maker XP AceUpgrade RMXP to RMVXA performance!
XPA TilemapTilemap rewrite with many features, including custom resolution!



Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!