"Inspect" Event Animation
Authors: Jaiden, KK20
Version: 1.1
Type: Event Feature
Key Term: Environment Add-on
IntroductionDo you want to indicate that an event can be interacted with using a nifty animation? This is the script for you! Similar to how most games have some sort of a "press to interact" indicator, this script displays an animation when the player is facing events you've marked for "inspection".
Features- Easy to select which event / event page to display on
- Animation displayed is customizable
- Should be reasonably compatible with most scripts
ScreenshotsGif example using a custom animation:
Demo(N/A)
Script#==============================================================================
# Inspect Event
# by Jaiden, KK20
# Version 1.1
# September 2018
#==============================================================================
# Checks if an event is flagged for "inspection" and displays an
# animation above the player indicating it can be interacted with.
# -----
# This script aliases methods in the following classes:
# * Game_Character
# * Game_Event
# * Game_Map
# * Sprite_Character
# It may not be compatible with other scripts that have heavily
# modified these classes
#==============================================================================
# HOW TO USE THIS SCRIPT
# -----
# Super easy! Just create a comment with the text \inspect_event in the page of
# an event that you want to have display an animaton over the player when
# they are facing it. Then, set the animation ID below.
#==============================================================================
module InspectEvent
#--------------------------------------------------------------------------
# Animation ID
#--------------------------------------------------------------------------
# Set this value to the ID in your animation database that you want
# to display to indicate that an event can be inspected
EVENT_ANIMATION_ID = 98
#--------------------------------------------------------------------------
end
#==============================================================================
# END CONFIGURATION / DOCUMENTATION
#==============================================================================
#==============================================================================
# ** Game_Character
#==============================================================================
class Game_Character
#--------------------------------------------------------------------------
# * Public Instance Variables
# inspect_event - flags an event for interation
# animation_loop_id - id for a looped animation
#--------------------------------------------------------------------------
attr_accessor :inspect_event
attr_accessor :animation_loop_id
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
alias inspect_event_initialize initialize
def initialize
inspect_event_initialize
# Flag to determine if an event can be inspected
@inspect_event = false
# ID for looped animations
@animation_loop_id = 0
end
end
#==============================================================================
# ** Game_Event
#==============================================================================
class Game_Event
alias inspect_event_refresh refresh
def refresh
# Call original
inspect_event_refresh
# Initialize flag
@inspect_event = false
events_changed = false
# Check each list item for a comment
return if @list.nil?
@list.each do |cmd|
# Check if it's a comment
if cmd.code == 108
# Check if the comment contains the string "\inspect_event"
if cmd.parameters[0] == "\\inspect_event"
# Flag it
@inspect_event = true
# Indicate that events were changed
events_changed = true
end
else
# Next list item
next
end
end
# If at least one event was written to be inspected, refresh the map
if events_changed
# Indicate map needs refresh
$game_map.need_refresh = true
events_changed = false
end
end
#--------------------------------------------------------------------------
# * Check if player is adjacent to and facing an event
#--------------------------------------------------------------------------
def player_facing?
case $game_player.direction
when 2
self.y == $game_player.y + 1 && self.x == $game_player.x
when 4
self.x == $game_player.x - 1 && self.y == $game_player.y
when 6
self.x == $game_player.x + 1 && self.y == $game_player.y
when 8
self.y == $game_player.y - 1 && self.x == $game_player.x
end
end
end
#==============================================================================
# ** Game_Map
#==============================================================================
class Game_Map
#--------------------------------------------------------------------------
# * Setup
# map_id : map ID
#--------------------------------------------------------------------------
alias inspect_event_map_setup setup
def setup(map_id)
inspect_event_map_setup(map_id)
# Initialize array that contains IDs of events with flag
@inspectable_events = []
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
alias inspect_event_map_refresh refresh
def refresh
# Call original
inspect_event_map_refresh
# Initialize array that contains IDs of events with flag
@inspectable_events = []
# Reset animation
$game_player.animation_loop_id = 0
@player_interacted_event = nil
# Put IDs in array for events flagged for inspection
for event in @events.values
next unless event.inspect_event
@inspectable_events << event.id
end
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
alias inspect_event_map_update update
def update
# Call original
inspect_event_map_update
# Call animation method
inspect_event_anim
end
#--------------------------------------------------------------------------
# * Inspect Event Animation
#--------------------------------------------------------------------------
def inspect_event_anim
# Check if the player is still facing the event
if !@player_interacted_event.nil? && @player_interacted_event.player_facing?
# Exit the method
return
else
# Reset animation
$game_player.animation_loop_id = 0
@player_interacted_event = nil
end
# Check all events and determine if they can be inspected
@events.values.each do |event|
next unless @inspectable_events.include?(event.id)
if event.player_facing?
# Record the interacted event
@player_interacted_event = event
# Set animation
$game_player.animation_loop_id = InspectEvent::EVENT_ANIMATION_ID
# Exit method
return
end
end
end
end
#==============================================================================
# ** Sprite_Character
#==============================================================================
class Sprite_Character
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
alias inspect_event_character_update update
def update
# Call original
inspect_event_character_update
# Set loop animation
if @character.animation_loop_id != 0
anim = $data_animations[@character.animation_loop_id]
loop_animation(anim)
else
loop_animation(nil)
end
end
end
InstructionsInstructions are in the script, but it is as simple as putting a comment with "\inspect_event" in the event page you want the animation to display on. Note that the default animation used, "EM Exclamation" plays a sound every time it is looped. I suggest creating a new, silent animation and setting its ID in the configuration.
CompatibilityThis script aliases the Game_Map, Game_Event, Game_Character and Sprite_Character classes. This will not be compatible with any scripts that heavily re-write those classes.
Credits and Thanks- KK20 for helping with 90% of this
- Everyone else in the Discord server for helping out and/or dealing with my ramblings
Author's NotesThis is my first script. I figured I'd make a contribution back to Chaos Project since this community has been so helpful in my game's development. Hopefully this script treats someone else just as well!
Credit for this script isn't required, but greatly appreciated, with the exception of redistribution. If you post this script elsewhere, please link back to this original post.