[XP] Heretic's Lightning

Started by Heretic86, October 23, 2013, 05:08:49 am

Previous topic - Next topic


October 23, 2013, 05:08:49 am Last Edit: January 13, 2014, 09:07:17 pm by Heretic86
Heretic's Lightning
Authors: Heretic
Version: 1.0
Type: Custom Lightning Flash
Key Term: Custom Environment System


Using Change Screen Color Tone for Lightning Flashes can often lead to problems if you have another call to Change Screen Color Tone.  Typical when Transferring Maps.  This script provides a simplified solution.


  • No "Stuck" Screen Bugs or Incorrect Fades that result from any use of Change Screen Color Tone for Lightning Flashes

  • Simulates a Lightning Flash with a Script call

  • Can be used as a Base Script for other more advanced Storm Scripts

  • Includes an easy way to Randomize Volume and Pitch for Thunder Sound Effects


No Screenshots.  The Game Screen lights up then goes back to dark.  Its Lightning!  What can I say?


No Demo.

Not entirely true.  Script does have a Demo, but the Demo contains a bunch of other scripts and hundreds of NPC's and many Maps.  Only one of those NPC's gives a Demo for the Lightning Flash effect.  Demo is my "Collection of 100% Compatible Scripts", and the NPC that provides the Demo is on the Beach Map where the Demo begins.

See my Signature for the Download Link of the "Collection Demo" at the bottom of this post.


Place above Main.  Can go above everything except the Default Scripts and any other Scripts that fully redefine Game_Screen Initialize or Game_Screen Update.

Spoiler: ShowHide
#           Heretic's Lightning [XP]
#           Authors: Heretic
#           Version 1.0
#           Date: Monday, October 21st, 2013
#  The purpose of this script is to allow a Lightning Flash on the Screen
#  without using "Change Screen Color Tone".  The reason this is important
#  is that "Change Screen Color Tone" calls may conflict with using that
#  command to simulate Lightning for other purposes such as Transferring
#  between Maps.  It also fixes some issues where going into a Battle
#  where Lightning is controlled by Events causes the Screen to "get stuck"
#  Movie Lightning typically has one Bright Flash, returns to Normal Color
#  then a Secondary Flash that fades out slowly.  This script will simulate
#  that instead of needing to use the aforementioned "Change Screen Color
#  Tone" due to the inherit problems with Battles, Events, and Transfers
#  if you Fade to Black when changing maps like I do.
#  ---  Usage  ---
#  This script is simple
#  * lightning(duration) from an Event Script
#  * se_thunder(volume, pitch, filename[default 061-Thunderclap01])
#  ---  Thunder Sound Effects ---
#  I wanted a way to make Thunder Sound Effects play with a bit more variation
#  so I added "se_thunder(volume, pitch)" to allow for easier manipulation
#  of Thunder Sounds.  Its useful because you can throw Variables into the
#  arguments instead of always using a Static Number every time.  This allows
#  you to do something like this:
#  **  Event Script  **
#  pitch = rand(100) + 50
#  se_thunder(100, pitch)
#  This gives pitch a random number between 50 and 150 so the Pitch of the
#  sound of your Thunder can vary every time the Sound Effect Plays.
#  ---  Change Screen Color Tone  ---
#  The real purpose of this script is to prevent Change Screen Color Tone from
#  getting messed up by using it for both Lightning Flashes and any other time
#  that it is called.  This means that calling "Change Screen Color Tone" with
#  a Duration of say 30 Frames, then calling it again during that 30 Frames
#  causes either One or the Other to run, which is where Conflicts and Problems
#  come from.  If you have a Lightning Flash and the Player triggers "Change
#  Screen Color Tone", then "Change Screen Color Tone" will OVERRIDE the
#  Lightning Flash and your Screen should NEVER get messed up as a result.

# Version Number
$heretics_lightning = 1.0

