RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
Dynamic Lighting

0 Members and 1 Guest are viewing this topic.

***
Rep:
Level 60
Dynamic Lighting
Version: 1.5
Author: Marc of Fall From Eden
Date: March 17, 2012

Version History


  • <Version 1.5> 2012.03.17 - Added the ability to enable or disable all light effects through a switch ID.
  • <Version 1.4> 2012.03.14 - Merged the core script with the Player Lighting add-on and modified the core module accordingly.
  • <Version 1.2> 2012.02.18 - Provided a major bug fix for Dynamic Lighting (lights would "stick" to the window), a minor fix for Player Lighting (lighting changes would not be saved after loading a game), and provided another add-on script (Player Vignette) in the demo.
  • <Version 1.1> 2012.02.18 - Changed the way flickering is handled; also rearranged the "setup_lights" method and added the method "draw_lights". Also added the Player Lighting add-on.
  • <Version 1.0> 2012.02.16 - Original Release

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

  • Allows the creation of lights which emit from events on the map.
  • The visibility state and opacity of a light may be changed with script calls.
  • These changes are done without reloading Scene_Map, and can be persistent across map loads (with some minor eventing).
  • Given this, lights can be evented to blink or strobe directly on the map.
  • Different light types may use different pictures for their lighting effect.
  • All light types are written into a module that can be easily modified or extended.
  • You can have a dynamic light effect over the player.
  • Using the Player Vignette add-on, the player can optionally be surrounded by a dark vignette with modifiable size and opacity (perfect for dark dungeons and the like).

Screenshots





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, and the core script here. 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. For the player vignette, use this image for the default RMVX resolution or this one 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


  • Marc of Fall From Eden

Thanks

  • BulletXT and Kylock for the original Thomas Edison VX script. :)

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
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.
« Last Edit: March 22, 2012, 11:05:15 PM by Fall From Eden »

*
The Hero of Rhyme
Rep:
Level 83
( ͡° ͜ʖ ͡°)
2014 Queen of RMRKProject of the Year 20142014 Best RPG Maker User - Story2011 Best Newbie2014 Kindest Member2014 Best RPG Maker User - Creativity2013 Queen of RMRKBronze SS AuthorBronze Writing ReviewerSecret Santa 2013 ParticipantFor taking arms in the name of your breakfast.GOOD!For frequently finding and reporting spam and spam bots2012 Best Yuyubabe Smiley2012 Best RPG Maker User (Creativity);o
Prettyful. :V I extend my thanks to Marc, then.
Spoiler for My Games and Art:
ℒℴѵℯ❤


My Artwork Thread

The Lhuvia Tales [Current]

Ambassador [Complete]

The Postman [Complete]

The Wyvern [Complete]

Phoenix Wright: Haunted Turnabout [Complete]

Major Arcana [Cancelled]


***
Rep:
Level 60
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. :)

***
Rep:
Level 60
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! :)

**
Rep:
Level 62
Shou Akuma Chimera
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

^^''

***
Rep:
Level 60
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. :)

**
Rep: +0/-0Level 62
RMRK Junior
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.

***
Rep:
Level 60
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.

**
Rep: +0/-0Level 62
RMRK Junior
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.
« Last Edit: March 22, 2012, 06:07:41 PM by d_m_b87 »

**
Rep: +0/-0Level 62
RMRK Junior
I got it figured out I just went in and modified the picture. Much easier than figuring out the script haha.

***
Rep:
Level 60
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. :)

*
Rep:
Level 85
I solve practical problems.
For taking arms in the name of your breakfast.
Very Pretty, Its a shame I don't use vx :(

***
Rep:
Level 60
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. :)

**
Rep: +0/-0Level 67
RPGVX Advanced (I Do Not Script Tough)
Freakin' Sick Duude  ;D

**
Rep: +0/-0Level 67
RPGVX Advanced (I Do Not Script Tough)
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..     

**
Rep: +0/-0Level 67
RPGVX Advanced (I Do Not Script Tough)
Sorry Its Fixed  ;D It Was A Mistake Of Mine, It Wasn't The Light, But The Vignette I Wanted To Take  Away  :)

*
Rep: +0/-0Level 55
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.

****
Rep:
Level 57
Miiiiaf =^+^=
GIAW 14: ParticipantParticipant - GIAW 11
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
« Last Edit: October 05, 2012, 06:22:39 PM by Amycha19 »


As blonde as can be!!!
Doesn't mean I'm the dumb one...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Spoiler for supporting!: