Author Topic: [XP] Blinking Characters  (Read 3057 times)

Offline mad.array

  • Trained Member
  • *
  • Posts: 26
  • LV: 7
  • Gender: Male
  • Homeless Dev
    • View Profile
[XP] Blinking Characters
« on: March 28, 2013, 01:30:32 PM »
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.
(click to show/hide)

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!"

Offline KK20

  • Master Scripter Fixer
  • Global Moderator
  • Guardian of Chaos
  • ****
  • Posts: 3128
  • LV: 378
  • Gender: Male
  • Choco Octo <3
    • View Profile
Re: [XP] Blinking Characters
« Reply #1 on: April 07, 2018, 09:43:11 AM »
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.
Code: [Select]
#==============================================================================
# ** 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!


NNID: KK20-CP
Discord: KK20 Tyler#8901

Join the CP Discord Server!