# ** Game_Screen
#  This class handles screen maintenance data, such as change in color tone,
#  flashing, etc. Refer to "$game_screen" for the instance of this class.
class Game_Screen
 # * Initialization for Game_Screen - Alias
 unless method_defined?(:lightning_flash_game_screen_initialize)
   alias lightning_flash_game_screen_initialize initialize
 def initialize
   # Call Original or Other Aliases
   # New Properties
   @lightning_duration = 0
   @lightning = 0
 # * Start Changing Color Tone
 #     tone : color tone
 #     duration : time
 unless method_defined?(:lightning_flash_start_tone_change)
   alias lightning_flash_start_tone_change start_tone_change
 def start_tone_change(tone, duration)
   # Call Original or Other Aliases
   lightning_flash_start_tone_change(tone, duration)
   # Clear any Lightning Flashes - Half of fixing Color Tone Screw Ups
   @lightning_duration = 0
   @lightning = 0
   @last_tone = nil
 # * Frame Update for Game_Screen
 unless method_defined?(:lightning_flash_game_screen_update)
   alias lightning_flash_game_screen_update update
 def update
   # Call Original or Other Aliases
   # If Lightning
   if @lightning_duration > 0
     # First Flash - Fully Grayed Out - Tone(R,G,B, Grayscale)
     if @lightning_duration == @lightning
       # Change Tone to Lightning Flash Tone
       @tone = Tone.new(34, 34, 51, 255)
     # End First Flash - Return to Last Color Tone
     elsif @lightning_duration == @lightning - 2
       # Set Tone to Last Tone
       @tone = @last_tone
     # Second Flash - Slightly Grayed Out - Tone(R,G,B, Grayscale)
     elsif @lightning_duration == @lightning - 6
       # Change Tone to Lightning Flash Tone
       @tone = Tone.new(34, 34, 51, 224)      
     # Lightning Flash Fade - Fade from Flash to Tone Target
     # This is half of what fixes Color Tone Screw Ups
     elsif @lightning_duration < @lightning - 6
       d = @lightning_duration
       @tone.red = (@tone.red * (d - 1) + @tone_target.red) / d
       @tone.green = (@tone.green * (d - 1) + @tone_target.green) / d
       @tone.blue = (@tone.blue * (d - 1) + @tone_target.blue) / d
       @tone.gray = (@tone.gray * (d - 1) + @tone_target.gray) / d
     # Countdown
     @lightning_duration -= 1
 # * Lightning
 #     duration : time in Frames
 def lightning(duration=30)
   # Error Checking
   if (not duration.is_a?(Integer) or duration < 1) and $DEBUG
     # Display Error
     print "Warning: lightning(duration) expects\n",
           "duration to be a Positive Number!\n\n",
           "lightning(\"", duration, "\") Ignored!"
     # Prevent Execution of Lightning
   # If there is no Current Lightning Flash
   if @lightning_duration == 0 or @last_tone.nil?
     # Store Last Tone
     @last_tone = @tone_target.clone
   # Set up Lightning Animation Values (+6 is offset for First Flash)
   @lightning_duration = duration * 2 + 6
   @lightning = duration * 2

# ** Interpreter
class Interpreter
 # * Lightning
 #     duration : time in Frames
 def lightning(duration)
   # Call Game Screen for Command Execution
 # * Thunder
 #     volume : Numeric Value between 0 and 100 at which SE will Play
 #     pitch  : Numeric Value that SE will Play.  100 for Normal Pitch
 #     file   : Sound Effect File Name in SE Database
 #   - Plays Thuder Sound Effect with Variations on Volume and Pitch
 def se_thunder(volume=100, pitch=100, file='061-Thunderclap01')
   # Call Game Screen for Command Execution (order is different than args)
   thunder = RPG::AudioFile.new(file, volume, pitch)
   # Play Sound


In an Event Script, just run "lightning(30)" for a Lightning Flash that takes 30 Frames.

NOTES: If you make any calls to "Change Screen Color Tone", it takes precedence over Lightning and the Screen will fade properly.  That is what this script is intended to fix.  The script adds 6 Frames for the First Flash.  So if you put in 30 frames, it will take 36 Frames to complete.  You can mess with this if you'd like, or change the Tone that the Screen fades to, but some knowledge of scripting will be required.

This script also includes a call for "se_thunder(volume, pitch, file[optional])"

se_thunder was created to allow you to use a Variable when playing a Thunder Sound Effect instead of having to specify Numerically what the Volume and Pitch will be.  It also defaults to '061-Thunderclap01' when no "File" is specified.

In an Event Script, do this:
# Random Volume between 80 and 100
vol = rand(20) + 80
# Random Pitch between 50 and 150
pitch = rand(100) + 50
# Play Thunder Sound
se_thunder(vol, pitch)


I don't know of any scripts this wouldn't be compatible with.  Maybe seriously exotic stuff that completely redefines Game_Screen, but even then, it should be highly compatible

Credits and Thanks

  • Folders Coffee

  • Five Hour Energy

  • Totinos Pizza

Author's Notes

This script is mainly intended for people not too familiar with RMXP, or anyone else that has experienced a "Stuck Screen" glitch where using "Change Screen Color Tone" has ever caused their game to get "Stuck" on the bright part of a Lightning Flash.  Change Screen Color Tone isnt really intended for making Lightning Flashes due to the fact that multiple calls to Change Screen Color Tone are necessary to create that "Hollywood Lightning" type of flash.  When one is executed and another is not is what causes the Screen to get stuck.  This happens when Transferring Maps during a Lightning Flash.  It doesnt happen every time and can be difficult to diagnose the cause.

The "Style" of this script uses "Hollywood Lightning", where the screen will flash, immediatly go dark, then flash again with a slow fade to the original color.

Not sure about VX / Ace compatability as usual.  So expect a few revisions for forward compatability.
Current Scripts:
Heretic's Moving Platforms

Current Demos:
Collection of Art and 100% Compatible Scripts

(Script Demos are all still available in the Collection link above.  I lost some individual demos due to a server crash.)