iPhone App Directory
RPG Maker VX
 
Gallery Members Search Calendar Help


Welcome Guest ( Log In | Register )

Collapse

>Announcement

Keep an eye out for the upcoming 3rd Quarter Contest!
3 Pages V   1 2 3 >  
Reply to this topicStart new topic
> Lighting System for Caves and Spooky Areas, Moving light sources, easy to use
Rating 5 V
Raoul589
post Dec 6 2010, 10:08 PM
Post #1



Group Icon


Type: Coder
Alignment: Chaotic Good




Lighting System For Caves and Spooky Areas

by Raoul589



Introduction

This script is used to create a dark ambience with light sources. Good for puzzles and atmosphere. Check the screenshots below.


Features

- Easy script methods for adding and removing light sources, and setting light level
- Three types of light source:
-> Attach a light source to the player (e.g. for a lantern)
-> Attach a light source to an arbitrary location on the map
-> Attach a light source to an event. The light source will move with the event.
- Support for lightning effects
- The size and shape of the light sources can be customised
- Compatible with all menus and the standard battle system (quite possibly non-standard ones too)
- Full and detailed usage documentation
- If you are careful, compatible with most any other script


Screenshots

Spoiler:

Spoiler:

Spoiler:

Spoiler:



How to Install:

This bit has a few instructions, but remain calm. They are individually quite simple, and we'll step through them.

- Paste the main script code into the "materials" section of the script editor. Above Main and below the other stuff.

- Bear with me here. We need to add 4 lines to the core classes. Don't worry, it won't hurt the engine in any way. Firstly, add the following lines to the Scene_Base script:

Spoiler:
CODE
def start
      # THE LINE BELOW WAS ADDED
      $lights.updateframe if !$lights.nil? # THIS LINE WAS ADDED
      # THE LINE ABOVE WAS ADDED
end

def update
# THE LINE BELOW WAS ADDED
$lights.updateframe if !$lights.nil? # THIS LINE WAS ADDED
# THE LINE ABOVE WAS ADDED
end


Now, add the following lines to the Scene_File script:

Spoiler:
CODE
def write_save_data(file)
    characters = []
    for actor in $game_party.members
      characters.push([actor.character_name, actor.character_index])
    end
    $game_system.save_count += 1
    $game_system.version_id = $data_system.version_id
    @last_bgm = RPG::BGM::last
    @last_bgs = RPG::BGS::last
    Marshal.dump(characters,           file)
    Marshal.dump(Graphics.frame_count, file)
    Marshal.dump(@last_bgm,            file)
    Marshal.dump(@last_bgs,            file)
    Marshal.dump($game_system,         file)
    Marshal.dump($game_message,        file)
    Marshal.dump($game_switches,       file)
    Marshal.dump($game_variables,      file)
    Marshal.dump($game_self_switches,  file)
    Marshal.dump($game_actors,         file)
    Marshal.dump($game_party,          file)
    Marshal.dump($game_troop,          file)
    Marshal.dump($game_map,            file)
    Marshal.dump($game_player,         file)
    # THE LINE BELOW WAS ADDED
    $lights.dump(file)          # THIS LINE WAS ADDED
    # THE LINE ABOVE WAS ADDED
end


def read_save_data(file)
characters           = Marshal.load(file)
Graphics.frame_count = Marshal.load(file)
@last_bgm            = Marshal.load(file)
@last_bgs            = Marshal.load(file)
$game_system         = Marshal.load(file)
$game_message        = Marshal.load(file)
$game_switches       = Marshal.load(file)
$game_variables      = Marshal.load(file)
$game_self_switches  = Marshal.load(file)
$game_actors         = Marshal.load(file)
$game_party          = Marshal.load(file)
$game_troop          = Marshal.load(file)
$game_map            = Marshal.load(file)
$game_player         = Marshal.load(file)
# THE LINE BELOW WAS ADDED
$lights.load(file)        # THIS LINE WAS ADDED
# THE LINE ABOVE WAS ADDED
if $game_system.version_id != $data_system.version_id
$game_map.setup($game_map.map_id)
$game_player.center($game_player.x, $game_player.y)
end
end



- Whew, we're through the tough part. Finally, put a file called "LightStamp.png" into the "Graphics/Pictures/" folder. This will determine the size and appearance of the lights in the game. If this picture is not in the folder, the script will still work, but the game will take about 30 seconds longer to start up as the game draws a default light stamp from scratch. Three sample light stamps are provided with the demo and the one used in the demo is attached.

Once you have done these things, you can use the methods provided in the script whenever you want. Go for your life. Typically, the methods are called using the form

$lights.methodname(arguments)

A full description of how to install and use the script is given in a word document in the demo called 'Lighting System Specifications'.


Demo

A demo is provided in the attachments section.



Script


Spoiler:
CODE
# Raoul589's lighting script

# Lighting interface:
#
# $lights.on
# $lights.off
# $lights.isoff
# $lights.dim(amount)
# $lights.brighten(amount)
# $lights.transition(brightness)
# $lights.flash(duration)
# $lights.setlightlevel(brightness)
# $lights.getlightlevel
# $lights.addstationarysource(x, y)
# $lights.addeventsource(event)
# $lights.addplayersource
# $lights.removeplayersource
# $lights.removesource(sourceid)
# $lights.removeallsources
#
# $lights.updateframe   // Should be called in a common event every frame
# $lights.initialize    // Don't touch this at all unless you know what it does
#
#

# default settings
LIGHTCIRC = 175
BRIGHTCIRC = 25
CENTERBRIGHTNESS = 200
CENTEROPACITY = 255 - CENTERBRIGHTNESS
# end default settings


class LightSource
  
  @x
  @y
  @width
  @height
  
  # light source constructor
  def initialize
    @x = 0
    @y = 0
    @width = $lights.truelightcirc
    @height = $lights.truelightcirc
  end
  
  # updates the light source
  def update
  end
  
  
  def getx
    return @x
  end
  
  def gety
    return @y
  end
  
  def getwidth
    return @width
  end
  
  def getheight
    return @height
  end
  
end # class end


# non-moving light source
class StationarySource < LightSource
  
  # only the stationary source is interested in the map coordinates
  @mapx
  @mapy
  
  def initialize(x, y)
    super()
    @mapx = x
    @mapy = y
    update
  end
  
  
  def update
    super()
    @x = 32 * @mapx - (@width / 2) + 16 - ($game_map.display_x / 8)
    @y = 32 * @mapy - (@height / 2) + 16 - ($game_map.display_y / 8)
  end
  
  
  def getmapx
    return @mapx
  end
  
  
  def getmapy
    return @mapy
  end
  
end # class end


# light source that moves with an event
class EventSource < LightSource
  
  @event
  
  def initialize(eventid)
    super()
    @event = $game_map.events[eventid]
    update
  end
  
  
  def update
    super()
    @x = (@event.real_x / 8) - (@width / 2) + 16 - ($game_map.display_x / 8)
    @y = (@event.real_y / 8) - (@height / 2) + 16 - ($game_map.display_y / 8)
  end
  
  def getevent
    return @event
  end
  
end # class end


# light source that moves with the player
class PlayerSource < LightSource
  
  def initialize
    super()
    update
  end
  
  def update
    super()
    @x = ($game_player.real_x / 8) - (@width / 2) +
            16 - ($game_map.display_x / 8)
    @y = ($game_player.real_y / 8) - (@height / 2) +
            16 - ($game_map.display_y / 8)
  end
  
end # class end


class Lighting

attr_accessor :truelightcirc
  
# variables which should not be externally accessed

@lightsoff
@lightlevel
@desiredlightlevel
@lightchangerate
@lightsources
@sprviewport
@bmpspr
@tintcolor
@offin

