Chaos Project

RPG Maker => RPG Maker Scripts => RMXP Script Database => Topic started by: ThallionDarkshine on February 16, 2013, 04:10:46 pm

Title: [XP] Auras
Post by: ThallionDarkshine on February 16, 2013, 04:10:46 pm
Auras
Authors: ThallionDarkshine
Version: 0.1
Type: Misc Add-on
Key Term: Misc Add-on



Introduction

It's sometimes hard in an RPG Maker game to tell who's talking. Either you can add in an extra little window showing the current speaker's name, or you can add it to the start of the message. Here's another way to let users know who's speaking. This script allows you to create auras on events, causing a custom image to rotate or zoom in and out around them. There are three different animations for the auras at the moment, but you can use any combination of these, allowing you to create many cool effects.


Features




Screenshots

Spoiler: ShowHide

(http://i.imgur.com/irHOlJ0.png)



Demo

None


Script

Spoiler: ShowHide

module Auras
 # to give an aura to any event or the player, use this script call:
 #   aura(event_id, type)
 #     event_id - the id of the event or -1 for the player
 #       to give an aura to the current event, use @event_id for this value
 #     type - the type of aura set up later in the configuration
 #       set to a value of nil to turn off the aura
 # to turn off all the auras currently showing, use this script call:
 #   close_auras
 
 # whether to allow multiple auras to be shown simultanously on different
 #   characters
 MULTI_AURA = false
 
 # the configuration for the different types of auras
 # to add a new effect, use this template
 #   when TYPE then return {
 #       EFFECTS
 #     }
 # the different effects are:
 #   :filename => FILENAME,
 #     FILENAME - determines the filename of the aura picture in the
 #       Graphics/Pictures folder
 #   :spin => [DURATION, CLOCKWISE],
 #     DURATION - how long the spin effect should take
 #     CLOCKWISE - whether to spin clockwise
 #   :rock => [DURATION, SPIN_DEGREES],
 #     DURATION - how long the rock effect should take
 #     SPIN_DEGREES - how far the aura should spin before rocking back to the
 #       other side
 #   :zoom => [DURATION, ZOOM_AMOUNT],
 #     DURATION - how long the zoom effect should take
 #     ZOOM_AMOUNT - how much the aura should zoom in (or out with a value
 #       less than 1)
 def self.aura(type)
   case type
   when 0 then return {
       :filename => 'aura2',
       :spin => [60, false],
       :rock => [15, 8],
       :zoom => [10, 0.9],
     }
   end
   return {}
 end
end

class Sprite_Aura < Sprite
 def initialize(character, type)
   super(character.viewport)
   @character = character
   @args = Auras.aura(type)
   if @args.keys.include?(:filename)
     self.bitmap = RPG::Cache.picture(@args[:filename]).clone
     self.ox, self.oy = self.bitmap.width / 2, self.bitmap.height / 2
   end
   @args[:rock].push(1) if @args.keys.include?(:rock)
   @args[:zoom].push(1) if @args.keys.include?(:zoom)
   @args.each { |key, val|
     val.push(key == :rock ? val[0] / 2 : 0) if val.is_a?(Array)
   }
   update
 end
 
 def update
   super()
   w = (@character.bitmap.nil? ? 0 : @character.bitmap.width)
   h = (@character.bitmap.nil? ? 0 : @character.bitmap.height)
   self.x = @character.x - @character.ox + @character.src_rect.width / 2
   self.y = @character.y - @character.oy + @character.src_rect.height / 2
   self.z = @character.z + 100
   self.angle = 0
   if @args.keys.include?(:spin)
     s_args = @args[:spin]
     s_args[-1] = (s_args[-1] + 1) % s_args[0]
     self.angle += (s_args[1] ? 1 : -1) * 360 * s_args[-1] / s_args[0]
   end
   if @args.keys.include?(:rock)
     r_args = @args[:rock]
     r_args[-1] += r_args[-2]
     r_ang = r_args[1] * (r_args[-1] - r_args[0] / 2.0) / (r_args[0] / 2.0)
     r_args[-2] = 0-r_args[-2] if r_args[-1] == r_args[0] or r_args[-1] == 0
     self.angle += r_ang
   end
   if @args.keys.include?(:zoom)
     z_args = @args[:zoom]
     z_args[-1] += z_args[-2]
     self.zoom_x = self.zoom_y = 1 + (z_args[1] - 1.0) * z_args[-1] / z_args[0]
     z_args[-2] = 0-z_args[-2] if z_args[-1] == z_args[0] or z_args[-1] == 0
   end
 end
end

module RPG
 class Sprite
   alias tdks_auras_init initialize
   def initialize(viewport = nil)
     tdks_auras_init(viewport)
     @_aura = nil
   end
   
   def aura(type)
     @_aura = Sprite_Aura.new(self, type)
   end
   
   def dispose_aura
     unless @_aura.nil?
       @_aura.bitmap.dispose unless @_aura.bitmap.nil? or @_aura.bitmap.disposed?
       @_aura.dispose
       @_aura = nil
     end
   end
   
   alias tdks_auras_updt update
   def update
     tdks_auras_updt
     unless @_aura.nil?
       @_aura.update
     end
   end
 end
end

class Game_Character
 attr_accessor :aura
 
 alias tdks_auras_init initialize
 def initialize
   tdks_auras_init
   @aura = nil
 end
end

class Sprite_Character
 alias tdks_auras_sc_init initialize
 def initialize(viewport, character = nil)
   tdks_auras_sc_init(viewport, character)
   @old_aura = nil
 end
 
 alias tdks_auras_sc_updt update
 def update
   tdks_auras_sc_updt
   if @character.aura != @old_aura
     unless @character.aura.nil?
       self.aura(@character.aura)
     else
       self.dispose_aura
     end
     @old_aura = @character.aura
   end
 end
end

class Interpreter
 alias tdks_auras_init initialize
 def initialize(depth = 0, main = false)
   tdks_auras_init(depth, main)
   @aura_events = []
 end
 
 def aura(event_id = @event_id, type = nil)
   @aura_events.delete_if { |i| i[0] != $game_map.map_id }
   close_auras unless Auras::MULTI_AURA
   if event_id == -1
     $game_player.aura = type
   else
     $game_map.events[event_id].aura = type
   end
   @aura_events.push([$game_map.map_id, event_id])
 end
 
 def close_auras
   @aura_events.each { |i|
     if i[1] == -1
       $game_player.aura = nil
     else
       $game_map.events[i[1]].aura = nil
     end
   }
   @aura_events = []
 end
end



Instructions

All in the script.


Compatibility

None known.


Credits and Thanks




Author's Notes

None