Introduction
This script grants the ability to generate an aura effect for map events, whether drawn behind or atop the graphic itself. Along with that, this script also includes a feature to render pre-defined text messages above the event. Designed to work separate of each other, the text and aura options must be defined in each event that has the added effect. An event will only require the options required for the effect desired.
Script
The Script
Code:
#==============================================================================
# ** Djigital Aura
#------------------------------------------------------------------------------
# by DerVVulfman
# version 1.1
# 09-25-2016
# RGSS / RPGMaker XP
# Requires the SDK Add-On: Event Comment Supplemental
# (http://save-point.org/thread-3823.html)
#==============================================================================
#
# INTRODUCTION:
#
# This script grants the ability to generate an aura effect for map events,
# whether drawn behind or atop the graphic itself. Along with that, this
# script also includes a feature to render pre-defined text messages above
# the event. Designed to work separate of each other, the text and aura
# options must be defined in each event that has the added effect. An event
# will only require the options required for the effect desired.
#
# Flexible, this system allows the desired effect to be delivered through
# the use of a scripted Hotkey, a script call, or by way of a common event
# using the script call and triggered by an Item of Skill in the database.
#
#
# AURA EFFECT:
# The aura effect is made by way of a secondary characterset graphic within
# the Graphics\Characters folder. Initially, it was only to be drawn behind
# the event sprite but has been altered so it can be drawn in front. Along
# with that, the opacity of the aura effect need not be 100% solid.
#
# The comment used, by default is the word Aura followed by the charset in
# use. EX: Aura RedAura
#
#
# TEXT EFFECT:
# The text effect appears above the rendered sprite, and uses the calcula-
# ted height of the sprite for text placement. If no height adjustment is
# required, you need only supply the string to render. But if the height
# needs to be raised or lowered, you must put supply a two-parameter array.
# Here, the first parameter is a the text (WITHIN QUOTES) while the second
# parameter is the height.
#
# The comment used, by default is the word AText followed by the text drawn
# above the character.
# EX: AText Thief
# EX: AText "Lvl1 Thief"
# EX: AText ["Giant Monster!", -30]
#
#
# THE SCRIPT CALL:
# For convenience purposes, a very simple script call was made which will
# turn on the aura effect for a time, either EXTREMELY BRIEF if the system
# was set to use the 'constant-press' mode, or for a pre-defined amount of
# time as set in the configuration section.
#
#
# USED FROM THE MENU:
# IF you wish to use a SKILL or ITEM to perform the aura effect, you will
# need to add a WAIT command for approximately 10 frames before calling
# the aura script call. Yes, the script call will draw aura effect and/or
# text effects onto events near the player is merely 'aura'.
#
#
#==============================================================================
#
# TERMS AND CONDITIONS:
#
# Free for use, even in commercial games.
#
#==============================================================================
module Aura
# ACTION CONTROL
# ==============
#
AURA_MODE = false # MODE: (true = while press/false = timed)
AURA_KEY = Input::A # Key Pressed to perform aura test
# EVENT CONTROL
# =============
#
AURA_GRAPHIC = 'Aura' # Event Comment for Aura (Ex: 'Aura Fred')
AURA_RANGE = 5 # Range from event (in Tiles)
# RENDER CONTROL
# ==============
#
AURA_DELAY = 40 # Delay (in frames) that the aura shows
AURA_OVER = true # Drawn over or under the character?
AURA_OPACITY = 64 # How solid the aura is drawn (0-255)
# TEXT CONTROL
# ============
#
AURA_TEXT = 'AText' # Event Comment for text(EX:'AText Thief')
AURA_FONT = "Arial" # Font used to render text
AURA_SIZE = 14 # Size of Font Used
AURA_COLOR = [255,0,255,255] # Color of text (RRR,GGG,BBB,AAA)
AURA_SHADOW = [0,0,0,255] # Color of text (or nil if not used)
end
#==============================================================================
# ** Game_Map
#------------------------------------------------------------------------------
# This class handles the map. It includes scrolling and passable determining
# functions. Refer to "$game_map" for the instance of this class.
#==============================================================================
class Game_Map
#--------------------------------------------------------------------------
# * Aura Script's In range? (Near Fantastica addendum Anti-Lag Edit)
# object : event object in map
#--------------------------------------------------------------------------
def aura_in_range?(object)
screne_x = $game_map.display_x
screne_x -= 256
screne_y = $game_map.display_y
screne_y -= 256
screne_width = $game_map.display_x
screne_width += 2816
screne_height = $game_map.display_y
screne_height += 2176
return false if object.real_x <= screne_x-32
return false if object.real_x >= screne_width+32
return false if object.real_y <= screne_y-32
return false if object.real_y >= screne_height+32
return true
end
end
#==============================================================================
# ** Game_Character
#------------------------------------------------------------------------------
# This class deals with characters. It's used as a superclass for the
# Game_Player and Game_Event classes.
#==============================================================================
class Game_Character
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :character_name # character file name
attr_accessor :aura_delay # Aura Delay
attr_accessor :aura_character # Original character from Aura
attr_accessor :aura_text # Text that appears in Aura
attr_accessor :aura_text_y # Y-Adjust for text that appears
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias game_character_aura_initialize initialize
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
# Perform the original call
game_character_aura_initialize
# New values
@aura_delay = nil
@aura_character = ""
@aura_text = ""
@aura_text_y = 0
end
end
#==============================================================================
# ** Game_Event
#------------------------------------------------------------------------------
# This class deals with events. It handles functions including event page
# switching via condition determinants, and running parallel process events.
# It's used within the Game_Map class.
#==============================================================================
class Game_Event < Game_Character
#--------------------------------------------------------------------------
# * Public instance variables
#--------------------------------------------------------------------------
attr_reader :page # Event page
end
#==============================================================================
# ** Sprite_Character
#------------------------------------------------------------------------------
# This sprite is used to display the character.It observes the Game_Character
# class and automatically changes sprite conditions.
#==============================================================================
class Sprite_Character < RPG::Sprite
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
if @sprite_character_aura_stack_fix.nil?
alias sprite_character_aura_initialize initialize
alias sprite_character_aura_dispose dispose
@sprite_character_aura_stack_fix = true
end
#--------------------------------------------------------------------------
# * Object Initialization
# viewport : viewport
# character : character (Game_Character)
#--------------------------------------------------------------------------
def initialize(viewport, character = nil)
# What kind is the character? (Event or nothing)
@actor = (character.is_a?(Game_Event)) ? 'event' : nil
# Perform the original call
sprite_character_aura_initialize(viewport, character)
end
#--------------------------------------------------------------------------
# * Did the aura change its visibility?
#--------------------------------------------------------------------------
def show_hide_aura?
# According to the kind of the actor, the check is made...
return false unless @character.is_a?(Game_Event)
if (@character.aura_character != "" &&
@character.aura_delay == Aura::AURA_DELAY-1)
return true
end
if (@character.aura_delay == 0 && @character.aura_character == "")
@character.aura_delay = nil
return true
end
return false
end
#--------------------------------------------------------------------------
# * Update graphics for Aura effect
#--------------------------------------------------------------------------
def update_aura
# Remember tile ID, file name and hue
@tile_id = @character.tile_id
@character_name = @character.character_name
@character_hue = @character.character_hue
# If the actor isent supported, return immideatly
return if @actor == nil
# According to the kind of the actor, the update is made...
@page = @character.page if @character.is_a?(Game_Event)
end
#--------------------------------------------------------------------------
# * Update
#--------------------------------------------------------------------------
def update
super()
# If something changed...
if @tile_id != @character.tile_id or
@character_name != @character.character_name or
@character_hue != @character.character_hue or show_hide_aura?
# First, update the information known
update_aura
# Then update the graphics
update_tile
end
# Set visible situation
self.visible = (not @character.transparent)
# If graphic is character
if @tile_id == 0
# Set rectangular transfer
sx = @character.pattern * @cw
sy = (@character.direction - 2) / 2 * @ch
self.src_rect.set(sx, sy, @cw, @ch)
end
# Set sprite coordinates
self.x = @character.screen_x
self.y = @character.screen_y
self.z = @character.screen_z(@ch)
# Set opacity level, blend method, and bush depth
self.opacity = @character.opacity
self.blend_type = @character.blend_type
self.bush_depth = @character.bush_depth
# Animation
if @character.animation_id != 0
animation = $data_animations[@character.animation_id]
animation(animation, true)
@character.animation_id = 0
end
update_aura_text
end
#--------------------------------------------------------------------------
# * Dispose
#--------------------------------------------------------------------------
def dispose
# Original Dispose
sprite_character_aura_dispose
# Dispose aura Sprite
dispose_aura_text
end
#--------------------------------------------------------------------------
# * Dispose aura Sprite
#--------------------------------------------------------------------------
def dispose_aura_text
# Dispose aura Sprite
unless @_aura_text_sprite.nil?
@_aura_text_sprite.dispose
@_aura_text_sprite = nil
end
end
#--------------------------------------------------------------------------
# * Update Tile
#--------------------------------------------------------------------------
def update_tile
# Decide between map tile or event tile
(@tile_id >= 384) ? update_map_tile : update_event_tile
end
#--------------------------------------------------------------------------
# * Update Map Tile (from the tileset)
#--------------------------------------------------------------------------
def update_map_tile
self.bitmap = RPG::Cache.tile($game_map.tileset_name, @tile_id,
@character.character_hue)
self.src_rect.set(0, 0, 32, 32)
self.ox = 16
self.oy = 32
end
#--------------------------------------------------------------------------
# * Update Map Tile (from a map event)
#--------------------------------------------------------------------------
def update_event_tile
# Create an image render array
renders = []
# If handling a event
if @character.is_a?(Game_Event) == true and @actor == 'event'
# Check for comment input
params = @character.aura_character
# If the effect is drawn under the character
unless Aura::AURA_OVER == true
# Set up the aura effect character if it exists
renders.push([params, 0]) if !(params.nil? or params == "")
end
# Then set up the character's normal graphic
renders.push([@character_name, @character_hue])
# If the effect is drawn over the character
if Aura::AURA_OVER == true
# Set up the aura effect character if it exists
renders.push([params, 0]) if !(params.nil? or params == "")
end
end
# Dispose old bitmap
self.bitmap.dispose unless self.bitmap.nil?
# Draws the character bitmap
bmp = RPG::Cache.character(@character_name, @character_hue)
self.bitmap = Bitmap.new(bmp.width, bmp.height)
src_rect = Rect.new(0, 0, bmp.width, bmp.height)
# If character fits the size
if renders.size > 0
for graphic in renders
next if graphic[0] == nil
render_bitmap = RPG::Cache.character(graphic[0], graphic[1].to_i)
src_rect = Rect.new(0, 0, bmp.width, bmp.height)
opacity = 255
opacity = Aura::AURA_OPACITY if graphic[0] != @character_name
self.bitmap.blt(0, 0, render_bitmap, src_rect, opacity)
end
else
src_rect = Rect.new(0, 0, bmp.width, bmp.height)
self.bitmap.blt(0, 0, bmp, src_rect, 255)
end
# Divide the charset into pieces
@cw = bitmap.width / 4
@ch = bitmap.height / 4
self.ox = @cw / 2
self.oy = @ch
end
#--------------------------------------------------------------------------
# * Update Display Sprite
#--------------------------------------------------------------------------
def update_aura_text
# Dispose and exit if character has no aura
return dispose_aura_text if @character.aura_text.nil?
# Create the aura text if text sprite doesn't exist
return create_aura_text if @_aura_text_sprite.nil?
# If aura text isn't the same as before
unless @_aura_display_text == @character.aura_text
# Dispose Sprite
dispose_aura_text
# Re-Create Sprite
create_aura_text
end
# Update aura Sprite Position
@_aura_text_sprite.x = self.x
@_aura_text_sprite.y = self.y - self.oy + @character.aura_text_y
end
#--------------------------------------------------------------------------
# * Create aura Sprite
#--------------------------------------------------------------------------
def create_aura_text
# Creates Display Bitmap
bitmap = Bitmap.new(162, 26)
# Set font in bitmap
bitmap.font.name = Aura::AURA_FONT
bitmap.font.size = Aura::AURA_SIZE
# Turns off Text Shadow written by SephirothSpawn
bitmap.draw_shadow = false if bitmap.respond_to?(:draw_shadow)
# Draws Text Shadow
unless Aura::AURA_SHADOW.nil?
bitmap.font.color = create_aura_color(Aura::AURA_SHADOW)
bitmap.draw_text(1, 1, 160, 24, @character.aura_text, 1)
end
# Draws aura Display Text
bitmap.font.color = create_aura_color(Aura::AURA_COLOR)
bitmap.draw_text(0, 0, 160, 24, @character.aura_text, 1)
# Creates Display Text Sprite
@_aura_text_sprite = Sprite.new(self.viewport)
@_aura_text_sprite.bitmap = bitmap
@_aura_text_sprite.ox = 80
@_aura_text_sprite.oy = 24
@_aura_text_sprite.x = self.x
@_aura_text_sprite.y = self.y - self.oy + @character.aura_text_y
@_aura_text_sprite.z = 3000
@_aura_text_sprite.visible = true
# Saves aura Text
@_aura_display_text = @character.aura_text
end
#--------------------------------------------------------------------------
# * Create aura text color
# color_array : array of four color parameters (rrr,ggg,bbb,aaa)
#--------------------------------------------------------------------------
def create_aura_color(color_array)
return Color.new(color_array[0], color_array[1],
color_array[2], color_array[3])
end
end
#==============================================================================
# ** Interpreter
#------------------------------------------------------------------------------
# This interpreter runs event commands. This class is used within the
# Game_System class and the Game_Event class.
#==============================================================================
class Interpreter
#--------------------------------------------------------------------------
# * Script Call Command
#--------------------------------------------------------------------------
def aura
return unless $scene.is_a?(Scene_Map)
$scene.aura_test
end
end
#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
# This class performs map screen processing.
#==============================================================================
class Scene_Map
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias game_map_aura_update update
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
@current = false if @current.nil?
# Do test if key triggered
(Aura::AURA_MODE == true) ? aura_mode_two : aura_mode_one
# Perform the original call
game_map_aura_update
end
#--------------------------------------------------------------------------
# * Aura System Mode One : Single keypress that draws the aura for X frames
#--------------------------------------------------------------------------
def aura_mode_one
# Do test if key triggered
aura_test if Input.trigger?(Aura::AURA_KEY)
# Update timer
aura_delay_update
end
#--------------------------------------------------------------------------
# * Aura System Mode Two : Constatn keypress the shows aura until released
#--------------------------------------------------------------------------
def aura_mode_two
# Player cannot be moving
return aura_cancel if $game_player.moving?
# Obtain keypress as local variable (works better as set variable)
test = aura_toggle_key
# If the current aura_key state doesn't match the keypress, we toggled
if @current != test
# Turn on or off the effect based on the new toggle state
(test == true) ? aura_test : aura_cancel
# And reset the toggle aura key toggle state
@current = test
end
end
#--------------------------------------------------------------------------
# * Aura System Toggle Key : Returns if the desired keypress is true or not
#--------------------------------------------------------------------------
def aura_toggle_key
return true if Input.press?(Aura::AURA_KEY)
return false
end
#--------------------------------------------------------------------------
# * Test objects within range of player within the map
# range : area range from target (default in config)
#--------------------------------------------------------------------------
def aura_test(range=Aura::AURA_RANGE)
# No larger than approx 1/2 map height (effect safeguard)
range = 7 if range > 7
# Cycle through events
for event in $game_map.events
# Skip if not in screen range (limit the events tested)
next unless $game_map.aura_in_range?(event[1])
# Perform aura if in range of player
aura_apply(event) if aura_in_range?($game_player, event[1],range)
end
end
#--------------------------------------------------------------------------
# * Test objects within the map to remove effect
#--------------------------------------------------------------------------
def aura_cancel
# Cycle through events
for event in $game_map.events
# Skip if not in screen range (limit the events tested)
next unless $game_map.aura_in_range?(event[1])
# Perform aura if in range of player
aura_reset(event)
end
end
#--------------------------------------------------------------------------
# * Update the aura delay counter
#--------------------------------------------------------------------------
def aura_delay_update
for event in $game_map.events
next if event[1].aura_delay.nil?
next aura_reset(event) if event[1].aura_delay == 0
event[1].aura_delay -= 1 if event[1].aura_delay > 0
end
end
#--------------------------------------------------------------------------
# * Reset the event back to no aura
# event : event
#--------------------------------------------------------------------------
def aura_reset(event)
event[1].aura_delay = 0
event[1].aura_character = ""
event[1].aura_text = ""
event[1].aura_text_y = 0
end
#--------------------------------------------------------------------------
# * Aura Script's In Circle Range? (Near Fantastica View Range Edit)
# element : element
# object : object
# range : range from the target in tiles
#--------------------------------------------------------------------------
def aura_in_range?(element, object, range)
x = (element.x - object.x) * (element.x - object.x)
y = (element.y - object.y) * (element.y - object.y)
r = x + y
return true if r <= (range * range)
return false
end
#--------------------------------------------------------------------------
# * Apply Aura Effect on Event
# event : event
#--------------------------------------------------------------------------
def aura_apply(event)
# Get list of comments
mylist = SDK.event_comment_list(event[1])
# Exit if no Aura ID
return if mylist.nil?
# Garner data from comment list
returned = SDK.event_comment_data(mylist, Aura::AURA_TEXT)
unless returned.nil?
if returned[0,1] == "["
r_array = []
r_array = eval(returned)
event[1].aura_text = r_array[0]
event[1].aura_text_y = r_array[1].to_i
else
event[1].aura_text = returned
event[1].aura_text_y = 0
end
end
# Garner data from comment list
returned = SDK.event_comment_data(mylist, Aura::AURA_GRAPHIC)
# Exit if invalid data
return if returned.nil?
event[1].aura_character = returned
event[1].aura_delay = (Aura::AURA_MODE == true) ? Aura::AURA_DELAY-1 :
Aura::AURA_DELAY
end
end
Notes:
The system allows for both Auras and Aura Texts to be shown per event. Each has their own comment command. You can use one or both per event page. And triggering different pages for an event is possible.
Currently, the designated color of the aura text is set to purple. This by way of the AURA_COLOR value having been set to [255,0,255,255]. It is an RGBA array, so [255,255,255,255] would be solid white.
Remember to have aura graphics that match your chosen events, especially insofar as pixel size. Size differences between the aura graphics and the event's own characterset will appear rather odd.
Nicely done so far!
I've some questions left.
Could it be possivle to implement a text system like I asked where one could define a text appearing above the NPC which comes alongside.
Like: Ghost LVL 1:
Is it possible to change the aura system so that the auras will be shown when the player is only holding the button? I dont like the Idea of just pressing the button once.
Is there a mechanism to deactivate the aura system?
You may now set up the system to use a single keypress that will render the aura effect on characters for a set duration, or have the feature allow you to press and hold the designated hotkey for as long as you wish. And not only can you see an aura behind (or covering) the character, but text above the character if such was made.
And descriptive aura texts have now been added as well, including an option for height adjustment.
Please note. You cannot walk AND hold the hotkey at the same time for the newer press-and-hold aura function. The player must remain still to concentrate. And it would cause a lot of issues handling repeated cycles of detecting if the events were in range as the player is constantly moving from tile to tile and so forth.
Also note. The required SDK Comments Add-On had been updated to handle returned strings that include spaces within.
Up is down, left is right and sideways is straight ahead. - Cord "Circle of Iron", 1978 (written by Bruce Lee and James Coburn... really...)
You may now set up the system to use a single keypress that will render the aura effect on characters for a set duration, or have the feature allow you to press and hold the designated hotkey for as long as you wish. And not only can you see an aura behind (or covering) the character, but text above the character if such was made.
And descriptive aura texts have now been added as well, including an option for height adjustment.
Please note. You cannot walk AND hold the hotkey at the same time for the newer press-and-hold aura function. The player must remain still to concentrate. And it would cause a lot of issues handling repeated cycles of detecting if the events were in range as the player is constantly moving from tile to tile and so forth.
Also note. The required SDK Comments Add-On had been updated to handle returned strings that include spaces within.
Okay, works fine. Thank you really really much.
I still have some questions left:
1. Can you add a switch which will deactivate the possibility to use the Aura skill. Baiscially like if switch 2 is on, searching for auras wont work even if pressed. Because in some situations I dont want the hero to use it :))
For example, I dont want the Hero to use the aura while talking to a NPC ohr while Autoruns.
2. Is it possible to use the aura skill via common events? Or asking the other way, is it possible to ask in a conditional branch wheiter the AURA_MODE is currently on (because it would help me a lot, really :) )
3. Is it possible to change the color of the Aura Text shown?
There was plenty described within the script itself, one of which is that the comments must be on the current page for an event. One COULD make events that have no comments (aura or text) one one page, but have comments on another. In this, you could use switches to deactivate or activate the page to the events with the comments.
Insofar as using common events, it is clearly described in the script's instructions. And the AURA_MODE value is a configurable value, not a toggle switch that turns on or off during the game. But each event has its OWN form of test, that being the aura_delay value. as long as the aura delay for an event isn't nil, it must be on. Understand that each event has its own value because of the option to give each event a timer before their respective auras fade. The player could be a button-masher and one event may still have the aura visible while another is turned on.
And the color to the aura text is defined in the configurable section. I choose not to add too much to the comment system so as to not slow it down.
And everything here is within the 'confines' of the initial request.
Up is down, left is right and sideways is straight ahead. - Cord "Circle of Iron", 1978 (written by Bruce Lee and James Coburn... really...)
Hm.. I understood about the color issue, but I didint clearly understand the switch off mechanism.
I know that the AURA_MODE is not a method to deactivate the script iself with it. It only toggles between pressing and holding.
I also noted, that the aura effect is handled for each npc and not as a whole like using self switches to deactivate it (Which is in fact a good thing)
But I asked for a upper switch to completly deactivate the whole aura skill system. Like a definble switch in the script itself.
I hope Im not confusing anyone, well I already confused my self abit, so lets forget about that XD.
Not confusing. I'm basically done with the script.
What I said was if you wanted to make a switch that turns off the ability to show auras, then make a second page for your events with that RMXP switch turned on and no aura comments. That way, there is no need for me to add any more.
Up is down, left is right and sideways is straight ahead. - Cord "Circle of Iron", 1978 (written by Bruce Lee and James Coburn... really...)
I noteded that one can turn the aura of an event off via self switches/Switches but it would be much easier to be able deactivate the Script itself with a single switch implemented. This is why I asked. At some points I want to deactivate the Ability to use it.
Since Im doing some extra things with it, it could help me alot.
Sorry for double post, but I thought this is needed.
I've managed to somehow through help to make a definable switch to switch the aura searching on and off.
But the biggest problem is the intense lag that the script is creating.
I've made a complete new game without any other scripts.
I tested on a map with 300 events. Without the sript I get like 40 fps.
But with the both scripts in the demo I get like 8 FPS. This is insane.
Is their anyway to fix this?
Now I have the script the way I want to be, but I cant use it...
( ≧Д≦)
Im so helpless.
BTW: As I noticed this only applies for the edited version below me, with your original script it doesnt happen.
Oh lord, what did I do wrong this time?
Heres the exact code:
The only changed part are these:
Quote:#-------------------------------------------------------------------------- # * Aura System Mode One : Single keypress that draws the aura for X frames #-------------------------------------------------------------------------- def aura_mode_one if$game_switches[Aura::AURA_SWITCH] == truethen # Do test if key triggered
aura_test if Input.trigger?(Aura::AURA_KEY) # Update timer
aura_delay_update else
aura_cancel end end #-------------------------------------------------------------------------- # * Aura System Mode Two : Constatn keypress the shows aura until released #-------------------------------------------------------------------------- def aura_mode_two if$game_switches[Aura::AURA_SWITCH] == truethen # Player cannot be moving return aura_cancel if$game_player.moving? # Obtain keypress as local variable (works better as set variable)
test = aura_toggle_key # If the current aura_key state doesn't match the keypress, we toggled if@current != test # Turn on or off the effect based on the new toggle state (test == true) ? aura_test : aura_cancel # And reset the toggle aura key toggle state @current = test end else
aura_cancel end end
# ** Djigital Aura
#------------------------------------------------------------------------------
# by DerVVulfman
# version 1.1
# 09-25-2016
# RGSS / RPGMaker XP
# Requires the SDK Add-On: Event Comment Supplemental
# (http://save-point.org/thread-3823.html)
#==============================================================================
#
# INTRODUCTION:
#
# This script grants the ability to generate an aura effect for map events,
# whether drawn behind or atop the graphic itself. Along with that, this
# script also includes a feature to render pre-defined text messages above
# the event. Designed to work separate of each other, the text and aura
# options must be defined in each event that has the added effect. An event
# will only require the options required for the effect desired.
#
# Flexible, this system allows the desired effect to be delivered through
# the use of a scripted Hotkey, a script call, or by way of a common event
# using the script call and triggered by an Item of Skill in the database.
#
#
# AURA EFFECT:
# The aura effect is made by way of a secondary characterset graphic within
# the Graphics\Characters folder. Initially, it was only to be drawn behind
# the event sprite but has been altered so it can be drawn in front. Along
# with that, the opacity of the aura effect need not be 100% solid.
#
# The comment used, by default is the word Aura followed by the charset in
# use. EX: Aura RedAura
#
#
# TEXT EFFECT:
# The text effect appears above the rendered sprite, and uses the calcula-
# ted height of the sprite for text placement. If no height adjustment is
# required, you need only supply the string to render. But if the height
# needs to be raised or lowered, you must put supply a two-parameter array.
# Here, the first parameter is a the text (WITHIN QUOTES) while the second
# parameter is the height.
#
# The comment used, by default is the word AText followed by the text drawn
# above the character.
# EX: AText Thief
# EX: AText "Lvl1 Thief"
# EX: AText ["Giant Monster!", -30]
#
#
# THE SCRIPT CALL:
# For convenience purposes, a very simple script call was made which will
# turn on the aura effect for a time, either EXTREMELY BRIEF if the system
# was set to use the 'constant-press' mode, or for a pre-defined amount of
# time as set in the configuration section.
#
#
# USED FROM THE MENU:
# IF you wish to use a SKILL or ITEM to perform the aura effect, you will
# need to add a WAIT command for approximately 10 frames before calling
# the aura script call. Yes, the script call will draw aura effect and/or
# text effects onto events near the player is merely 'aura'.
#
#
#==============================================================================
#
# TERMS AND CONDITIONS:
#
# Free for use, even in commercial games.
#
#==============================================================================
module Aura
# ACTION CONTROL
# ==============
#
AURA_SWITCH = 77 # Schalter, um Aura-Feature zu aktivieren
AURA_MODE = true # MODE: (true = while press/false = timed)
AURA_KEY = Input::A # Key Pressed to perform aura test
# EVENT CONTROL
# =============
#
AURA_GRAPHIC = 'Aura' # Event Comment for Aura (Ex: 'Aura Fred')
AURA_RANGE = 5 # Range from event (in Tiles)
# RENDER CONTROL
# ==============
#
AURA_DELAY = 40 # Delay (in frames) that the aura shows
AURA_OVER = true # Drawn over or under the character?
AURA_OPACITY = 255 # How solid the aura is drawn (0-255)
# TEXT CONTROL
# ============
#
AURA_TEXT = 'AText' # Event Comment for text(EX:'AText Thief')
AURA_FONT = "Arial" # Font used to render text
AURA_SIZE = 14 # Size of Font Used
AURA_COLOR = [255,255,255,255] # Color of text (RRR,GGG,BBB,AAA)
AURA_SHADOW = [0,0,0,255] # Color of text (or nil if not used)
end
#==============================================================================
# ** Game_Map
#------------------------------------------------------------------------------
# This class handles the map. It includes scrolling and passable determining
# functions. Refer to "$game_map" for the instance of this class.
#==============================================================================
class Game_Map
#--------------------------------------------------------------------------
# * Aura Script's In range? (Near Fantastica addendum Anti-Lag Edit)
# object : event object in map
#--------------------------------------------------------------------------
def aura_in_range?(object)
screne_x = $game_map.display_x
screne_x -= 256
screne_y = $game_map.display_y
screne_y -= 256
screne_width = $game_map.display_x
screne_width += 2816
screne_height = $game_map.display_y
screne_height += 2176
return false if object.real_x <= screne_x-32
return false if object.real_x >= screne_width+32
return false if object.real_y <= screne_y-32
return false if object.real_y >= screne_height+32
return true
end
end
#==============================================================================
# ** Game_Character
#------------------------------------------------------------------------------
# This class deals with characters. It's used as a superclass for the
# Game_Player and Game_Event classes.
#==============================================================================
class Game_Character
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :character_name # character file name
attr_accessor :aura_delay # Aura Delay
attr_accessor :aura_character # Original character from Aura
attr_accessor :aura_text # Text that appears in Aura
attr_accessor :aura_text_y # Y-Adjust for text that appears
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias game_character_aura_initialize initialize
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
# Perform the original call
game_character_aura_initialize
# New values
@aura_delay = nil
@aura_character = ""
@aura_text = ""
@aura_text_y = 0
end
end
#==============================================================================
# ** Game_Event
#------------------------------------------------------------------------------
# This class deals with events. It handles functions including event page
# switching via condition determinants, and running parallel process events.
# It's used within the Game_Map class.
#==============================================================================
class Game_Event < Game_Character
#--------------------------------------------------------------------------
# * Public instance variables
#--------------------------------------------------------------------------
attr_reader :page # Event page
end
#==============================================================================
# ** Sprite_Character
#------------------------------------------------------------------------------
# This sprite is used to display the character.It observes the Game_Character
# class and automatically changes sprite conditions.
#==============================================================================
class Sprite_Character < RPG::Sprite
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
if @sprite_character_aura_stack_fix.nil?
alias sprite_character_aura_initialize initialize
alias sprite_character_aura_dispose dispose
@sprite_character_aura_stack_fix = true
end
#--------------------------------------------------------------------------
# * Object Initialization
# viewport : viewport
# character : character (Game_Character)
#--------------------------------------------------------------------------
def initialize(viewport, character = nil)
# What kind is the character? (Event or nothing)
@actor = (character.is_a?(Game_Event)) ? 'event' : nil
# Perform the original call
sprite_character_aura_initialize(viewport, character)
end
#--------------------------------------------------------------------------
# * Did the aura change its visibility?
#--------------------------------------------------------------------------
def show_hide_aura?
# According to the kind of the actor, the check is made...
return false unless @character.is_a?(Game_Event)
if (@character.aura_character != "" &&
@character.aura_delay == Aura::AURA_DELAY-1)
return true
end
if (@character.aura_delay == 0 && @character.aura_character == "")
@character.aura_delay = nil
return true
end
return false
end
#--------------------------------------------------------------------------
# * Update graphics for Aura effect
#--------------------------------------------------------------------------
def update_aura
# Remember tile ID, file name and hue
@tile_id = @character.tile_id
@character_name = @character.character_name
@character_hue = @character.character_hue
# If the actor isent supported, return immideatly
return if @actor == nil
# According to the kind of the actor, the update is made...
@page = @character.page if @character.is_a?(Game_Event)
end
#--------------------------------------------------------------------------
# * Update
#--------------------------------------------------------------------------
def update
super()
# If something changed...
if @tile_id != @character.tile_id or
@character_name != @character.character_name or
@character_hue != @character.character_hue or show_hide_aura?
# First, update the information known
update_aura
# Then update the graphics
update_tile
end
# Set visible situation
self.visible = (not @character.transparent)
# If graphic is character
if @tile_id == 0
# Set rectangular transfer
sx = @character.pattern * @cw
sy = (@character.direction - 2) / 2 * @ch
self.src_rect.set(sx, sy, @cw, @ch)
end
# Set sprite coordinates
self.x = @character.screen_x
self.y = @character.screen_y
self.z = @character.screen_z(@ch)
# Set opacity level, blend method, and bush depth
self.opacity = @character.opacity
self.blend_type = @character.blend_type
self.bush_depth = @character.bush_depth
# Animation
if @character.animation_id != 0
animation = $data_animations[@character.animation_id]
animation(animation, true)
@character.animation_id = 0
end
update_aura_text
end
#--------------------------------------------------------------------------
# * Dispose
#--------------------------------------------------------------------------
def dispose
# Original Dispose
sprite_character_aura_dispose
# Dispose aura Sprite
dispose_aura_text
end
#--------------------------------------------------------------------------
# * Dispose aura Sprite
#--------------------------------------------------------------------------
def dispose_aura_text
# Dispose aura Sprite
unless @_aura_text_sprite.nil?
@_aura_text_sprite.dispose
@_aura_text_sprite = nil
end
end
#--------------------------------------------------------------------------
# * Update Tile
#--------------------------------------------------------------------------
def update_tile
# Decide between map tile or event tile
(@tile_id >= 384) ? update_map_tile : update_event_tile
end
#--------------------------------------------------------------------------
# * Update Map Tile (from the tileset)
#--------------------------------------------------------------------------
def update_map_tile
self.bitmap = RPG::Cache.tile($game_map.tileset_name, @tile_id,
@character.character_hue)
self.src_rect.set(0, 0, 32, 32)
self.ox = 16
self.oy = 32
end
#--------------------------------------------------------------------------
# * Update Map Tile (from a map event)
#--------------------------------------------------------------------------
def update_event_tile
# Create an image render array
renders = []
# If handling a event
if @character.is_a?(Game_Event) == true and @actor == 'event'
# Check for comment input
params = @character.aura_character
# If the effect is drawn under the character
unless Aura::AURA_OVER == true
# Set up the aura effect character if it exists
renders.push([params, 0]) if !(params.nil? or params == "")
end
# Then set up the character's normal graphic
renders.push([@character_name, @character_hue])
# If the effect is drawn over the character
if Aura::AURA_OVER == true
# Set up the aura effect character if it exists
renders.push([params, 0]) if !(params.nil? or params == "")
end
end
# Dispose old bitmap
self.bitmap.dispose unless self.bitmap.nil?
# Draws the character bitmap
bmp = RPG::Cache.character(@character_name, @character_hue)
self.bitmap = Bitmap.new(bmp.width, bmp.height)
src_rect = Rect.new(0, 0, bmp.width, bmp.height)
# If character fits the size
if renders.size > 0
for graphic in renders
next if graphic[0] == nil
render_bitmap = RPG::Cache.character(graphic[0], graphic[1].to_i)
src_rect = Rect.new(0, 0, bmp.width, bmp.height)
opacity = 255
opacity = Aura::AURA_OPACITY if graphic[0] != @character_name
self.bitmap.blt(0, 0, render_bitmap, src_rect, opacity)
end
else
src_rect = Rect.new(0, 0, bmp.width, bmp.height)
self.bitmap.blt(0, 0, bmp, src_rect, 255)
end
# Divide the charset into pieces
@cw = bitmap.width / 4
@ch = bitmap.height / 4
self.ox = @cw / 2
self.oy = @ch
end
#--------------------------------------------------------------------------
# * Update Display Sprite
#--------------------------------------------------------------------------
def update_aura_text
# Dispose and exit if character has no aura
return dispose_aura_text if @character.aura_text.nil?
# Create the aura text if text sprite doesn't exist
return create_aura_text if @_aura_text_sprite.nil?
# If aura text isn't the same as before
unless @_aura_display_text == @character.aura_text
# Dispose Sprite
dispose_aura_text
# Re-Create Sprite
create_aura_text
end
# Update aura Sprite Position
@_aura_text_sprite.x = self.x
@_aura_text_sprite.y = self.y - self.oy + @character.aura_text_y
end
#--------------------------------------------------------------------------
# * Create aura Sprite
#--------------------------------------------------------------------------
def create_aura_text
# Creates Display Bitmap
bitmap = Bitmap.new(162, 26)
# Set font in bitmap
bitmap.font.name = Aura::AURA_FONT
bitmap.font.size = Aura::AURA_SIZE
# Turns off Text Shadow written by SephirothSpawn
bitmap.draw_shadow = false if bitmap.respond_to?(:draw_shadow)
# Draws Text Shadow
unless Aura::AURA_SHADOW.nil?
bitmap.font.color = create_aura_color(Aura::AURA_SHADOW)
bitmap.draw_text(1, 1, 160, 24, @character.aura_text, 1)
end
# Draws aura Display Text
bitmap.font.color = create_aura_color(Aura::AURA_COLOR)
bitmap.draw_text(0, 0, 160, 24, @character.aura_text, 1)
# Creates Display Text Sprite
@_aura_text_sprite = Sprite.new(self.viewport)
@_aura_text_sprite.bitmap = bitmap
@_aura_text_sprite.ox = 80
@_aura_text_sprite.oy = 24
@_aura_text_sprite.x = self.x
@_aura_text_sprite.y = self.y - self.oy + @character.aura_text_y
@_aura_text_sprite.z = 3000
@_aura_text_sprite.visible = true
# Saves aura Text
@_aura_display_text = @character.aura_text
end
#--------------------------------------------------------------------------
# * Create aura text color
# color_array : array of four color parameters (rrr,ggg,bbb,aaa)
#--------------------------------------------------------------------------
def create_aura_color(color_array)
return Color.new(color_array[0], color_array[1],
color_array[2], color_array[3])
end
end
#==============================================================================
# ** Interpreter
#------------------------------------------------------------------------------
# This interpreter runs event commands. This class is used within the
# Game_System class and the Game_Event class.
#==============================================================================
class Interpreter
#--------------------------------------------------------------------------
# * Script Call Command
#--------------------------------------------------------------------------
def aura
return unless $scene.is_a?(Scene_Map)
$scene.aura_test
end
end
#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
# This class performs map screen processing.
#==============================================================================
class Scene_Map
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias game_map_aura_update update
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
@current = false if @current.nil?
# Do test if key triggered
(Aura::AURA_MODE == true) ? aura_mode_two : aura_mode_one
# Perform the original call
game_map_aura_update
end
#--------------------------------------------------------------------------
# * Aura System Mode One : Single keypress that draws the aura for X frames
#--------------------------------------------------------------------------
def aura_mode_one
if $game_switches[Aura::AURA_SWITCH] == true then
# Do test if key triggered
aura_test if Input.trigger?(Aura::AURA_KEY)
# Update timer
aura_delay_update
else
aura_cancel
end
end
#--------------------------------------------------------------------------
# * Aura System Mode Two : Constatn keypress the shows aura until released
#--------------------------------------------------------------------------
def aura_mode_two
if $game_switches[Aura::AURA_SWITCH] == true then
# Player cannot be moving
return aura_cancel if $game_player.moving?
# Obtain keypress as local variable (works better as set variable)
test = aura_toggle_key
# If the current aura_key state doesn't match the keypress, we toggled
if @current != test
# Turn on or off the effect based on the new toggle state
(test == true) ? aura_test : aura_cancel
# And reset the toggle aura key toggle state
@current = test
end
else
aura_cancel
end
end
#--------------------------------------------------------------------------
# * Aura System Toggle Key : Returns if the desired keypress is true or not
#--------------------------------------------------------------------------
def aura_toggle_key
return true if Input.press?(Aura::AURA_KEY)
return false
end
#--------------------------------------------------------------------------
# * Test objects within range of player within the map
# range : area range from target (default in config)
#--------------------------------------------------------------------------
def aura_test(range=Aura::AURA_RANGE)
# No larger than approx 1/2 map height (effect safeguard)
range = 7 if range > 7
# Cycle through events
for event in $game_map.events
# Skip if not in screen range (limit the events tested)
next unless $game_map.aura_in_range?(event[1])
# Perform aura if in range of player
aura_apply(event) if aura_in_range?($game_player, event[1],range)
end
end
#--------------------------------------------------------------------------
# * Test objects within the map to remove effect
#--------------------------------------------------------------------------
def aura_cancel
# Cycle through events
for event in $game_map.events
# Skip if not in screen range (limit the events tested)
next unless $game_map.aura_in_range?(event[1])
# Perform aura if in range of player
aura_reset(event)
end
end
#--------------------------------------------------------------------------
# * Update the aura delay counter
#--------------------------------------------------------------------------
def aura_delay_update
for event in $game_map.events
next if event[1].aura_delay.nil?
next aura_reset(event) if event[1].aura_delay == 0
event[1].aura_delay -= 1 if event[1].aura_delay > 0
end
end
#--------------------------------------------------------------------------
# * Reset the event back to no aura
# event : event
#--------------------------------------------------------------------------
def aura_reset(event)
event[1].aura_delay = 0
event[1].aura_character = ""
event[1].aura_text = ""
event[1].aura_text_y = 0
end
#--------------------------------------------------------------------------
# * Aura Script's In Circle Range? (Near Fantastica View Range Edit)
# element : element
# object : object
# range : range from the target in tiles
#--------------------------------------------------------------------------
def aura_in_range?(element, object, range)
x = (element.x - object.x) * (element.x - object.x)
y = (element.y - object.y) * (element.y - object.y)
r = x + y
return true if r <= (range * range)
return false
end
#--------------------------------------------------------------------------
# * Apply Aura Effect on Event
# event : event
#--------------------------------------------------------------------------
def aura_apply(event)
# Get list of comments
mylist = SDK.event_comment_list(event[1])
# Exit if no Aura ID
return if mylist.nil?
# Garner data from comment list
returned = SDK.event_comment_data(mylist, Aura::AURA_TEXT)
unless returned.nil?
if returned[0,1] == "["
r_array = []
r_array = eval(returned)
event[1].aura_text = r_array[0]
event[1].aura_text_y = r_array[1].to_i
else
event[1].aura_text = returned
event[1].aura_text_y = 0
end
end
# Garner data from comment list
returned = SDK.event_comment_data(mylist, Aura::AURA_GRAPHIC)
# Exit if invalid data
return if returned.nil?
event[1].aura_character = returned
event[1].aura_delay = (Aura::AURA_MODE == true) ? Aura::AURA_DELAY-1 :
Aura::AURA_DELAY
end
end