@lightstamp

@workingcolor
@workingrect

  
# methods

# this method sets up the lighting class
def initialize
  
  @lightsoff = false
  @lightlevel = 0
  @offin = 0
  @desiredlightlevel = @lightlevel
  @lightchangerate = 1
  @tintcolor = Color.new(0, 0, 0, 255 - @lightlevel)
  @workingcolor = Color.new(0,0,0,CENTEROPACITY)
  @workingrect = Rect.new(0,0,0,0)
  @lightsources = Array.new
  @pendingeventsources = nil
  
  @sprviewport = Viewport.new(0,0, 544, 416)
  @sprviewport.z = 99
  
  @lightstamp = Bitmap.new(LIGHTCIRC,LIGHTCIRC)
  @lightstamp.fill_rect(0,0,@lightstamp.width, @lightstamp.height, @workingcolor)
  
  h = @lightstamp.width / 2
  k = @lightstamp.height / 2
  halflightcirc = LIGHTCIRC / 2
  rmult = (255 - CENTEROPACITY).to_f / ((LIGHTCIRC/2) - (BRIGHTCIRC/2)).to_f
  startr = (BRIGHTCIRC / 2) - 1
  
#=begin
  if(FileTest.exist?("Graphics/Pictures/LightStamp.png"))

  @lightstamp = Bitmap.new("Graphics/Pictures/LightStamp")
    
  else    # we need to draw the circle from scratch
  
  for r in (BRIGHTCIRC/2)..(LIGHTCIRC/2)
    for x in 0..(@lightstamp.width - 1)
      for y in 0..(@lightstamp.height - 1)
        
        xy = (x - h) * (x - h) + (y - k) * (y - k)
        
        if(xy >= r * r and xy < (r + 1) * (r + 1))
          @lightstamp.set_pixel(x,y, Color.new(0,0,0, CENTEROPACITY +
                                                ((r - startr)*rmult).to_i))
        end

      end
    end
  end
  
  for x in 0..(@lightstamp.width - 1)
    for y in 0..(@lightstamp.height - 1)
      
      xy = (x - h) * (x - h) + (y - k) * (y - k)
      
      if(xy > halflightcirc * halflightcirc)
        @lightstamp.set_pixel(x,y, Color.new(0,0,0, 255))
      end
        
    end
  end
    
  end # filecheck end

  @truelightcirc = @lightstamp.width
#=end  

end

# this method should not be called directly.
def updateframe
  
  if(!@pendingeventsources.nil? and $scene.is_a?(Scene_Map))
    @pendingeventsources.each do |i|
      addeventsource(i)
    end
    @pendingeventsources = nil
  end
  
  la = true
  
  if($scene.is_a?(Scene_Battle) or $scene.is_a?(Scene_Skill) or
          $scene.is_a?(Scene_Item) or $scene.is_a?(Scene_Title) or
              $scene.is_a?(Scene_Shop) or $scene.is_a?(Scene_Gameover) or
                $scene.is_a?(Scene_File) or $scene.is_a?(Scene_End))
   v = Viewport.new(0,0,544, 416)
   v.z = -1
   @bmpspr.viewport = v if (!@bmpspr.nil? and !@bmpspr.disposed?)
   la = false
  end
  
  if(@lightsoff == true and la)
    
    if(@lightlevel != @desiredlightlevel)
      if(@lightlevel < @desiredlightlevel)
        @lightlevel += @lightchangerate
        if(@lightlevel > @desiredlightlevel)
          @lightlevel = @desiredlightlevel.to_i
          @desiredlightlevel = @desiredlightlevel.to_i
        end
      end
      if(@lightlevel > @desiredlightlevel)
        @lightlevel -= @lightchangerate
        if(@lightlevel < @desiredlightlevel)
          @lightlevel = @desiredlightlevel.to_i
          @desiredlightlevel = @desiredlightlevel.to_i
        end
      end
      @tintcolor.set(0, 0, 0, 255 - @lightlevel)
    end
    
    @bmpspr.bitmap.dispose if (!@bmpspr.nil? and !@bmpspr.disposed?)
    @bmpspr.dispose if (!@bmpspr.nil? and !@bmpspr.disposed?)
    @bmpspr = Sprite.new(@sprviewport)
    @bmpspr.bitmap = Bitmap.new(544, 416)
    
    #@bmpspr.bitmap.clear
    @bmpspr.bitmap.fill_rect(0, 0, 544, 416, @tintcolor)
    
    @workingcolor = Color.new(0, 0, 0, 0)
    
    @lightsources.each do |ls|
      ls.update
      @bmpspr.bitmap.fill_rect(ls.getx, ls.gety,
                                ls.getwidth, ls.getheight, @workingcolor)
      @workingrect.set(0, 0, @lightstamp.width, @lightstamp.height)
      @bmpspr.bitmap.blt(ls.getx, ls.gety, @lightstamp,
                          @workingrect, @tintcolor.alpha)
    end
                        
  end
  
  if(@lightsoff == false)
    if(@offin != 0)
      @offin -= 1
      if @offin <= 0
        @offin = 0
        off
      end
    end
  end
  
end

# turn lights on; normal lighting
def on
  
  if(@lightsoff == false)
    return
  end
  
  @bmpspr.bitmap.dispose
  @bmpspr.dispose
  @lightsoff = false
  
end

# turn lights off; this script activates
def off
  
  if(@lightsoff == true)
    return
  end
  
  @bmpspr = Sprite.new
  @bmpspr.bitmap = Bitmap.new(544, 416)
  @lightsoff = true
  
end


# jumps to full lighting before transitioning the prior @desiredlightlevel
def flash(duration)
  
  prevdesiredlevel = @desiredlightlevel
  setlightlevel(255)
  transition(prevdesiredlevel, duration)

end


def onforduration(duration)
  on
  @offin = duration
end

# transition smoothly to the light level given over the duration in frames
def transition(brightness, duration)
  
  @desiredlightlevel = brightness
  @lightchangerate = ((@lightlevel - @desiredlightlevel).abs).to_f/duration.to_f
  
end


# set the ambient lighting level of the screen when lights are off
def setlightlevel(level)
  
  if(level > 255)
    level = 255
  end
  
  if(level < 0)
    level = 0
  end
  
  @lightlevel = level.to_i
  @desiredlightlevel = @lightlevel
  @tintcolor.set(0, 0, 0, 255 - @lightlevel)
  
end

# returns value of lightlevel
def getlightlevel
  return @lightlevel
end



#decreases ambient lighting by amount
def dim(amount)
  
  amount = amount.to_i
  
  setlightlevel(@lightlevel - amount)

end

# increases ambient lighting by amount
def brighten(amount)
  
  amount = amount.to_i
  
  setlightlevel(@lightlevel + amount)
  
end


# locks a light source to the given map position
def addstationarysource(x, y)
  
  @lightsources.length.times do |i|
    if(@lightsources[i].class == StationarySource)
      if(@lightsources[i].getmapx == x and @lightsources[i].getmapy == y)
        return false
      end
    end
  end
  
  @lightsources << StationarySource.new(x, y)
  return @lightsources[@lightsources.length - 1]
  
end

  
# locks a light source to the event represented by the id
def addeventsource(eventid)
  
  @lightsources.each do |ls|
    if(ls.class == EventSource)
      if(ls.getevent == $game_map.events[eventid])
        return ls
      end
    end
  end
    
  @lightsources << EventSource.new(eventid)
  return @lightsources[@lightsources.length - 1]
  
end

# locks a light source to the player
def addplayersource
  
  @lightsources.length.times do |i|
    if(@lightsources[i].class == PlayerSource)
      return false
    end
  end
  
  @lightsources << PlayerSource.new
  return true
  
