Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

> SAI Custom Event Commands, Advanced screen tones, panoramas, pictures, and more
Sailerius
post Jun 11 2011, 12:52 AM
Post #1


Blue Blue Glass Moon
Group Icon

Group: Revolutionary
Posts: 881
Type: Developer
RM Skill: Beginner





Version: 1.0
Author: Bishop Myers ("Sailerius")
Release Date: June 11, 2011


Introduction
Adds some new features to some familiar event commands as well as restored lost functionality from outdated RPG Maker engines.

Features
*Diagonal Map Scrolling: Easily scroll maps diagonally instead of in only one direction at a time.
*Advanced Screen Tones: Memorize, restore, and save screen tones as well as define easy-to-use presets.
*Vertical Screen Shake: Shake the screen instead of, or at the same time as, shaking it horizontally.
*Advanced Picture Placement: Place pictures beneath characters instead of on top of them for advanced visual effects.
*Scroll Panorama: Move the panorama or set it to move automatically.

Script
Script
CODE
#===============================================================================
# ** SAI Custom Event Commands
#-------------------------------------------------------------------------------
# Author: Bishop Myers ("Sailerius")
# Version: 1.0
# Date: 2011.06.10
# SDK Version: 2.4 - Part II
#===============================================================================
# Instructions
# ------------------------------------------------------------------------------
# Call any of these new methods in a Call Script event to use them.
# ------------------------------------------------------------------------------
# Advanced Map Scrolling
# ------------------------------------------------------------------------------
#   scroll_down_left(x)
#   scroll_down(x)
#   scroll_down_right(x)
#   scroll_left(x)
#   scroll_right(x)
#   scroll_up_left(x)
#   scroll_up(x)
#   scroll_up_right(x)
# Calling any of these methods will scroll the map screen by x tiles in the
# respective direction. You can optionally give a second parameter to specify
# a scroll speed. If none is given, it will default to 4.
# Example: scroll_up_left(10, 6) will scroll the map up and to the left by 10
# tiles at a speed of 6.
# ------------------------------------------------------------------------------
# Advanced Screen Tones
# ------------------------------------------------------------------------------
#   save_tone(name)
# Calling this method will save the current screen tone and remember it with
# the name you gave it. In order to use that tone again, call show_tone and
# supply it with the same name you used to save it.
#
#   restore_tone(x)
# Calling this method will restore the memorized screen tone. The transition
# will take x frames.
#
#   show_tone(name, x)
# Calling this method will bring back a saved screen tone with the name you
# supply it with. The transition will take x frames.
#
#   memorize_tone
# Calling this method will memorize the current screen tone without saving it.
# The memorized screen tone will be overwritten the next time this method is
# called.
#
#   black(x)
# This method is a shortcut that will fade the screen to black. The transition
# will take x frames.
#
#   white(x)
# This method is a shortcut that will fade the screen to white. The transition
# will take x frames.
#
#   darken(strength, x)
# Calling this method will darken the current screen tone by the strength
# given, which must be a number between 0-255. The transition will take x
# frames.
#
#   lighten(strength, x)
# Calling this method will lighten the current screen tone by the strength
# given, which must be a number between 0-255. The transition will take x
# frames.
# ------------------------------------------------------------------------------
# Advanced Screen Shake
# ------------------------------------------------------------------------------
#   shake(x, y, speed, duration)
# Calling this method will shake the screen horizontally with a power of x and
# vertically with a power of y at the given speed and for the given duration.
# x, y and speed should be from 1-9 with 9 being the strongest.
# ------------------------------------------------------------------------------
# Pictures Under People
# ------------------------------------------------------------------------------
#   pup(x)
# Calling this method will cause picture number x to appear beneath characters.
# ------------------------------------------------------------------------------
# Move Panorama
# ------------------------------------------------------------------------------
#   move_pan(x, y)
# Calling this method will cause the map's panorama to begin moving at a
# horizontal speed of x and a vertical speed of y.
#
#   auto_move_pan(x, y)
# Calling this method will cause the map's panorama to automatically move at a
# horizontal speed of x and a vertical speed of y. To stop a panorama from
# moving, just call this with an x and y value of 0.
# You can set a map to automatically scroll its panorama by adding an entry
# manually to the Configuration section below.
#===============================================================================

#-------------------------------------------------------------------------------
# * SDK Log
#-------------------------------------------------------------------------------
SDK.log('SAI Custom Event Commands', 'Sailerius', 1.0, '2011.05.10')
SDK.log_overwrite(:Game_Map, :update_scrolling)

module SAI
  #-----------------------------------------------------------------------------
  # * Configuration
  #-----------------------------------------------------------------------------
  # Advanced Screen Tones
  #   Define preset screen tones here.
  #-----------------------------------------------------------------------------
  TONES = {
    'default' => Tone.new(0, 0, 0, 0),
    'black' => Tone.new(-255, -255, -255, 0),
    'white' => Tone.new(255, 255, 255, 0),
    'gray' => Tone.new(0, 0, 0, 255)
  }
  
  #-----------------------------------------------------------------------------
  # Move Panorama
  #   Specify which maps automatically have a scrolling panorama here.
  #   Entries should follow this format:
  #     map ID => [horizontal speed, vertical speed]
  #   For example, 3 => [2, 1] means that map #3 will scroll its panorama at a
  #   speed of 2 horizontally and 1 vertically.
  #-----------------------------------------------------------------------------
  MOVING_PANORAMA_MAPS = {
    #3 => [2, 1]
    1 => [3, 2]
  }
  MOVING_PANORAMA_MAPS.default = [0, 0]
end

#===============================================================================
# ** Game_Map
#===============================================================================
class Game_Map  
  #-----------------------------------------------------------------------------
  # * Alias Listings
  #-----------------------------------------------------------------------------
  alias_method :sailerius_saicec_gamemap_setup,  :setup
  alias_method :sailerius_saicec_gamemap_update, :update
  
  #-----------------------------------------------------------------------------
  # * Public Instance Variables
  #-----------------------------------------------------------------------------
  attr_reader   :panorama_ox
  attr_reader   :panorama_oy
  
  #-----------------------------------------------------------------------------
  # * Setup
  #     map_id : map ID
  #-----------------------------------------------------------------------------
  def setup(map_id)
    sailerius_saicec_gamemap_setup(map_id)
    @panorama_ox = 0
    @panorama_oy = 0
  end
  
  #--------------------------------------------------------------------------
  # * Move Panorama
  #     xdist : horizontal distance
  #     ydist : vertical distance
  #--------------------------------------------------------------------------
  def move_panorama(xdist, ydist)
    @panorama_ox += xdist
    @panorama_oy += ydist
  end
  
  #-----------------------------------------------------------------------------
  # * Update Scrolling
  #-----------------------------------------------------------------------------
  def update_scrolling
    # If scrolling
    if @scroll_rest > 0
      # Change from scroll speed to distance in map coordinates
      distance = 2 ** @scroll_speed
      # Execute scrolling
      case @scroll_direction            
      when 1  # Down-left
        scroll_down(distance)
        scroll_left(distance)
      when 2  # Down
        scroll_down(distance)
      when 3  # Down-right
        scroll_down(distance)
        scroll_right(distance)
      when 4  # Left
        scroll_left(distance)
      when 6  # Right
        scroll_right(distance)
      when 7  # Up-left
        scroll_up(distance)
        scroll_left(distance)
      when 8  # Up
        scroll_up(distance)
      when 9  # Up-right
        scroll_up(distance)
        scroll_right(distance)      
      end            
      # Subtract distance scrolled
      @scroll_rest -= distance
    end
  end  
  
  #-----------------------------------------------------------------------------
  # * Update
  #-----------------------------------------------------------------------------
  def update
    sailerius_saicec_gamemap_update
    move_panorama(SAI::MOVING_PANORAMA_MAPS[@map_id][0],
      SAI::MOVING_PANORAMA_MAPS[@map_id][1])
  end
end

#===============================================================================
# ** Game_Screen
#===============================================================================
class Game_Screen
  #-----------------------------------------------------------------------------
  # * Alias Listings
  #-----------------------------------------------------------------------------
  alias_method :sailerius_saicec_gamescreen_initialize, :initialize
  alias_method :sailerius_saicec_gamescreen_start_shake, :start_shake
  alias_method :sailerius_saicec_gamescreen_update, :update
  
  #-----------------------------------------------------------------------------
  # * Public Instance Variables
  #-----------------------------------------------------------------------------
  attr_reader   :shake_vert                  # vertical shake positioning
  attr_reader   :pupped_pictures             # array of lowered pictures
  
  #-----------------------------------------------------------------------------
  # * Initialize
  #-----------------------------------------------------------------------------
  def initialize
    sailerius_saicec_gamescreen_initialize    
    @memorized_tone = @tone.clone
    # Initialize vertical shaking attributes
    @shake_vert = 0
    @shake_vert_power = 0
    @shake_vert_direction = 1
    # Initialized lowered pictures
    @pupped_pictures = []
  end
  
  #-----------------------------------------------------------------------------
  # * Start Shaking
  #     power : horizontal strength
  #     speed : speed
  #     duration : time
  #     power_vert : vertical strength
  #-----------------------------------------------------------------------------
  def start_shake(power, speed, duration, power_vert = 0)  
    sailerius_saicec_gamescreen_start_shake(power, speed, duration)
    @shake_vert_power = power_vert
  end
  
  #-----------------------------------------------------------------------------
  # * Save Screen Tone
  #     name : New screen tone name
  #-----------------------------------------------------------------------------
  def save_tone(name)
    SAI::TONES[name] = @tone.clone
    return true
  end
  
  #-----------------------------------------------------------------------------
  # * Restore Screen Tone
  #     duration : Duration of screen tone transition
  #-----------------------------------------------------------------------------
  def restore_tone(duration)
    start_tone_change(@memorized_tone, duration)
    return true
  end
  
  #-----------------------------------------------------------------------------
  # * Show Stored Screen Tone
  #     name : Name of saved screen tone to restore
  #     duration : Duration of screen tone transition
  #-----------------------------------------------------------------------------
  def show_tone(name, duration)
    tone = SAI::TONES[name]
    unless tone.nil?
      start_tone_change(tone, duration)
    end
    return true
  end
  
  #-----------------------------------------------------------------------------
  # * Memorize Screen Tone
  #-----------------------------------------------------------------------------
  def memorize_tone
    @memorized_tone = @tone.clone
    return true
  end
  
  #-----------------------------------------------------------------------------
  # * Darken Screen Tone
  #     amount : Amount to darken the screen (0-255)
  #     duration : Duration of screen tone transition
  #-----------------------------------------------------------------------------
  def darken_tone(amount, duration)
    tone = @tone.clone
    tone.red -= amount
    tone.green -= amount
    tone.blue -= amount
    start_tone_change(tone, duration)
    return true
  end
  
  #-----------------------------------------------------------------------------
  # * Pictures Under People
  #     picture : Number of the picture to push down
  #-----------------------------------------------------------------------------
  def pup(picture)
    @pupped_pictures.push(picture)
  end
  
  #-----------------------------------------------------------------------------
  # * Frame Update
  #-----------------------------------------------------------------------------
  def update
    sailerius_saicec_gamescreen_update
    # Vertical shaking support
    if @shake_duration >= 1 or @shake_vert != 0
      delta = (@shake_vert_power * @shake_speed * @shake_vert_direction) / 10.0
      if @shake_duration <= 1 and @shake_vert * (@shake_vert + delta) < 0
        @shake_vert = 0
      else
        @shake_vert += delta
      end
      if @shake_vert > @shake_vert_power * 1.5
        @shake_vert_direction = -1
      end
      if @shake_vert < - @shake_vert_power * 1.5
        @shake_vert_direction = 1
      end
    end
  end
end

#===============================================================================
# ** Scene_Map
#===============================================================================
class Scene_Map
  #-----------------------------------------------------------------------------
  # * Public Instance Variables
  #-----------------------------------------------------------------------------
  attr_accessor   :spriteset                
