The RPG Maker Resource Kit

RMRK RPG Maker Creation => VX => VX Scripts Database => Topic started by: Fall From Eden on February 17, 2012, 12:06:06 AM

Title: Dynamic Lighting
Post by: Fall From Eden on February 17, 2012, 12:06:06 AM
Dynamic Lighting
Version: 1.5
Author: Marc of Fall From Eden
Date: March 17, 2012

Version History



Description


This script allows you to place dynamic lights that emit from events on the map. The main difference between this script and scripts such as Thomas Edison VX or Kylock's Light System is the fact that lights may be enabled or disabled while the scene is running without requiring the script call "$scene = Scene_Map.new" (which causes the screen to momentarily freeze). The opacity level of lights may also be changed while the scene is running, thus allowing you to event systems that allow lights to smoothly blink or strobe (or any other effect you can think of utilizing the visibility and opacity of lights).

The way light types are defined has changed dramatically as well, allowing you to define your own lights and their properties easily through a module. This way, you can have lights with differing x and y zoom values (in essence, creating lights with different shapes), and light types may also use different pictures (for instance, lanterns could have a different light picture displayed than torches).

The script also enables you to have a light effect dynamically created over the player's character in-game with the same dynamic qualities as any other light shown on the map.

The script demo also includes a module that attempts to recreate the light effects seen in Thomas Edison VX.

Features


Screenshots

(https://rmrk.net/proxy.php?request=http%3A%2F%2Fdl.dropbox.com%2Fu%2F7444326%2FRGSS2%2FPictures%2FDynamic%2520Lighting%25201.png&hash=7bbd2990d961632f9f9bec2b79ea376e3b6dc9db)

(https://rmrk.net/proxy.php?request=http%3A%2F%2Fdl.dropbox.com%2Fu%2F7444326%2FRGSS2%2FPictures%2FDynamic%2520Lighting%25202.png&hash=5e13ff6116d93fd49b2633eaa86e359eecd22936)

Instructions

It is highly recommended that you download the script demo so as to learn how the effects were done and how to use the Marc::Light module effectively.

In any case, the script itself can be used as a drop-in replacement for Thomas Edison VX. By doing this, however, you may miss out on some of the more interesting features of this script (for instance, how to event lights so that they can blink or strobe on the map and save their visibility states).

You may create a light in the same way it is done in Thomas Edison VX: by creating a comment in the event you want to create light containing the name of the light type you want to emit (the light types are defined in the module Marc::Light and are clearly labeled). To hide the light effect when the map loads, simply append the word "INVISIBLE" to the name of the light type (for example, you could write the comment "FIRE INVISIBLE" without quotes to create a light of FIRE type that is hidden when the map is loaded).

To change the visibility state of a light on the map, you must make a script call. The method to set the visibility state is "set_light_visibility", and it takes up to two arguments: the event ID of the light you want to change, and the visibility state (which may be one of true, false, or "toggle"). If the visibility state argument is left out, the script will default to toggling the visibility of the light. So, to change the visibility state of the light on event ID 5, you could write any of the following (depending on the desired effect):

Code: [Select]
set_light_visibility(5, true)
set_light_visibility(5, false)
set_light_visibility(5, "toggle")
set_light_visibility(5) # functionally identical to set_light_visibility(5, "toggle")

Similarly, you can set the opacity level of a light on the map with the method "set_light_opacity". This method explicitly requires two arguments: the event ID of the light you want to modify, and the desired opacity level (from 0 to 255, 0 being fully transparent). The second argument can also use a variable (such as $game_variables[1]) that you can set with events.

Code: [Select]
set_light_opacity(5, 75)
set_light_opacity(5, $game_variables[1]) # sets the opacity to the value of Variable 1.

The last method, "light_visible?", simply returns true or false based on the visibility state of the light on the event ID specified by its argument. Given the nature of this method, the only argument you should provide is the event ID of the light you want to check.

Code: [Select]
light_visible?(5) # returns either true or false

This method can be used effectively in conditional branches for dynamic lights that you may wish the player to turn on and off via an external event (such as a floor plate or light switch). You could also potentially use this to create evented systems such as fire arrows that can light torches and give the player the ability to blow the torches back out. :)

With the Player Lighting add-on, a few new methods have been added to Game_Interpreter. These are the methods "player_light_visible?", "set_player_light_vis", "set_player_light_type", and "get_player_light_type".

The method "player_light_visible?" simply returns a true or false value based on the visibility of the player light. It requires no arguments, and doesn't expect any.

Code: [Select]
player_light_visible? # returns true or false

If you need to change the visibility of the player's light (for instance, if they turn off or lose whatever was generating the light), use the method "set_player_light_vis". This method has one optional argument: the visibility state to set the light to. This state can be one of true, false, or "toggle", and the method defaults to "toggle" if no argument is given.

Code: [Select]
set_player_light_vis(true)
set_player_light_vis("toggle")
set_player_light_vis # functionally identical to set_player_light_vis("toggle")

In order to change the light type shown on the player, use the method "set_player_light_type". This method takes one optional argument: the name of the type you wish to change the player's light to. If no argument is given, the type is reset to the default value supplied in the configuration section of the Player Lighting add-on.

NOTE: Light type changes are not dynamic. If you change the player's light type while on the map, you will have to make the script call "$scene = Scene_Map.new" due to the way light types are initialized.

Code: [Select]
set_player_light_type("TORCH")
set_player_light_type # reverts to default player light type

You can also get the current type of the player's light with the method "get_player_light_type". This method returns the player's light type as a string (which you could potentially use in Conditional Branches). No arguments are necessary or expected.

Code: [Select]
get_player_light_type

Script


You really should grab the demo. But in case you want just the script, you will have to grab the module here (http://dl.dropbox.com/u/7444326/RGSS2/Scripts/Dynamic%20Lighting%20Module.rb), and the core script here (http://dl.dropbox.com/u/7444326/RGSS2/Scripts/Dynamic%20Lighting.rb). You will also require a picture named "le" to use for your light effects if you use the supplied module. We recommend the one we made for it (http://dl.dropbox.com/u/7444326/RGSS2/Pictures/le.png). For the player vignette, use this image (http://dl.dropbox.com/u/7444326/RGSS2/Pictures/pv.png) for the default RMVX resolution or this one (http://dl.dropbox.com/u/7444326/RGSS2/Pictures/pv_640x480.png) for games using 640x480 resolution. If you use the 640x480 vignette, make sure to rename it to pv.png or change the value used for the vignette in the script's module.

Credit



Thanks


Support


You may receive support for this script in this topic or by sending us a personal message on these forums.

Known Compatibility Issues

This script will technically function properly if used in conjunction with Thomas Edison VX, but that really defeats the entire purpose, and will layer two lights on each event. As obvious as that may seem, we still thought it was worth mentioning. ;)

There is also a bug that we know about, but cannot seem to fix at the moment. If you have a map that is set to scroll horizontally, vertically, or both, the light effects will disappear if the same event is seen on the map twice and reappear once the event is shown on the map a single time. We think we know why this happens, but are currently at a loss as to how to fix the bug. If anyone has any ideas or thinks they can fix it, please feel free! Just let us know how you did it or how we can implement the bug fix. ;)

Demo


Dynamic Lighting Script Demo (http://dl.dropbox.com/u/7444326/RGSS2/Demos/Marc%20Dynamic%20Lighting.exe)
Includes the module, core script, and Player Vignette add-on.

Author's Notes


Download the demo. Really, it's very useful to see how everything works. ;)

With that said, this script was primarily written for our own needs while creating an atmospheric adventure-style game. Considering the thick atmosphere, we required lighting that could change dynamically in-game without reloading Scene_Map. After looking at the original Thomas Edison VX script, we decided to essentially rewrite the entire system from scratch... and ended up implementing it in a very different way.

In any case, if anyone would like to suggest improvements to the script, please feel free to let us know what you have in mind! :)

Restrictions

This script is licensed under a Creative Commons BY-SA 3.0 license. Essentially, you may use it for commercial games, but proper attribution is required; as well, you may modify the script any way you like as long as the modified version retains attribution to the original author and is released under an identical license.
Title: Re: Dynamic Lighting
Post by: yuyu! on February 17, 2012, 01:38:10 AM
Prettyful. :V I extend my thanks to Marc, then.
Title: Re: Dynamic Lighting
Post by: Fall From Eden on February 18, 2012, 06:31:06 AM
Marc: Thank you very much. :)

I am also posting this due to an update to the original core script; some things have been changed quite a bit (at least from the perspective of the user). I have also quickly written an add-on that can be used to provide the player with a dynamic light as a "lantern" effect that smoothly follows the character. This add-on and the update have now been added to the script demo. :)
Title: Re: Dynamic Lighting
Post by: Fall From Eden on March 17, 2012, 07:23:03 PM
Marc: Just to let everyone know, the script has now been updated to version 1.5. This version lets the user define a switch ID to enable and disable the processing of light effects (not just their visibility). The add-on Vignette script has also been updated to version 1.0 and now has the same feature (if you wish to see how this works in practice, feel free to play-test the demo and enable or disable the switches through the F9 debugging menu). :)

The script demo has been updated accordingly. Thank you! :)
Title: Re: Dynamic Lighting
Post by: Tetosan on March 21, 2012, 11:13:58 PM
Hey i've ran into a problem with this script:

I wanted to make an Testmap where i can see every lightning Effect on it's own but when i press new game this Error pops up:

Script 'Dynamic Lightning line 289: TypeError occured.

cannot convert Array into Integer

