Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Day/Night and Clear Lights with Clock

I have the same error as uldamoc :\

This script looks great, but what would make it more useful for me is to replace the $game_variables with the Time class.
In my case, I have a constantly updating $time global variable.

I've attempted to edit this multiple times to change it to Time format, but the code is sort-of messy, and I just cant get it to work with the time class.
Could you make another copy that reads just from a single variable (for the time)?

By the way, you can suppress (but i don't think it fixes it) the error by adding under line 295:

next if event.list == nil
 
Wow thanks ZenVirZan! That actually did the trick.

The script no longer conflicts with inactive variables and switches.. but I'm curious if there is a way to set the darkness manually without messing with the time system. For example, going into a cave during the day but the screen will become dark (to emulate the darkness of a cave) while the time system still runs.

Doesn't make much sense to have your underground caves or dungeons light up during the day and only be dark at night lol. Maybe a house with windows.. but not caves, dungeons, cellars etc.

Could this possibly be done with a switch or variable? (Example: You walk into a cave and Switch [Darkness]=ON activates) ..and for that matter is there a way to replace the 3 variables that are being used by the script with a variable number of your choice? All of the script's variables are using variables that my game is already using and it would be horrible to have to replace all of them. (Though not impossible.. just a huge pain)

For now I'm going to just disable time and manually set the time of day to get the dark effect I need.

Anyway.. thanks again ZenVirZan for the help!
 
uldamoc":30fs297o said:
I'm curious if there is a way to set the darkness manually without messing with the time system. For example, going into a cave during the day but the screen will become dark (to emulate the darkness of a cave) while the time system still runs.

Doesn't make much sense to have your underground caves or dungeons light up during the day and only be dark at night lol. Maybe a house with windows.. but not caves, dungeons, cellars etc.

Could this possibly be done with a switch or variable? (Example: You walk into a cave and Switch [Darkness]=ON activates) ..and for that matter is there a way to replace the 3 variables that are being used by the script with a variable number of your choice? All of the script's variables are using variables that my game is already using and it would be horrible to have to replace all of them. (Though not impossible.. just a huge pain)

For now I'm going to just disable time and manually set the time of day to get the dark effect I need.

This is already in the script. check lines 42 - 57:
from the script":30fs297o said:
[rgss]# Inside_Switch is the switch set to make insides darker, not meant for caves
#-----------------------------------
INSIDE_SWITCH = 9
 
# Inside_Opacity is the opacity set to increase when entering insides
#-----------------------------------
INSIDE_OPACITY = 10
 
# Cave_Switch is the switch set meant for caves
#-----------------------------------
CAVE_SWITCH = 11
 
# Cave_Opacity is the total opacity you want when entering caves.  Generally
# Should be set higher than the highest darkness.
#-----------------------------------
CAVE_OPACITY = 220
[/rgss]

Those numbers represent the switches used to trigger houses and caves as well as the opacity. you can change the number to the switch id that you are using.
 
I've got a problem -
All of the lights on the map have a comment light300
But only 1 of them is large. The rest are only the 100 size.
I added some prints into the script - the size variable is fine, its just drawing it wrong. Any ideas?

EDIT:
Appears to occur when 2 lights are near each other - i dont thing the

'self.bitmap.stretch_blt(light_rect, image_blt, base_rect)'

line is ever run (making it bigger) if you have to run

'self.bitmap.sub(light.x,light.y,image_sub)'

which does when the 'if overlapLights.size == 0' isnt == 0.

. . . if that makes sense?

EDIT2:
And even the default light100 lights are slightly different sizes to each other :\
 

Star

Sponsor

ZenVirZan":3eagpvfb said:
I've got a problem -
All of the lights on the map have a comment light300
But only 1 of them is large. The rest are only the 100 size.
I added some prints into the script - the size variable is fine, its just drawing it wrong. Any ideas?

EDIT:
Appears to occur when 2 lights are near each other - i dont thing the

'self.bitmap.stretch_blt(light_rect, image_blt, base_rect)'

line is ever run (making it bigger) if you have to run

'self.bitmap.sub(light.x,light.y,image_sub)'

which does when the 'if overlapLights.size == 0' isnt == 0.

. . . if that makes sense?

EDIT2:
And even the default light100 lights are slightly different sizes to each other :\
I'm not so sure about the sizing part or overlapping part since most of that was brew and gubid or gubid and brew, however you look at it. But I have discovered a work around for your problem, kinda stupid in a sense cause you have to make more graphics for bigger lights next to each other. I just made the normal sub graphic three times it's size and named it LightSUBBIG.

Code:
  def apply_lights

    applied_space = []

    for light in @lights.values

      image_sub = RPG::Cache.picture("LightSUB").clone

      image_blt = RPG::Cache.picture("LightBLT").clone

      image_sub2 = RPG::Cache.picture("LightSUBBIG").clone

      base_rect = image_sub.rect

      overlapLights = []

      size = (light.size/100.0)

      lwidth = base_rect.width*size

      light_rect = Rect.new(light.x-(lwidth/2), light.y-(lwidth/2), lwidth, lwidth)

      for applied_rect in applied_space

        if light_rect.overlap?(applied_rect)

          overlapLights << light_rect.area_in_overlap(applied_rect)

        end

      end

      #now draw it 

      if overlapLights.size == 0 #no overlap detected.. then just BLT it into the image

        self.bitmap.fill_rect(light_rect, Color.new(0,0,0,0))

        self.bitmap.stretch_blt(light_rect, image_blt, base_rect) 

      else

        if size == 3

          self.bitmap.sub(light.x,light.y,image_sub2)

          else

        self.bitmap.sub(light.x,light.y,image_sub)

          end

      end

      applied_space << light_rect

      image_sub.dispose

      image_sub2.dispose

      image_blt.dispose

    end

  end

Then that would make any lights next to each other with a light300 sub to normal size. I'm not currently working with this script because it basically suits all my needs but I'll try to help anyway I can.

Yeah I noticed the inactive switch error a while back. My first work around was to make the first page of any event be blank if it needed a switch or variable condition. My next work around or fix was unless event.erased or event.list == nil after the line that says
for event in $game_map.events.values.

I've attempted to edit this multiple times to change it to Time format, but the code is sort-of messy, and I just cant get it to work with the time class.
Could you make another copy that reads just from a single variable (for the time)?

I'm not sure what you mean by this. You're wanting a variable that just reads time? Basically rmxp reads every second as 40 frames in the scripts. I just use the timer under the system class. I've tried to make my own time class, but it never worked and it was just more convenient to use the timer because it's accessible in the events.
 

Batman

Sponsor

Is there any possibility that I can have say...a store open only certain hours (during the day) and have it closed during the other hours? (Night)

Also, I'm a very graphic heavy user (photoshop graphic artist), and I've noticed that the darkness seriously interferes with the graphics that show up.

e.g:
headache.png

The windowskin and faceset (which are both just pictures) SHOULD be much brighter
 
You can adjust the Z height of the overlay map.

Just edit:
Code:
 

#---------------------------------------------

#Spriteset_Map

#---------------------------------------------

class Spriteset_Map

  alias init_spr_map_lights initialize

  def initialize

    # Make nighttime sprite

    @nighttime = Nighttime.new(0,0)

    @nighttime.z = 2000   #THIS LINE TO HAVE A LOWER NUMBER

    init_spr_map_lights

    @nighttime.refresh

    @map_idd = $game_map.map_id

  end

 

And yes, just attach your store to only show up during the dependant hours. You would use the time variable and just make a guess on where those hours would be.
 
Anything can be done to show a "light" on your character using the comment method? because when you try with show picture it won't work as the script covers the map with black tinting.

Also is there a way to fix the lights not going away when you try to do so but have to go in a new map or open/close inventory to have them go away?

Thanks
 
I like this script a lot, but seem to be having a bug with my combat system (atoa cbs with atb), It seems that any time youre in battle at midnight the combat is ended and the player is brought back to the map, I cant find any particular variable conflicts, or code overlaps. I figure the easiest way to handle this is to simply disable the timer during combat, since i kind of wanted to do that any way. How could I go about intergrating that?
 
So no one found a way to make some sort of light show on your character while moving?

My game is going to be very dark and I wish I could use some small light source around my character since using a picture as light source is not going to work with this script.
 
This script in itself is pretty nice, but it would be cool, if you added the ability to use light if you had a certain item, as well as have the light source follow the events. I started on it myself, got it to follow events and such, but the way you draw the bitmap made it lag a little when I redrew for new positions, Id work on it more but dont have enough time.
 
Wish someone does.

I could use it for having a light source in my project to use during the night. (In my project during the night it's very very dark apart of some lights like fires or tvs, lamps etc etc but these won't be everywhere specially when outside in the world.)
 

regi

Sponsor

I've been looking over the script, and I believe I found a small error in the Rect overlap? function (from line 144):
Code:
def overlap?(rect)

    corners = []

    corners << [rect.x, rect.y] #UL

    corners << [rect.x+rect.width, rect.y] #UR

    corners << [rect.x+rect.width, rect.y+height] #LR

    corners << [rect.x, rect.y+height] #LL
should read:
Code:
def overlap?(rect)

    corners = []

    corners << [rect.x, rect.y] #UL

    corners << [rect.x+rect.width, rect.y] #UR

    corners << [rect.x+rect.width, rect.y+rect.height] #LR

    corners << [rect.x, rect.y+rect.height] #LL

I'm doing a bit more tinkering to see if the lights can follow the player/moving events (right now, they don't seem to update and just stay in place, even if the player moves...) Will post updates as I go!
 

regi

Sponsor

If anyone's still interested in getting a light for the player, try this (hope you don't mind me messing around with your script ;)

At the top, create a variable: DEFAULT_RADIUS = 100 and change the value to what you want the player's light radius to be.

In "create_lights" (line 295), add the following segment above the line "for event in $game_map.events.values":
Code:
  def create_lights

    if $game_switches[CAVE_SWITCH] == true

      @lights[$game_player] = Light.new($game_player, DEFAULT_RADIUS)

    elsif @lights[$game_player] != nil

      @lights.delete($game_player)

    end

    

    for event in $game_map.events.values

      ...

    end

  end

In "def update", add the following before the last end (line 441):
Code:
  def update

    ...

    for light in @lights.values

      if light.x != light.old_x or light.y != light.old_y

      refresh

      return

    end

 

  end
Finally, change "class Light" (line 461) to the following:
Code:
class Light

  attr_reader :old_x

  attr_reader :old_y

  

  def initialize(event, size)

    @event = event

    @size = size

    @old_x = self.x

    @old_y = self.y

  end

  def size

    return @size

  end

  def x

    return @event.real_x/4 + 16

  end

  def y

    return @event.real_y/4 + 16

  end

end



Unfortunately, the downside to moving lights is that it lags. A LOT. If you have at least two lights overlapping, and one of them moves, refreshing every frame will drain the frame rate (for me, combined with my pixelmovement ABS scripts, down to around 7fps on a large map :sad: ). I've identified the problem to be the "sub" function. Gonna hand this over to any scripting gurus out there, any way to make it more efficient?
 
I just tried it but was getting several errors so I switched back and besides until the lag is removed from moving lights I'd rather not use it, but it's nice people are still trying to fix this script.

I hope someday it gets fixed, I really would love a sort of light source I could use on my character when you find a flash light for example which can be switched on/off.
 

regi

Sponsor

Fixed my above post, it should work now.
Unfortunately the lag issue still stands... I think partly because instead of updating each light individually, it refreshes the whole nighttime effect (every single light). When I have time later I'll look into creating a refresh function for each individual light sprite.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top