end

#===============================================================================
# ** Spriteset_Map
#===============================================================================
class Spriteset_Map
  #-----------------------------------------------------------------------------
  # * Alias Listings
  #-----------------------------------------------------------------------------
  alias_method :sailerius_saicec_spritesetmap_update, :update
  alias_method :sailerius_saicec_spritesetmap_initialize, :initialize
  
  #-----------------------------------------------------------------------------
  # * Initialize
  #-----------------------------------------------------------------------------
  def initialize
    sailerius_saicec_spritesetmap_initialize
    for i in $game_screen.pupped_pictures
      @picture_sprites[i - 1].dispose
      @picture_sprites[i - 1] = Sprite_Picture.new(@viewport1,
      $game_screen.pictures[i])
    end
  end
  
  #-----------------------------------------------------------------------------
  # * Update
  #-----------------------------------------------------------------------------
  def update
    @viewport1.oy = $game_screen.shake_vert
    sailerius_saicec_spritesetmap_update
    @panorama.ox += $game_map.panorama_ox
    @panorama.oy += $game_map.panorama_oy
  end
  
  #-----------------------------------------------------------------------------
  # * Push Picture Down
  #     picture : Number of the picture to push down
  #-----------------------------------------------------------------------------
  def push_picture_down(picture)
    @picture_sprites[picture - 1].dispose
    @picture_sprites[picture - 1] = Sprite_Picture.new(@viewport1,
      $game_screen.pictures[picture])
  end
end

#===============================================================================
# ** Spriteset_Battle
#===============================================================================
class Spriteset_Battle
  #-----------------------------------------------------------------------------
  # * Alias Listings
  #-----------------------------------------------------------------------------
  alias_method :sailerius_saicec_spritesetbattle_update, :update
  
  #-----------------------------------------------------------------------------
  # * Update
  #-----------------------------------------------------------------------------
  def update
    @viewport1.oy = $game_screen.shake_vert
    sailerius_saicec_spritesetbattle_update
  end
end

#===============================================================================
# ** Sprite_Picture
#===============================================================================
class Sprite_Picture < Sprite
  #-----------------------------------------------------------------------------
  # * Alias Listings
  #-----------------------------------------------------------------------------
  alias_method :sailerius_saicec_spritepicture_update, :update
  
  #-----------------------------------------------------------------------------
  # * Update
  #-----------------------------------------------------------------------------
  def update
    sailerius_saicec_spritepicture_update
    if $game_screen.pupped_pictures.include?(@picture.number)
      self.z = 0
    end
  end
end