^^''
Title: Re: Dynamic Lighting
Post by: Fall From Eden on March 22, 2012, 01:13:32 AM
Marc: Ah, my mistake. I must have overlooked that line while rewriting the way opacity flickering works. Thank you for reporting it! :)

Replace this:
Code: [Select]
@light.opacity = rand(@data[6] * 3) + (opacity - (@data[6] * 3))

With this:
Code: [Select]
@light.opacity = rand(@data[6].to_a[0] * 3) + (opacity - (@data[6].to_a[0] * 3))

It should function properly once that has been done. The demo and script will be updated to reflect this change. :)
Title: Re: Dynamic Lighting
Post by: d_m_b87 on March 22, 2012, 08:22:38 AM
I want to start with saying that this is a great script. I have one minor issue I was hoping you could help me with tho. I'm using yanflys engine melody, and one of those scripts makes the screen size bigger. That offsets the player vignette by about five tiles. I was wondering if you could tell me how to change the x and y coordinates for the vignette pic. I'd really appreciate it.
Title: Re: Dynamic Lighting
Post by: Fall From Eden on March 22, 2012, 04:26:55 PM
I want to start with saying that this is a great script. I have one minor issue I was hoping you could help me with tho. I'm using yanflys engine melody, and one of those scripts makes the screen size bigger. That offsets the player vignette by about five tiles. I was wondering if you could tell me how to change the x and y coordinates for the vignette pic. I'd really appreciate it.

Marc: The X and Y coordinates for the vignette are specified in the update method of Marc_Vignette (specifically, the lines that begin with @vignette.x and @vignette.y). Without seeing the script you're using to change the screen resolution, I'm not sure how to help without telling you to fiddle with those formulas.
Title: Re: Dynamic Lighting
Post by: d_m_b87 on March 22, 2012, 05:01:29 PM
I'm not exactly sure which one changes the screen resolution, since there were about eight scripts of yanflys I put in at the same time. I'll figure it out tho and then post it for you to look at. Thanks.

Edit: Damn it turns out I can't post the script. I'm using an damn iPhone cause its the only access I have to the Internet. I did find out which script was changing the resolution tho. It's YEM Core Fixes and Upgrades. If you want to take the time to find the script that would be great. If not I'll understand.
Title: Re: Dynamic Lighting
Post by: d_m_b87 on March 22, 2012, 08:03:18 PM
I got it figured out I just went in and modified the picture. Much easier than figuring out the script haha.
Title: Re: Dynamic Lighting
Post by: Fall From Eden on March 22, 2012, 08:30:12 PM
I got it figured out I just went in and modified the picture. Much easier than figuring out the script haha.

Glad to know that you got it to work as intended without having to modify the script. We'll also update the original post sometime later tonight with a vignette image to be used for games using 640x480 resolution (since that seems to be relatively common lately).

Thanks for posting about it. :)
Title: Re: Dynamic Lighting
Post by: IAMFORTE on March 22, 2012, 10:27:46 PM
Very Pretty, Its a shame I don't use vx :(
Title: Re: Dynamic Lighting
Post by: Fall From Eden on March 22, 2012, 11:02:46 PM
Very Pretty, Its a shame I don't use vx :(
And it's a shame that we don't have a copy of XP, or we'd consider porting it. :(

Also, we're updating the initial post now to include a 640x480 vignette picture for those of you using that screen resolution for your games. :)
Title: Re: Dynamic Lighting
Post by: digdarkevil on June 17, 2012, 01:51:00 AM
Freakin' Sick Duude  ;D
Title: Re: Dynamic Lighting
Post by: digdarkevil on July 15, 2012, 02:27:03 PM
I Cant Turn Off The Players's Light  :-\
I Set This To False

    PLAYER_LIGHT_VISIBILITY = false

But The Light Is Still Visible, I Have Tried The Script Call
set_player_light_vis(false) And Nothing Happened... Sorry To Bother You With This I Was Just Wondering If I Did It Correctly Or It Is A Uncompatibility With One Of My Other Scripts Or Something..     
Title: Re: Dynamic Lighting
Post by: digdarkevil on July 15, 2012, 02:34:57 PM
Sorry Its Fixed  ;D It Was A Mistake Of Mine, It Wasn't The Light, But The Vignette I Wanted To Take  Away  :)
Title: Re: Dynamic Lighting
Post by: megane-kun on October 03, 2012, 10:23:57 AM
I am not sure if this should go here or in the Simple Shadows script thread, but I was wondering if there's a way to make the player (with the player vignette turned on) cast shadows on objects as if the player is carrying a light source.

Thanks and apologies if I had posted in the wrong place.
Title: Re: Dynamic Lighting
Post by: Little Psycho on October 05, 2012, 06:18:05 PM
Hi,

I have a small but rather important question about this script.
Is there a way I can spread the light over 2 spaces?
I want to get a faint red glow from the windows and they are 1wide but 2 high...


Thanks!! :D

EDIT: I found a sollution!! Thanks :D