end

# removes all light sources
def removeallsources
  @lightsources.clear
end

# removes the light source from the player
def removeplayersource
  
  sourceat = -1
  
  @lightsources.length.times do |i|
    if(@lightsources[i].class == PlayerSource)
      sourceat = i
    end
  end
  
  if(sourceat != -1)
    @lightsources.delete_at(sourceat)
  end
  
end


# removes the source specified by the source id, which is the actual object
def removesource(sourceid, y = -1)

  if(y == -1)
    if(!sourceid.is_a?(LightSource))
      e = $game_map.events[sourceid]
      @lightsources.each do |i|
        if(!e.nil? and i.is_a?(EventSource) and i.event == e)
          sourceid = i
        end
      end
    end
  
    @lightsources.delete(sourceid)

  else
    
    s = Array.new
    
    @lightsources.each do |i|
      if(i.is_a?(StationarySource) and i.mapx == sourceid and i.mapy == y)
        s.push(i)
      end
    end

    s.each do |i|
      @lightsources.delete(i)
    end
  end

end


def isoff
  return @lightsoff
end


def getlightlevel
  return @lightlevel
end


def dump(file)
  Marshal.dump(@lightsoff, file)
  Marshal.dump(@lightlevel, file)
  Marshal.dump(@desiredlightlevel, file)
  Marshal.dump(@lightchangerate, file)
  Marshal.dump(@lightsources, file)
  Marshal.dump(@offin, file)
end


def load(file)
  @lightsoff = Marshal.load(file)
  @lightlevel = Marshal.load(file)
  @desiredlightlevel = Marshal.load(file)
  @lightchangerate = Marshal.load(file)
  
  @lightsources = Array.new
  
  
  lsrc = Marshal.load(file)
  @pendingeventsources = Array.new
  lsrc.each do |i|
    if(i.is_a?(EventSource))
      ev = i.getevent
      @pendingeventsources.push(ev.id)
    end
    if(i.is_a?(PlayerSource))
      addplayersource
    end
    if(i.is_a?(StationarySource))
      addstationarysource(i.getmapx, i.getmapy)
    end
  end
  
  @offin = Marshal.load(file)
  @tintcolor = Color.new(0, 0, 0, 255 - @lightlevel)
end
  


# debug method. ideally empty.
def testmethod

end


def debugwrite(msg)
  f = File.new("debug.txt", "a")
  f.puts(msg)
end

  
end # class end

$lights = Lighting.new  # This is the variable that will be used for lighting


class Game_Event
  attr_accessor :id
end



FAQ:

Q: Where can I find out more information about this script?
A: Have a look at the word document provided with the demo. Of course, you can always post something here.

Q: Have you made any other awesome scripts?
A: Well, you could always check out my other script. It's called 'Fine Character Control'. You could be the first to reply!

Please download the latest demo if you plan to copy the script straight from the demo.

Credits:

- Original script written by Raoul589
- Thanks to Dizzie for providing the light stamp image


Notes:

- There are a few limitations with the script, outlined in the accompanying word document and demonstrated in the demo. The main thing to remember is that this, being a graphical script, is not a cheap script to run, and so you should be careful not to go overboard.

- If you wish to make your own light stamps, and you have Windows, you can run the attached program 'CircleDrawer' to draw a new light stamp of specified size and opacity etc.

This post has been edited by ???nOBodY???: Mar 22 2013, 08:56 AM
Attached File(s)
Attached File  CircleDrawer__NOT_THE_DEMO_.zip ( 8.98MB ) Number of downloads: 299
Attached File  Lighting_Demo.zip ( 836.22K ) Number of downloads: 446
Attached File  Lighting_Demo_1.1.zip ( 838.07K ) Number of downloads: 916
 
Go to the top of the page
 
+Quote Post
   
???nOBodY???
post Dec 7 2010, 08:45 PM
Post #2


moogles + nightmares + coffee = Scripting Psychopathic Tendency
Group Icon


Type: Coder
Alignment: Chaotic Neutral




Very interesting. Reminds me of Golden Sun. XD Nice script you've got there!


--------------------
*The Master List Update Project is currently up-to-date with the latest scripts for that dream project!
*By entering the RGSS2/Ruby Scripting section, you are agreeing to abide by The Coder's Creed.

My Scripts
Spoiler:

ACK Script Requests
Spoiler:

Scripts
Stat Change Formulas
GTBS Ziifee's spin menu Submenus
GTBS Weapon Unleash
GTBS Enemy Status
Attack Command Submenu
Jump To (X,Y)
BGM/BGS Fadein
Window_Message - Pop Text
Spell Management Menu
Melee Mastery Management Menu
Ghost List
Save / Autoload
Some Popup v2.9 => v2.91
Scene_StringEntry v1.02
Scene_StringEntry: More Than 24-Character Input
Scene_StringEntry: Scrolling Character Input Window
Scene_StringEntry: Typing Input
MA's Quest Journal - Accept Quest Add-On (internal)
MA's Quest Journal - Accept Quest Add-On (external)
Easy-to-Add Extra Ziifee Spin Commands
Scrolling Battle Message
Non-Differentiating Enemies
Quest Item Drops
(VX) FP Conditional Drops
FFTA World Map HUD bugfix
RSSBS / SSS - Wereforms patch
Death Counterattack
Targetting Extension

My Heart (Resources)
Spoiler:

Projects
Project AMBROSIA
*something generically clever*

Support these:
Spoiler:







Awards:
Spoiler:

Go to the top of the page
 
+Quote Post
   
Raoul589
post Dec 8 2010, 04:20 AM
Post #3



Group Icon


Type: Coder
Alignment: Chaotic Good




QUOTE (???nOBodY??? @ Dec 8 2010, 07:15 AM) *
Very interesting. Reminds me of Golden Sun. XD Nice script you've got there!


It's funny you should say that. When I was making it I did have GS in the back of my mind. In particular, that cave where you rescue the ruler of Tolbi. laugh.gif
Go to the top of the page
 
+Quote Post
   
pjcr
post Dec 8 2010, 08:36 AM
Post #4


Pixel Thief
Group Icon


Type: Artist
Alignment: Neutral Good




Very good, now I don't have to use pictures...
Great job!

This post has been edited by pjcr: Dec 8 2010, 08:37 AM


--------------------
Go to the top of the page
 
+Quote Post
   
Zephyrus
post Dec 8 2010, 10:15 AM
Post #5



Group Icon


Type: Writer
Alignment: Neutral Good




Great! I really need this script! laugh.gif
Finally, I can darken my cave dungeon in my project.
Thanks! biggrin.gif


--------------------


Nice resources for your game project:
Spoiler:

Celianna's:
Spoiler:







Rajawali's
Spoiler:
Go to the top of the page
 
+Quote Post
   
Sasame Kiryu
post Dec 9 2010, 09:01 AM
Post #6


どのような
Group Icon


Type: Writer
Alignment: Chaotic Neutral




I get an error every time I shut my project down after activating the script:

Script 'Lighting' line260: RGSSError occured.

disposed sprite

It happens when I play the demo as well. Don't know specifically what it means, but otherwise, the script works perfect.
Go to the top of the page
 
+Quote Post
   
Lady Atlas
post Dec 9 2010, 09:48 AM
Post #7



Group Icon


Type: Designer
Alignment: Neutral Good




Cool, I really like this!!! Thanks! smile.gif
Go to the top of the page
 
+Quote Post
   
Raoul589
post Dec 9 2010, 02:09 PM
Post #8



Group Icon


Type: Coder
Alignment: Chaotic Good




QUOTE (Sasame Kiryu @ Dec 9 2010, 07:31 PM) *
I get an error every time I shut my project down after activating the script:

Script 'Lighting' line260: RGSSError occured.

disposed sprite

It happens when I play the demo as well. Don't know specifically what it means, but otherwise, the script works perfect.


Thanks for reporting the error. I couldn't replicate it, but I made a small change to the script which should get rid of the problem. It is reflected in both the demo and the main post, so if you want to fix the problem, just try overwriting the Lighting script with the now changed one in my post.
Go to the top of the page
 
+Quote Post
   
Celianna
post Dec 9 2010, 02:45 PM
Post #9



Group Icon


Type: Artist
Alignment: Chaotic Evil




Great! Now every time asks how to make a puzzle that includes the player holding a lantern and give light only around them, I'll just direct them to this script biggrin.gif
Go to the top of the page
 
+Quote Post
   
I.m Autistic
post Dec 9 2010, 11:37 PM
Post #10



Group Icon


Type: Undisclosed
Alignment: Unaligned




Hi... Guys!! I don't wannts to be a smart ass or something
but I think it's hard to add this script for the newbie
because they are afraid to mess with the default script
in script editor so I made a few edit about this script. . . . . .
sso they can add this script on material section!!

here it goes
just add it below material and your good to gow
Spoiler:
CODE
#==============================================================================
# ** Light Source
#------------------------------------------------------------------------------
# created by: Raoul589's
#
# Lighting interface:
#
# $lights.on
# $lights.off
# $lights.isoff
# $lights.dim(amount)
# $lights.brighten(amount)
# $lights.transition(brightness)
# $lights.flash(duration)
# $lights.setlightlevel(brightness)
# $lights.getlightlevel
# $lights.addstationarysource(x, y)
# $lights.addeventsource(event)
# $lights.addplayersource
# $lights.removeplayersource
# $lights.removesource(sourceid)
# $lights.removeallsources
#
# $lights.updateframe   // Should be called in a common event every frame
# $lights.initialize    // Don't touch this at all unless you know what it does
#
#
# default settings
LIGHTCIRC = 175
BRIGHTCIRC = 25
CENTERBRIGHTNESS = 200
CENTEROPACITY = 255 - CENTERBRIGHTNESS
# end default settings
#------------------------------------------------------------------------------
# ** Scene_Base
#------------------------------------------------------------------------------
#  This is a superclass of all scenes in the game.
#==============================================================================
$imported = {} if $imported == nil
$imported["LightSource"] = true
class Scene_Base
  def start
      # THE LINE BELOW WAS ADDED
      $lights.updateframe if !$lights.nil? # THIS LINE WAS ADDED
      # THE LINE ABOVE WAS ADDED
  end
  def update
  # THE LINE BELOW WAS ADDED
    $lights.updateframe if !$lights.nil? # THIS LINE WAS ADDED
  # THE LINE ABOVE WAS ADDED
  end
end
#==============================================================================
# ** Scene_File
#------------------------------------------------------------------------------
#  This class performs the save and load screen processing.
#==============================================================================
class Scene_File < Scene_Base
alias LightSource_write_save_data write_save_data
alias LightSource_read_save_data read_save_data
  def write_save_data(file)
  LightSource_write_save_data
    # THE LINE BELOW WAS ADDED
    $lights.dump(file)          # THIS LINE WAS ADDED
    # THE LINE ABOVE WAS ADDED
  end


  def read_save_data(file)
  LightSource_read_save_data
  # THE LINE BELOW WAS ADDED
    $lights.load(file)        # THIS LINE WAS ADDED
  # THE LINE ABOVE WAS ADDED
    if $game_system.version_id != $data_system.version_id
      $game_map.setup($game_map.map_id)
      $game_player.center($game_player.x, $game_player.y)
    end
  end
end
class LightSource
  
  @x
  @y
  @width
  @height
  
  # light source constructor
  def initialize
    @x = 0
    @y = 0
    @width = $lights.truelightcirc
    @height = $lights.truelightcirc
  end
  
  # updates the light source
  def update
  end
  
  
  def getx
    return @x
  end
  
  def gety
    return @y
  end
  
  def getwidth
    return @width
  end
  
  def getheight
    return @height
  end
  
end # class end


# non-moving light source
class StationarySource < LightSource
  
  # only the stationary source is interested in the map coordinates
  @mapx
  @mapy
  
  def initialize(x, y)
    super()
    @mapx = x
    @mapy = y
    update
  end
  
  
  def update
    super()
    @x = 32 * @mapx - (@width / 2) + 16 - ($game_map.display_x / 8)
    @y = 32 * @mapy - (@height / 2) + 16 - ($game_map.display_y / 8)
  end
  
  
  def getmapx
    return @mapx
  end
  
  
  def getmapy
    return @mapy
  end
  
end # class end


# light source that moves with an event
class EventSource < LightSource
  
  @event
  
  def initialize(eventid)
    super()
    @event = $game_map.events[eventid]
    update
  end
  
  
  def update
    super()
    @x = (@event.real_x / 8) - (@width / 2) + 16 - ($game_map.display_x / 8)
    @y = (@event.real_y / 8) - (@height / 2) + 16 - ($game_map.display_y / 8)
  end
  
  def getevent
    return @event
  end
  
end # class end


# light source that moves with the player
class PlayerSource < LightSource
  
  def initialize
    super()
    update
  end
  
  def update
    super()
    @x = ($game_player.real_x / 8) - (@width / 2) +
            16 - ($game_map.display_x / 8)
    @y = ($game_player.real_y / 8) - (@height / 2) +
            16 - ($game_map.display_y / 8)
  end
  
end # class end


class Lighting

attr_accessor :truelightcirc
  
# variables which should not be externally accessed

@lightsoff
@lightlevel
@desiredlightlevel
@lightchangerate
@lightsources
@sprviewport
@bmpspr
@tintcolor
@offin

@lightstamp

@workingcolor
@workingrect

  
# methods

# this method sets up the lighting class
def initialize
  
  @lightsoff = false
  @lightlevel = 0
  @offin = 0
  @desiredlightlevel = @lightlevel
  @lightchangerate = 1
  @tintcolor = Color.new(0, 0, 0, 255 - @lightlevel)
  @workingcolor = Color.new(0,0,0,CENTEROPACITY)
  @workingrect = Rect.new(0,0,0,0)
  @lightsources = Array.new
  @pendingeventsources = nil
  
  @sprviewport = Viewport.new(0,0, 544, 416)
  @sprviewport.z = 99
  
  @lightstamp = Bitmap.new(LIGHTCIRC,LIGHTCIRC)
  @lightstamp.fill_rect(0,0,@lightstamp.width, @lightstamp.height, @workingcolor)
  
  h = @lightstamp.width / 2
  k = @lightstamp.height / 2
  halflightcirc = LIGHTCIRC / 2
  rmult = (255 - CENTEROPACITY).to_f / ((LIGHTCIRC/2) - (BRIGHTCIRC/2)).to_f
  startr = (BRIGHTCIRC / 2) - 1
  