#===============================================================================
# ** Interpreter
#===============================================================================
class Interpreter
  #-----------------------------------------------------------------------------
  # * Scroll Down-left
  #-----------------------------------------------------------------------------
  def scroll_down_left(distance, speed = 4)
    $game_map.start_scroll(1, distance, speed)
  end
  
  #-----------------------------------------------------------------------------
  # * Scroll Down
  #-----------------------------------------------------------------------------
  def scroll_down(distance, speed = 4)
    $game_map.start_scroll(2, distance, speed)
  end
  
  #-----------------------------------------------------------------------------
  # * Scroll Down-right
  #-----------------------------------------------------------------------------
  def scroll_down_right(distance, speed = 4)
    $game_map.start_scroll(3, distance, speed)
  end
  
  #-----------------------------------------------------------------------------
  # * Scroll Left
  #-----------------------------------------------------------------------------
  def scroll_left(distance, speed = 4)
    $game_map.start_scroll(4, distance, speed)
  end
  
  #-----------------------------------------------------------------------------
  # * Scroll Right
  #-----------------------------------------------------------------------------
  def scroll_right(distance, speed = 4)
    $game_map.start_scroll(6, distance, speed)
  end
  
  #-----------------------------------------------------------------------------
  # * Scroll Up-left
  #-----------------------------------------------------------------------------
  def scroll_up_left(distance, speed = 4)
    $game_map.start_scroll(7, distance, speed)
  end  
  
  #-----------------------------------------------------------------------------
  # * Scroll Up
  #-----------------------------------------------------------------------------
  def scroll_up(distance, speed = 4)
    $game_map.start_scroll(8, distance, speed)
  end  
  
  #-----------------------------------------------------------------------------
  # * Scroll Up-right
  #-----------------------------------------------------------------------------
  def scroll_up_right(distance, speed = 4)
    $game_map.start_scroll(9, distance, speed)
  end
  
  #-----------------------------------------------------------------------------
  # * Save Current Screen Tone
  #-----------------------------------------------------------------------------
  def save_tone(name)
    $game_screen.save_tone(name)
  end
  
  #-----------------------------------------------------------------------------
  # * Restore Memorized Screen Tone
  #-----------------------------------------------------------------------------
  def restore_tone(name, duration)
    $game_screen.restore_tone(name, duration)
  end
  
  #-----------------------------------------------------------------------------
  # * Show Saved Screen Tone
  #-----------------------------------------------------------------------------
  def show_tone(name, duration)
    $game_screen.show_tone(name, duration)
  end
  
  #-----------------------------------------------------------------------------
  # * Memorize Current Screen Tone
  #-----------------------------------------------------------------------------
  def memorize_tone
    $game_screen.memorize_tone
  end
  
  #-----------------------------------------------------------------------------
  # * Fade to Black
  #-----------------------------------------------------------------------------
  def black(duration)
    $game_screen.show_tone('black', duration)
  end
  
  #-----------------------------------------------------------------------------
  # * Fade to White
  #-----------------------------------------------------------------------------
  def white(duration)
    $game_screen.show_tone('white', duration)
  end
  
  #-----------------------------------------------------------------------------
  # * Darken Screen Tone
  #-----------------------------------------------------------------------------
  def darken(amount, duration)
    $game_screen.darken_tone(amount, duration)
  end
  
  #-----------------------------------------------------------------------------
  # * Lighten Screen Tone
  #-----------------------------------------------------------------------------
  def lighten(amount, duration)
    $game_screen.darken_tone(-amount, duration)
  end
  
  #-----------------------------------------------------------------------------
  # * Shake Screen
  #-----------------------------------------------------------------------------
  def shake(horizontal, vertical, speed, duration)
    $game_screen.start_shake(horizontal, speed, duration, vertical)
  end
  
  #-----------------------------------------------------------------------------
  # * Pictures Under People
  #-----------------------------------------------------------------------------
  def pup(picture)
    $scene.spriteset.push_picture_down(picture)
  end
  
  #-----------------------------------------------------------------------------
  # * Move Panorama
  #-----------------------------------------------------------------------------
  def move_pan(x, y)
    $game_map.move_panorama(x, y)
  end
  
  #-----------------------------------------------------------------------------
  # * Automatically Move Panorama
  #-----------------------------------------------------------------------------
  def auto_move_pan(x, y)
    SAI::MOVING_PANORAMA_MAPS[$game_map.map_id][0] = x
    SAI::MOVING_PANORAMA_MAPS[$game_map.map_id][1] = y
  end
end


Customization
The configuration section explains how to add preset screen tones as well as how to set maps to have automatically scrolling panoramas. Simply add your own entries like the examples do.


Compatibility
Requires SDK v2.4 to function. As such, it should be compatible with any other SDK script.


DEMO
Coming soon!


Installation
Paste below the SDK script.


FAQ
Q: How do I use this?
A: Simply add a Call Script action to an event and use one of the event commands as detailed in the Instructions section of the script. For example, to use the advanced screen shake method, just enter shake(6, 8, 9, 9) or with whatever numbers you want to use. When in doubt, read the instructions!


Terms and Conditions
This script is free for all use, including commercial.


Credits
Please give credit to Bishop Myers ("Sailerius") if you use this script.

This post has been edited by Sailerius: Jun 13 2011, 03:02 PM


__________________________
Go to the top of the page
 
+Quote Post
   

Posts in this topic
- Sailerius   SAI Custom Event Commands   Jun 11 2011, 12:52 AM


Closed TopicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 21st May 2013 - 10:53 PM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker