Northern49
Member
I'm looking to change this script made by Trickster. I need it to be able to hide certain events at a certain frame number until a certain frame number. For example, call script may look like this:
Variables 102 and 103 represent the event's position on the map
109 represents the animation ID to play
1 represents the amount of times it will play
45 represents event ID to hide
7 represents which frame in the animation should the event disappear at
13 represents when the event is redisplayed, if omitted, redisplays at the end of the animation, 0 if the event is never to be reappeared
This image below shows an animation I've created that is currently called using Trickster's animation script @ its X and Y coordinates. When the target hits 7 frames, previously, using the "show animation" event command, the target would disappear, and in its place would be the same actor though shooting his weapon. When the shooting ends, the event redisplays.
This method is used in conjunction with a custom battle system I am programming. Help would be greatly appreciated.
http://img527.imageshack.us/img527/5774 ... en1ov5.png[/img]
Animation script, followed by association script, and by call script:
Code:
animation3 =
Animation.new('screen',
$game_variables[102],
$game_variables[103],109,1, 45, 7, 13)
$animations.push(animation3)
Variables 102 and 103 represent the event's position on the map
109 represents the animation ID to play
1 represents the amount of times it will play
45 represents event ID to hide
7 represents which frame in the animation should the event disappear at
13 represents when the event is redisplayed, if omitted, redisplays at the end of the animation, 0 if the event is never to be reappeared
This image below shows an animation I've created that is currently called using Trickster's animation script @ its X and Y coordinates. When the target hits 7 frames, previously, using the "show animation" event command, the target would disappear, and in its place would be the same actor though shooting his weapon. When the shooting ends, the event redisplays.
This method is used in conjunction with a custom battle system I am programming. Help would be greatly appreciated.
http://img527.imageshack.us/img527/5774 ... en1ov5.png[/img]
Animation script, followed by association script, and by call script:
Code:
=begin
┌──────────────────────────────────────â”
│◠Display Animations 2.0 │
│ │
│ Created By │
│ │
│ Trickster (tricksterguy@hotmail.com)│
│ │
│ │
└──────────────────────────────────────┘
â–ºIntro
This script will allow you to display an animation at any (x,y) position or
any tile so you will not have to use blank events to display an animation at
that tile
â–ºInstructions
Add this above main.
Calling
$animations.push(Animation.new(type,x,y,id[,loop,sound,viewport]))
anything within the [] is optional
type is the type of animation use either 1,2,3 or 'screen','tile','map'
1 or 'screen' follows the player it stays on the screen
2 or 'tile' stays at a particular tile (x,y)
3 or 'map' stays at a particular position (x,y) on the map
4 or 'player' follows the player (x,y) defines the offset
5 or 'event' follows an event (use x parameter for id and [x,y] for offset)
id is the animation id to play
Optional
loop is the number of times to play the animation
set this to nil an the animation plays forever
the default value is 1
sound set to true and you will hear the animation's sounds
set this to false and the sounds will not play
the default value is true
viewport is the animations viewport the default is the whole screen
=end
#==============================================================================
# ** Animation
#------------------------------------------------------------------------------
# This class displays an animation, it can be displayed at any (x,y) rather than
# using the show animation event command and being restricted to displaying it
# on an event.
#==============================================================================
class Animation
#--------------------------------------------------------------------------
# * Static (Class) Variables
#--------------------------------------------------------------------------
@@animations = []
@@reference_count = {}
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :x
attr_accessor :y
attr_accessor :z
attr_accessor :ox
attr_accessor :oy
attr_accessor :loop
attr_accessor :sound
attr_accessor :flash
attr_accessor :hit
attr_accessor :viewport
attr_accessor :visible
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(type, x, y, id, loop = 1, sound = true, flash = true, hit = true,
viewport = nil)
# Setup Type of Animation Display
@type = type
# Initialize Offset X and Offset Y and Z
@ox, @oy, @z = 0,0,2000
# Set Visiblility to true
@visible = true
# Branch Out According to Type
case type
when 'screen','map',1,3
# When Screen or Map or 1 or 3 Set X and Y to given coordinates
@x, @y = x, y
when 'tile',2
# When Tile or 2 Set X and Y to real coordinates
# Convert Tile coordinates to Screen coordinates
@x, @y = (x % $game_map.width) * 128, (y % $game_map.height) * 128
when 'player',4
# When Player or 4 Set Offset X and Y to Coordinates Given
@battler = $game_player
@ox, @oy = x, y
when 'event',5
# When Event or 5 Set Offset X and Y to The Y Given (An Array)
@battler = $game_map.events[x]
@ox, @oy = *y
end
# Get Animation
@animation = $data_animations[id]
# If animation is nil then return
return if @animation.nil?
# Initialize looping sound and viewport
@loop, @sound, @viewport = loop, sound, viewport
# If there is no battler then hit is false
@hit = @battler == nil ? false : hit
# Initialize Animation
animation
end
#--------------------------------------------------------------------------
# * Animation Initialize
#--------------------------------------------------------------------------
def animation
# Dispose any old Animation
dispose_animation
# Setup Duration
@animation_duration = @animation.frame_max
# Get Animation Name and Hue
animation_name = @animation.animation_name
animation_hue = @animation.animation_hue
# Get Animation Bitmap
bitmap = RPG::Cache.animation(animation_name, animation_hue)
# Increase or Setup Reference Count for Bitmap
if @@reference_count.include?(bitmap)
@@reference_count[bitmap] += 1
else
@@reference_count[bitmap] = 1
end
# Setup Animation Sprites
@animation_sprites = []
# Prevent Duplicate Screen Animations from being played
if @animation.position != 3 or not @@animations.include?(@animation)
16.times do |i|
sprite = ::Sprite.new(self.viewport)
sprite.bitmap = bitmap
sprite.visible = false
@animation_sprites[i] = sprite
end
@@animations << @animation unless @@animations.include?(@animation)
end
# Update Animation
update_animation
end
#--------------------------------------------------------------------------
# * Update
#--------------------------------------------------------------------------
def update
# If Animation is not equal to nil and 2 frames has passed
if @animation != nil and (Graphics.frame_count % 2 == 0)
# Decrease Duration
@animation_duration -= 1
# Update animation
update_animation
end
# Clear Animations
@@animations.clear
end
#--------------------------------------------------------------------------
# * Update Animation
#--------------------------------------------------------------------------
def update_animation
# If Duration is Greater than zero or Indefinite Loop Or Looping
if @animation_duration > 0 or @loop.nil? or @loop > 1
# If Duration is Zero (For Looping)
if @animation_duration == 0
# Reset Animation Duration and Decrease Loops if not an Indefinite Loop
@animation_duration = @animation.frame_max
@loop -= 1 if !@loop.nil?
end
# Get Frame Index cell_data and position
frame_index = @animation.frame_max - @animation_duration
cell_data = @animation.frames[frame_index].cell_data
position = @animation.position
# Set Sprites for animation
animation_set_sprites(@animation_sprites, cell_data, position)
# Check Each Timing If at that frame then there is something that needs to
# Be done (Flash, Sound, etc..)
@animation.timings.each do |timing|
animation_process_timing(timing) if timing.frame == frame_index
end
else
# Dispose Animation
dispose_animation
end
end
#--------------------------------------------------------------------------
# * Dispose
#--------------------------------------------------------------------------
def dispose
dispose_animation
end
#--------------------------------------------------------------------------
# * Dispose Animation
#--------------------------------------------------------------------------
def dispose_animation
# Skip unless animations sprites is not nil (Array) and its not empty
return unless @animation_sprites != nil and not @animation_sprites.empty?
# Get a Sprite, Reduce Reference count, Dispose the bitmap if references
# are zero
sprite = @animation_sprites[0]
@@reference_count[sprite.bitmap] -= 1
sprite.bitmap.dispose if @@reference_count[sprite.bitmap] == 0
# Dispose Each Sprite
@animation_sprites.each {|sprite| sprite.dispose}
@animation_sprites.clear
@animation = nil
@disposed = true
end
#--------------------------------------------------------------------------
# * Disposed?
#--------------------------------------------------------------------------
def disposed?
return @disposed.nil? ? false : true
end
#--------------------------------------------------------------------------
# * Animation Set Sprites
#--------------------------------------------------------------------------
def animation_set_sprites(sprites, cell_data, position)
16.times do |i|
# Get Sprite and Pattern
sprite = sprites[i]
pattern = cell_data[i, 0]
# If Sprite is nil or Pattern is nil or -1
if sprite == nil or pattern == nil or pattern == -1
# Set Visibility to false unless sprite is nil
sprite.visible = false if sprite != nil
# Continue to Next Iteration
next
end
# Set Visibility
sprite.visible = self.visible
# Setup Source Rectangle
sprite.src_rect.set(pattern % 5 * 192, pattern / 5 * 192, 192, 192)
# Branch According to Type
case @type
when 'tile','map',2,3
sprite.x = (self.x - $game_map.display_x + 3) / 4 + 16
sprite.y = (self.y - $game_map.display_y + 3) / 4 + 32
when 'screen',1
sprite.x = self.x
sprite.y = self.y
when 'player','event',4,5
sprite.x = @battler.screen_x + self.ox
sprite.y = @battler.screen_y + self.oy
end
# Increase X and Y depending on position placed
sprite.x += cell_data[i, 1]
sprite.y += cell_data[i, 2]
# Setup Z to Z of the animation (Def. 2000)
sprite.z = self.z
# Setup Sprite's Offset X and Y
sprite.ox = 96
sprite.oy = 96
# Setup Other Properties
sprite.zoom_x = cell_data[i, 3] / 100.0
sprite.zoom_y = cell_data[i, 3] / 100.0
sprite.angle = cell_data[i, 4]
sprite.mirror = (cell_data[i, 5] == 1)
sprite.opacity = cell_data[i, 6]
sprite.blend_type = cell_data[i, 7]
end
end
#--------------------------------------------------------------------------
# * Animation Process Timing
#--------------------------------------------------------------------------
def animation_process_timing(timing)
# If Sound Enabled and Timing Sound Effect name is not an empty string
if timing.se.name != "" and self.sound
se = timing.se
Audio.se_play("Audio/SE/" + se.name, se.volume, se.pitch)
end
return if not hit
# IF Current Scene is Scene_Map and Battler is not nil
if $scene.is_a?(Scene_Map) and @battler != nil
# Find the character
character = $scene.spriteset.find_character(@battler)
end
return if character == nil
# Branch our according to Flash Scope
case timing.flash_scope
when 1
# Flash the Character
character.flash(timing.flash_color, timing.flash_duration * 2)
when 2
# Flash the Characters Viewport
if character.viewport != nil
character.viewport.flash(timing.flash_color, timing.flash_duration * 2)
end
when 3
# Make the Character Invisible
character.flash(nil, timing.flash_duration * 2)
end
end
#--------------------------------------------------------------------------
# * Set X Coordinate
#--------------------------------------------------------------------------
def x=(x)
sx = @battler == nil ? x : x - @battler.screen_x
if sx != 0 and @animation_sprites != nil
@animation_sprites.each {|sprite| sprite.x += sx}
end
@x = sx
end
#--------------------------------------------------------------------------
# * Set Y Coordinate
#--------------------------------------------------------------------------
def y=(y)
sy = @battler == nil ? y : y - @battler.screen_y
if sy != 0 and @animation_sprites != nil
@animation_sprites.each {|sprite| sprite.y += sy}
end
@y = sy
end
end
class Scene_Map
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_reader :spriteset
end
class Spriteset_Map
#--------------------------------------------------------------------------
# * Find Character
#--------------------------------------------------------------------------
def find_character(char)
@character_sprites.each do |character|
return character if character.character == char
end
end
end
Code:
$animations = []
class Scene_Map
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
alias animation_main main
def main
@animations = []
animation_main
($animations + @animations).each {|anim| anim.dispose}
$animations.clear
end
#--------------------------------------------------------------------------
# * Update
#--------------------------------------------------------------------------
alias animation_update update
def update
$animations.each do |anim|
anim.update
$animations.delete(anim) if anim.disposed?
end
@animations.each do |anim|
anim.update
@animations.delete(anim) if anim.disposed?
end
animation_update
end
end
=begin
For any Scene
Use @animations << <animation> instead of the global, the global is there
for "noob-friendliness"
class Scene_(WHATEVER)
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
alias animation_main main
def main
@animations = []
animation_main
@animations.each {|anim| anim.dispose}
@animations.clear
end
#--------------------------------------------------------------------------
# * Update
#--------------------------------------------------------------------------
alias animation_update update
def update
@animations.each do |anim|
anim.update
@animations.delete(anim) if anim.disposed?
end
animation_update
end
end
=end
Code:
animation3 =
Animation.new('screen',
$game_variables[102],
$game_variables[103],109,1)
$animations.push(animation3)