#=begin
  if(FileTest.exist?("Graphics/Pictures/LightStamp.png"))

  @lightstamp = Bitmap.new("Graphics/Pictures/LightStamp")
    
  else    # we need to draw the circle from scratch
  
  for r in (BRIGHTCIRC/2)..(LIGHTCIRC/2)
    for x in 0..(@lightstamp.width - 1)
      for y in 0..(@lightstamp.height - 1)
        
        xy = (x - h) * (x - h) + (y - k) * (y - k)
        
        if(xy >= r * r and xy < (r + 1) * (r + 1))
          @lightstamp.set_pixel(x,y, Color.new(0,0,0, CENTEROPACITY +
                                                ((r - startr)*rmult).to_i))
        end

      end
    end
  end
  
  for x in 0..(@lightstamp.width - 1)
    for y in 0..(@lightstamp.height - 1)
      
      xy = (x - h) * (x - h) + (y - k) * (y - k)
      
      if(xy > halflightcirc * halflightcirc)
        @lightstamp.set_pixel(x,y, Color.new(0,0,0, 255))
      end
        
    end
  end
    
  end # filecheck end

  @truelightcirc = @lightstamp.width
#=end  

end

# this method should not be called directly.
def updateframe
  
  if(!@pendingeventsources.nil? and $scene.is_a?(Scene_Map))
    @pendingeventsources.each do |i|
      addeventsource(i)
    end
    @pendingeventsources = nil
  end
  
  la = true
  
  if($scene.is_a?(Scene_Battle) or $scene.is_a?(Scene_Skill) or
          $scene.is_a?(Scene_Item) or $scene.is_a?(Scene_Title) or
              $scene.is_a?(Scene_Shop) or $scene.is_a?(Scene_Gameover) or
                $scene.is_a?(Scene_File) or $scene.is_a?(Scene_End))
   v = Viewport.new(0,0,544, 416)
   v.z = -1
   @bmpspr.viewport = v if (!@bmpspr.nil? and !@bmpspr.disposed?)
   la = false
  end
  
  if(@lightsoff == true and la)
    
    if(@lightlevel != @desiredlightlevel)
      if(@lightlevel < @desiredlightlevel)
        @lightlevel += @lightchangerate
        if(@lightlevel > @desiredlightlevel)
          @lightlevel = @desiredlightlevel.to_i
          @desiredlightlevel = @desiredlightlevel.to_i
        end
      end
      if(@lightlevel > @desiredlightlevel)
        @lightlevel -= @lightchangerate
        if(@lightlevel < @desiredlightlevel)
          @lightlevel = @desiredlightlevel.to_i
          @desiredlightlevel = @desiredlightlevel.to_i
        end
      end
      @tintcolor.set(0, 0, 0, 255 - @lightlevel)
    end
    
    @bmpspr.bitmap.dispose if (!@bmpspr.nil? and !@bmpspr.disposed?)
    @bmpspr.dispose if (!@bmpspr.nil? and !@bmpspr.disposed?)
    @bmpspr = Sprite.new(@sprviewport)
    @bmpspr.bitmap = Bitmap.new(544, 416)
    
    #@bmpspr.bitmap.clear
    @bmpspr.bitmap.fill_rect(0, 0, 544, 416, @tintcolor)
    
    @workingcolor = Color.new(0, 0, 0, 0)
    
    @lightsources.each do |ls|
      ls.update
      @bmpspr.bitmap.fill_rect(ls.getx, ls.gety,
                                ls.getwidth, ls.getheight, @workingcolor)
      @workingrect.set(0, 0, @lightstamp.width, @lightstamp.height)
      @bmpspr.bitmap.blt(ls.getx, ls.gety, @lightstamp,
                          @workingrect, @tintcolor.alpha)
    end
                        
  end
  
  if(@lightsoff == false)
    if(@offin != 0)
      @offin -= 1
      if @offin <= 0
        @offin = 0
        off
      end
    end
  end
  
end

# turn lights on; normal lighting
def on
  
  if(@lightsoff == false)
    return
  end
  
  @bmpspr.bitmap.dispose
  @bmpspr.dispose
  @lightsoff = false
  
end

# turn lights off; this script activates
def off
  
  if(@lightsoff == true)
    return
  end
  
  @bmpspr = Sprite.new
  @bmpspr.bitmap = Bitmap.new(544, 416)
  @lightsoff = true
  
end


# jumps to full lighting before transitioning the prior @desiredlightlevel
def flash(duration)
  
  prevdesiredlevel = @desiredlightlevel
  setlightlevel(255)
  transition(prevdesiredlevel, duration)

end


def onforduration(duration)
  on
  @offin = duration
end

# transition smoothly to the light level given over the duration in frames
def transition(brightness, duration)
  
  @desiredlightlevel = brightness
  @lightchangerate = ((@lightlevel - @desiredlightlevel).abs).to_f/duration.to_f
  
end


# set the ambient lighting level of the screen when lights are off
def setlightlevel(level)
  
  if(level > 255)
    level = 255
  end
  
  if(level < 0)
    level = 0
  end
  
  @lightlevel = level.to_i
  @desiredlightlevel = @lightlevel
  @tintcolor.set(0, 0, 0, 255 - @lightlevel)
  
end

# returns value of lightlevel
def getlightlevel
  return @lightlevel
end



#decreases ambient lighting by amount
def dim(amount)
  
  amount = amount.to_i
  
  setlightlevel(@lightlevel - amount)

end

# increases ambient lighting by amount
def brighten(amount)
  
  amount = amount.to_i
  
  setlightlevel(@lightlevel + amount)
  
end


# locks a light source to the given map position
def addstationarysource(x, y)
  
  @lightsources.length.times do |i|
    if(@lightsources[i].class == StationarySource)
      if(@lightsources[i].getmapx == x and @lightsources[i].getmapy == y)
        return false
      end
    end
  end
  
  @lightsources << StationarySource.new(x, y)
  return @lightsources[@lightsources.length - 1]
  
end

  
# locks a light source to the event represented by the id
def addeventsource(eventid)
  
  @lightsources.each do |ls|
    if(ls.class == EventSource)
      if(ls.getevent == $game_map.events[eventid])
        return ls
      end
    end
  end
    
  @lightsources << EventSource.new(eventid)
  return @lightsources[@lightsources.length - 1]
  
end

# locks a light source to the player
def addplayersource
  
  @lightsources.length.times do |i|
    if(@lightsources[i].class == PlayerSource)
      return false
    end
  end
  
  @lightsources << PlayerSource.new
  return true
  
end

# removes all light sources
def removeallsources
  @lightsources.clear
end

# removes the light source from the player
def removeplayersource
  
  sourceat = -1
  
  @lightsources.length.times do |i|
    if(@lightsources[i].class == PlayerSource)
      sourceat = i
    end
  end
  
  if(sourceat != -1)
    @lightsources.delete_at(sourceat)
  end
  
end

# removes the source specified by the source id, which is the actual object
def removesource(sourceid)

@lightsources.delete(sourceid)
  
end


def isoff
  return @lightsoff
end


def getlightlevel
  return @lightlevel
end


def dump(file)
  Marshal.dump(@lightsoff, file)
  Marshal.dump(@lightlevel, file)
  Marshal.dump(@desiredlightlevel, file)
  Marshal.dump(@lightchangerate, file)
  Marshal.dump(@lightsources, file)
  Marshal.dump(@offin, file)
end


def load(file)
  @lightsoff = Marshal.load(file)
  @lightlevel = Marshal.load(file)
  @desiredlightlevel = Marshal.load(file)
  @lightchangerate = Marshal.load(file)
  
  @lightsources = Array.new
  
  
  lsrc = Marshal.load(file)
  @pendingeventsources = Array.new
  lsrc.each do |i|
    if(i.is_a?(EventSource))
      ev = i.getevent
      @pendingeventsources.push(ev.id)
    end
    if(i.is_a?(PlayerSource))
      addplayersource
    end
    if(i.is_a?(StationarySource))
      addstationarysource(i.getmapx, i.getmapy)
    end
  end
  
  @offin = Marshal.load(file)
  @tintcolor = Color.new(0, 0, 0, 255 - @lightlevel)
end
  


# debug method. ideally empty.
def testmethod

end


def debugwrite(msg)
  f = File.new("debug.txt", "a")
  f.puts(msg)
end

  
end # class end

$lights = Lighting.new  # This is the variable that will be used for lighting


class Game_Event
  attr_accessor :id
end


By the way your script is awesome man . . .!!!
Go to the top of the page
 
+Quote Post
   
Raoul589
post Dec 10 2010, 12:44 PM
Post #11



Group Icon


Type: Coder
Alignment: Chaotic Good




QUOTE (I.m Autistic @ Dec 10 2010, 10:07 AM) *
Hi... Guys!! I don't wannts to be a smart ass or something
but I think it's hard to add this script for the newbie
because they are afraid to mess with the default script
in script editor so I made a few edit about this script. . . . . .
sso they can add this script on material section!!

here it goes
just add it below material and your good to gow
Spoiler:
CODE
#==============================================================================
# ** Light Source
#------------------------------------------------------------------------------
# created by: Raoul589's
#
# Lighting interface:
#
# $lights.on
# $lights.off
# $lights.isoff
# $lights.dim(amount)
# $lights.brighten(amount)
# $lights.transition(brightness)
# $lights.flash(duration)
# $lights.setlightlevel(brightness)
# $lights.getlightlevel
# $lights.addstationarysource(x, y)
# $lights.addeventsource(event)
# $lights.addplayersource
# $lights.removeplayersource
# $lights.removesource(sourceid)
# $lights.removeallsources
#
# $lights.updateframe   // Should be called in a common event every frame
# $lights.initialize    // Don't touch this at all unless you know what it does
#
#
# default settings
LIGHTCIRC = 175
BRIGHTCIRC = 25
CENTERBRIGHTNESS = 200
CENTEROPACITY = 255 - CENTERBRIGHTNESS
# end default settings
#------------------------------------------------------------------------------
# ** Scene_Base
#------------------------------------------------------------------------------
#  This is a superclass of all scenes in the game.
#==============================================================================
$imported = {} if $imported == nil
$imported["LightSource"] = true
class Scene_Base
  def start
      # THE LINE BELOW WAS ADDED
      $lights.updateframe if !$lights.nil? # THIS LINE WAS ADDED
      # THE LINE ABOVE WAS ADDED
  end
  def update
  # THE LINE BELOW WAS ADDED
    $lights.updateframe if !$lights.nil? # THIS LINE WAS ADDED
  # THE LINE ABOVE WAS ADDED
  end
end
#==============================================================================
# ** Scene_File
#------------------------------------------------------------------------------
#  This class performs the save and load screen processing.
#==============================================================================
class Scene_File < Scene_Base
alias LightSource_write_save_data write_save_data
alias LightSource_read_save_data read_save_data
  def write_save_data(file)
  LightSource_write_save_data
    # THE LINE BELOW WAS ADDED
    $lights.dump(file)          # THIS LINE WAS ADDED
    # THE LINE ABOVE WAS ADDED
  end


  def read_save_data(file)
  LightSource_read_save_data
  # THE LINE BELOW WAS ADDED
    $lights.load(file)        # THIS LINE WAS ADDED
  # THE LINE ABOVE WAS ADDED
    if $game_system.version_id != $data_system.version_id
      $game_map.setup($game_map.map_id)
      $game_player.center($game_player.x, $game_player.y)
    end
  end
end
class LightSource
  
  @x
  @y
  @width
  @height
  
  # light source constructor
  def initialize
    @x = 0
    @y = 0
    @width = $lights.truelightcirc
    @height = $lights.truelightcirc
  end
  
  # updates the light source
  def update
  end
  
  
  def getx
    return @x
  end
  
  def gety
    return @y
  end
  
  def getwidth
    return @width
  end
  
  def getheight
    return @height
  end
  
end # class end


# non-moving light source
class StationarySource < LightSource
  
  # only the stationary source is interested in the map coordinates
  @mapx
  @mapy
  
  def initialize(x, y)
    super()
    @mapx = x
    @mapy = y
    update
  end
  
  
  def update
    super()
    @x = 32 * @mapx - (@width / 2) + 16 - ($game_map.display_x / 8)
    @y = 32 * @mapy - (@height / 2) + 16 - ($game_map.display_y / 8)
  end
  
  
  def getmapx
    return @mapx
  end
  
  
  def getmapy
    return @mapy
  end
  
end # class end


# light source that moves with an event
class EventSource < LightSource
  
  @event
  
  def initialize(eventid)
    super()
    @event = $game_map.events[eventid]
    update
  end
  
  
  def update
    super()
    @x = (@event.real_x / 8) - (@width / 2) + 16 - ($game_map.display_x / 8)
    @y = (@event.real_y / 8) - (@height / 2) + 16 - ($game_map.display_y / 8)
  end
  
  def getevent
    return @event
  end
  
end # class end


# light source that moves with the player
class PlayerSource < LightSource
  
  def initialize
    super()
    update
  end
  
  def update
    super()
    @x = ($game_player.real_x / 8) - (@width / 2) +
            16 - ($game_map.display_x / 8)
    @y = ($game_player.real_y / 8) - (@height / 2) +
            16 - ($game_map.display_y / 8)
  end
  
end # class end


class Lighting

attr_accessor :truelightcirc
  
# variables which should not be externally accessed

@lightsoff
@lightlevel
@desiredlightlevel
@lightchangerate
@lightsources
@sprviewport
@bmpspr
@tintcolor
@offin

@lightstamp

@workingcolor
@workingrect

  
# methods

# this method sets up the lighting class
def initialize
  
  @lightsoff = false
  @lightlevel = 0
  @offin = 0
  @desiredlightlevel = @lightlevel
  @lightchangerate = 1
  @tintcolor = Color.new(0, 0, 0, 255 - @lightlevel)
  @workingcolor = Color.new(0,0,0,CENTEROPACITY)
  @workingrect = Rect.new(0,0,0,0)
  @lightsources = Array.new
  @pendingeventsources = nil
  
  @sprviewport = Viewport.new(0,0, 544, 416)
  @sprviewport.z = 99
  
  @lightstamp = Bitmap.new(LIGHTCIRC,LIGHTCIRC)
  @lightstamp.fill_rect(0,0,@lightstamp.width, @lightstamp.height, @workingcolor)
  
  h = @lightstamp.width / 2
  k = @lightstamp.height / 2
  halflightcirc = LIGHTCIRC / 2
  rmult = (255 - CENTEROPACITY).to_f / ((LIGHTCIRC/2) - (BRIGHTCIRC/2)).to_f
  startr = (BRIGHTCIRC / 2) - 1
  
#=begin
  if(FileTest.exist?("Graphics/Pictures/LightStamp.png"))

  @lightstamp = Bitmap.new("Graphics/Pictures/LightStamp")
    
  else    # we need to draw the circle from scratch
  
  for r in (BRIGHTCIRC/2)..(LIGHTCIRC/2)
    for x in 0..(@lightstamp.width - 1)
      for y in 0..(@lightstamp.height - 1)
        
        xy = (x - h) * (x - h) + (y - k) * (y - k)
        
        if(xy >= r * r and xy < (r + 1) * (r + 1))
          @lightstamp.set_pixel(x,y, Color.new(0,0,0, CENTEROPACITY +
                                                ((r - startr)*rmult).to_i))
        end

      end
    end
  end
  
  for x in 0..(@lightstamp.width - 1)
    for y in 0..(@lightstamp.height - 1)
      
      xy = (x - h) * (x - h) + (y - k) * (y - k)
      
      if(xy > halflightcirc * halflightcirc)
        @lightstamp.set_pixel(x,y, Color.new(0,0,0, 255))
      end
        
    end
  end
    
  end # filecheck end

  @truelightcirc = @lightstamp.width
#=end  

end

# this method should not be called directly.
def updateframe
  
  if(!@pendingeventsources.nil? and $scene.is_a?(Scene_Map))
    @pendingeventsources.each do |i|
      addeventsource(i)
    end
    @pendingeventsources = nil
  end
  
  la = true
  
  if($scene.is_a?(Scene_Battle) or $scene.is_a?(Scene_Skill) or
          $scene.is_a?(Scene_Item) or $scene.is_a?(Scene_Title) or
              $scene.is_a?(Scene_Shop) or $scene.is_a?(Scene_Gameover) or
                $scene.is_a?(Scene_File) or $scene.is_a?(Scene_End))
   v = Viewport.new(0,0,544, 416)
   v.z = -1
   @bmpspr.viewport = v if (!@bmpspr.nil? and !@bmpspr.disposed?)
   la = false
  end
  
  if(@lightsoff == true and la)
    
    if(@lightlevel != @desiredlightlevel)
      if(@lightlevel < @desiredlightlevel)
        @lightlevel += @lightchangerate
        if(@lightlevel > @desiredlightlevel)
          @lightlevel = @desiredlightlevel.to_i
          @desiredlightlevel = @desiredlightlevel.to_i
        end
      end
      if(@lightlevel > @desiredlightlevel)
        @lightlevel -= @lightchangerate
        if(@lightlevel < @desiredlightlevel)
          @lightlevel = @desiredlightlevel.to_i
          @desiredlightlevel = @desiredlightlevel.to_i
        end
      end
      @tintcolor.set(0, 0, 0, 255 - @lightlevel)
    end
    
    @bmpspr.bitmap.dispose if (!@bmpspr.nil? and !@bmpspr.disposed?)
    @bmpspr.dispose if (!@bmpspr.nil? and !@bmpspr.disposed?)
    @bmpspr = Sprite.new(@sprviewport)
    @bmpspr.bitmap = Bitmap.new(544, 416)
    
    #@bmpspr.bitmap.clear
    @bmpspr.bitmap.fill_rect(0, 0, 544, 416, @tintcolor)
    
    @workingcolor = Color.new(0, 0, 0, 0)
    
    @lightsources.each do |ls|
      ls.update
      @bmpspr.bitmap.fill_rect(ls.getx, ls.gety,
                                ls.getwidth, ls.getheight, @workingcolor)
      @workingrect.set(0, 0, @lightstamp.width, @lightstamp.height)
      @bmpspr.bitmap.blt(ls.getx, ls.gety, @lightstamp,
                          @workingrect, @tintcolor.alpha)
    end
                        
  end
  
  if(@lightsoff == false)
    if(@offin != 0)
      @offin -= 1
      if @offin <= 0
        @offin = 0
        off
      end
    end
  end
  
end

# turn lights on; normal lighting
def on
  
  if(@lightsoff == false)
    return
  end
  
  @bmpspr.bitmap.dispose
  @bmpspr.dispose
  @lightsoff = false
  
end

# turn lights off; this script activates
def off
  
  if(@lightsoff == true)
    return
  end
  
  @bmpspr = Sprite.new
  @bmpspr.bitmap = Bitmap.new(544, 416)
  @lightsoff = true
  
end


# jumps to full lighting before transitioning the prior @desiredlightlevel
def flash(duration)
  
  prevdesiredlevel = @desiredlightlevel
  setlightlevel(255)
  transition(prevdesiredlevel, duration)

end


def onforduration(duration)
  on
  @offin = duration
end

# transition smoothly to the light level given over the duration in frames
def transition(brightness, duration)
  
  @desiredlightlevel = brightness
  @lightchangerate = ((@lightlevel - @desiredlightlevel).abs).to_f/duration.to_f
  
end


# set the ambient lighting level of the screen when lights are off
def setlightlevel(level)
  
  if(level > 255)
    level = 255
  end
  
  if(level < 0)
    level = 0
  end
  
  @lightlevel = level.to_i
  @desiredlightlevel = @lightlevel
  @tintcolor.set(0, 0, 0, 255 - @lightlevel)
  
end

# returns value of lightlevel
def getlightlevel
  return @lightlevel
end



#decreases ambient lighting by amount
def dim(amount)
  
  amount = amount.to_i
  
  setlightlevel(@lightlevel - amount)

end

# increases ambient lighting by amount
def brighten(amount)
  
  amount = amount.to_i
  
  setlightlevel(@lightlevel + amount)
  
end


# locks a light source to the given map position
def addstationarysource(x, y)
  
  @lightsources.length.times do |i|
    if(@lightsources[i].class == StationarySource)
      if(@lightsources[i].getmapx == x and @lightsources[i].getmapy == y)
        return false
      end
    end
  end
  
  @lightsources << StationarySource.new(x, y)
  return @lightsources[@lightsources.length - 1]
  
end

  
# locks a light source to the event represented by the id
def addeventsource(eventid)
  
  @lightsources.each do |ls|
    if(ls.class == EventSource)
      if(ls.getevent == $game_map.events[eventid])
        return ls
      end
    end
  end
    
  @lightsources << EventSource.new(eventid)
  return @lightsources[@lightsources.length - 1]
  
end

# locks a light source to the player
def addplayersource
  
  @lightsources.length.times do |i|
    if(@lightsources[i].class == PlayerSource)
      return false
    end
  end
  
  @lightsources << PlayerSource.new
  return true
  
end

# removes all light sources
def removeallsources
  @lightsources.clear
end

# removes the light source from the player
def removeplayersource
  
  sourceat = -1
  
  @lightsources.length.times do |i|
    if(@lightsources[i].class == PlayerSource)
      sourceat = i
    end
  end
  
  if(sourceat != -1)
    @lightsources.delete_at(sourceat)
  end
  
end

# removes the source specified by the source id, which is the actual object
def removesource(sourceid)

@lightsources.delete(sourceid)
  
end


def isoff
  return @lightsoff
end


def getlightlevel
  return @lightlevel
end


def dump(file)
  Marshal.dump(@lightsoff, file)
  Marshal.dump(@lightlevel, file)
  Marshal.dump(@desiredlightlevel, file)
  Marshal.dump(@lightchangerate, file)
  Marshal.dump(@lightsources, file)
  Marshal.dump(@offin, file)
end


def load(file)
  @lightsoff = Marshal.load(file)
  @lightlevel = Marshal.load(file)
  @desiredlightlevel = Marshal.load(file)
  @lightchangerate = Marshal.load(file)
  
  @lightsources = Array.new
  
  
  lsrc = Marshal.load(file)
  @pendingeventsources = Array.new
  lsrc.each do |i|
    if(i.is_a?(EventSource))
      ev = i.getevent
      @pendingeventsources.push(ev.id)
    end
    if(i.is_a?(PlayerSource))
      addplayersource
    end
    if(i.is_a?(StationarySource))
      addstationarysource(i.getmapx, i.getmapy)
    end
  end
  
  @offin = Marshal.load(file)
  @tintcolor = Color.new(0, 0, 0, 255 - @lightlevel)
end
  


# debug method. ideally empty.
def testmethod

end


def debugwrite(msg)
  f = File.new("debug.txt", "a")
  f.puts(msg)
end

  
end # class end

$lights = Lighting.new  # This is the variable that will be used for lighting


class Game_Event
  attr_accessor :id
end


By the way your script is awesome man . . .!!!



Hey, thanks for your input. To be entirely honest, I *cough* haven't actually ever learned how to alias ruby methods in the way you have done... On a side note though, have you tried saving and loading with the script you posted? I don't know if it's just my project, but I get an error related to the alias when I try to save. If you could have a look again at the script, that would be helpful. And I would be happy to make your changes to my script if I was sure it would be stable.
Go to the top of the page
 
+Quote Post
   
~NeXy~
post Dec 15 2010, 01:37 PM
Post #12



Group Icon


Type: Designer




Hey, Raul589, awesome script man! smile.gif

I have a problem with it tough. I have followed your instructions carefuly and implemented the script into my project, but for some reason when I test the map nothing happens. I took some events from your demo and still nothing. But when I place that chumby guy from the first map of your demo, who demonstrates one possibility of the script, and try to talk to him in my map I get the following error:

????? 'Lighning' ? 167 ??? NoMethodError ????????
undefined method 'real_x' for nil:NilClass


I don't have much knowledge about scripting, so I can't really find what porblem is about or how to fix it. Could it be a compatibility issue? I have quite a lot of scripts in the project. If you have any idea how to make it work please let me know.
Go to the top of the page
 
+Quote Post
   
Secretmapper
post Dec 19 2010, 11:59 AM
Post #13



Group Icon


Type: Coder




Nice script, but it seems that in battles, the background is still black.

This post has been edited by Secretmapper: Dec 20 2010, 07:27 AM
Go to the top of the page
 
+Quote Post
   
Raoul589
post Dec 23 2010, 10:24 AM
Post #14



Group Icon


Type: Coder
Alignment: Chaotic Good




QUOTE (~NeXy~ @ Dec 16 2010, 12:07 AM) *
Hey, Raul589, awesome script man! smile.gif

I have a problem with it tough. I have followed your instructions carefuly and implemented the script into my project, but for some reason when I test the map nothing happens. I took some events from your demo and still nothing. But when I place that chumby guy from the first map of your demo, who demonstrates one possibility of the script, and try to talk to him in my map I get the following error:

????? 'Lighning' ? 167 ??? NoMethodError ????????
undefined method 'real_x' for nil:NilClass


I don't have much knowledge about scripting, so I can't really find what porblem is about or how to fix it. Could it be a compatibility issue? I have quite a lot of scripts in the project. If you have any idea how to make it work please let me know.


Hello Nexy,

If you have a lot of scripts, what you have to be careful about is that the other scripts aren't simply overwriting the four changes you were instructed to make in the core scripts. If any of the other scripts implement the methods referred to, e.g. Scene_Base::update or Scene_Base::start, then you will need to make the instructed changes there instead.

If you want to know if the other scripts are interfering with mine, a good start would be to go into them and do a ctrl-f (find) and look for "def start" and "def update". If you find them, that could well mean the changes made to the core code are being overwritten, and so the changes need to be made in the custom scripts instead.

If you send me a link to a copy of your project, I would be happy to look through it; it would help for making my script more compatible with other random scripts.
Go to the top of the page
 
+Quote Post
   
Raoul589
post Dec 23 2010, 10:28 AM
Post #15



Group Icon


Type: Coder
Alignment: Chaotic Good




QUOTE (Secretmapper @ Dec 19 2010, 10:29 PM) *
Nice script, but it seems that in battles, the background is still black.


Hey, I'm not entirely sure what you mean, but the battle background should just be the standard one, i.e. a warped version of whatever was on the screen at the point when battle commenced. In the case that the lights were turned down very dark and not many lights were on the screen, the battle background would be pretty much black. If this is not what you meant, please tell me and maybe give a screenshot?
Go to the top of the page
 
+Quote Post
   
skywind
post Jan 1 2011, 07:28 PM
Post #16



Group Icon


Type: Undisclosed




hi, thanks for the script. sorry me noob here. got a little problem.
i tried to off one of the static light. let say i on $lights.addstationarysource(10,8), so when i want to off the same source i call $lights.removesource(lights.addstationarysource(10,8))..

is it true the way i used? cause i got error message 'wrong number of arguments(0 for 1)'. i also tried $lights.removesource(10,8) but got another error.
Go to the top of the page
 
+Quote Post
   
Raoul589
post Jan 5 2011, 10:27 PM
Post #17



Group Icon


Type: Coder
Alignment: Chaotic Good




QUOTE (skywind @ Jan 2 2011, 05:58 AM) *
hi, thanks for the script. sorry me noob here. got a little problem.
i tried to off one of the static light. let say i on $lights.addstationarysource(10,8), so when i want to off the same source i call $lights.removesource(lights.addstationarysource(10,8))..

is it true the way i used? cause i got error message 'wrong number of arguments(0 for 1)'. i also tried $lights.removesource(10,8) but got another error.


That's a really good try at using it. Come back in a couple of days and I will have made the script do just what you wanted (because I think the way you tried to use it is a good idea).

The intended way to do what you are trying to do is this:

$mylight = $lights.addstationarysource(10,8)

then

$lights.removesource($mylight)


As I said, I really like the way you used it. I think I will script in support for doing that in the next couple of days.


EDIT: I made a few little changes to the script. If you copy the new script into your project again, you should be able to use $lights.removesource(10,8) as you initially tried to.

This post has been edited by Raoul589: Jan 5 2011, 11:52 PM
Go to the top of the page
 
+Quote Post
   
-Ender©
post Jan 10 2011, 01:00 AM
Post #18


One man Pen
Group Icon


Type: Undisclosed
Alignment: Neutral Evil




*Sigh* I must be a moron or something. Cuz I can only get the $lights.off command to work anything else Doesn't want to work like $lights.setlightlevel(50). Any help is great, Feel free to call me a Nub or Moron. biggrin.gif

This post has been edited by -Ender©: Jan 10 2011, 01:01 AM


--------------------

As a halo fan I am obligated to call you a Noob Biscuit and tell you to commit suicide for the blasphemy you just wrote
Go to the top of the page
 
+Quote Post
   
Raoul589
post Jan 11 2011, 03:59 AM
Post #19



Group Icon


Type: Coder
Alignment: Chaotic Good




QUOTE (-Ender© @ Jan 10 2011, 11:30 AM) *
*Sigh* I must be a moron or something. Cuz I can only get the $lights.off command to work anything else Doesn't want to work like $lights.setlightlevel(50). Any help is great, Feel free to call me a Nub or Moron. biggrin.gif


Hey,

$lights.off activates the system itself. So you won't see any effect at all until you have called that. To put it another way, you can think of it as $lights.(turn darkness effect on). So if you want to set the light level to 50, try going

$lights.off
$lights.setlightlevel(50)

What that would do is make the screen quite dark, but you still will be able to see a little.

If the problem is deeper than this, feel free to give more details.
Go to the top of the page
 
+Quote Post
   
-Ender©
post Jan 13 2011, 01:29 AM
Post #20


One man Pen
Group Icon


Type: Undisclosed
Alignment: Neutral Evil




QUOTE (Raoul589 @ Jan 10 2011, 07:59 PM) *
Hey,

$lights.off activates the system itself. So you won't see any effect at all until you have called that. To put it another way, you can think of it as $lights.(turn darkness effect on). So if you want to set the light level to 50, try going



Thank you so much.
I should have thought of that earlier.

And... Is their anyway to make the circle of light bigger?

**EDIT**
Ok Thanks For Help any how It would be awesome if you did add the size chager into the script
** EDIT END**

This post has been edited by -Ender©: Jan 13 2011, 06:55 PM


--------------------

As a halo fan I am obligated to call you a Noob Biscuit and tell you to commit suicide for the blasphemy you just wrote
Go to the top of the page
 
+Quote Post
   

3 Pages V   1 2 3 >
Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 30th September 2014 - 09:02 PM

RPGMakerVX.net is an Privacy Policy, Legal.