Jump to content
Vlue

Basic Game Time + Night/Day

Recommended Posts

Ice: The issue is that I had a switch that basically marked night time. The problem with this? Night time basically could be considered to take an expanse of game time between 8PM (20hr on a 24-hour clock) and 6 AM (6 am on a 24 hr clock)

 

So think about it for a bit: the hours needed to be encompassed are 20, 21, 22, 23... and then at 24, the clock becomes 0, 1, 2, 3, 4, 5 and 6. So the simple method works when we have a span of time where the value of the clock increases: 9am to 5pm is only 9 to 17. But 8pm to 5am is 20 to 5. You can't have a value that is greater than 20, and yet less than 5. Which is why two nestled conditional branches are needed to account for the fact that the values in the game clock reset when passing through the midnight marker.

Share this post


Link to post
Share on other sites

GameTime::hour? > ### or GameTime::hour? < ###

 

You're all thinkin' backwards :D

 

You can have a time that's either greater then sunset or lower then sunrise.

Share this post


Link to post
Share on other sites

I understand... Perhaps Vlue could explain this, he is better at this then I am.

I made an event.

 

Page 1 - Parallel Process

Condition branch: Script: GameTime::hour? == 6

Self-switch Operation A=ON

Switch Operation: [0001]Nighttime = OFF

Branch End

 

Page 2 -Parallel Process, Self switch A is on.

Condition branch Script: GameTime::hour? == 18

Self-switch Operation A=OFF

Switch Operation: [0001]Nighttime = ON

Branch End

 

Now this checks if its 6am if it is Night time switch is off and goes to page 2, when it becomes 6pm the night time switch turns on.

There are other ways to go about this, this method is simple I put something on the map (I assume you would have to create a common event for your purpose), anything effected by night time switch will show upon the second passage of time (Im not sure how to make it show right away, it basically needs to pass 24 hours then it works)

 

Edit: Vlue beat me to it! I could never understand those damn greater then less then symbols.

Edited by Ice Nick

Share this post


Link to post
Share on other sites

Vlue, is there any way to disable the clock at the very beginning of play, and then switch it back on with a trigger? I'm not talking about the toggle display- My game begins on a black background with text, and I need to disable the clock for that. Calling GameTime::clock(false) from a script at the very beginning is still too slow: the clock shows for a fraction of a second before the script drags it away, which isn't very good for the effect.

 

Another thing is that I'd like to have a fade out/fade in effect at two points: Sunrise and Sunset. Mostly because there are things that happen at sunset and at sunrise as far as events, but I'd prefer not to have WHAM, suddenly there's an old lady in the middle of the street without a transition. Any way to do that?

Edited by Maus Merryjest

Share this post


Link to post
Share on other sites

Vlue, is there any way to disable the clock at the very beginning of play, and then switch it back on with a trigger? I'm not talking about the toggle display- My game begins on a black background with text, and I need to disable the clock for that. Calling GameTime::clock(false) from a script at the very beginning is still too slow: the clock shows for a fraction of a second before the script drags it away, which isn't very good for the effect.

 

Another thing is that I'd like to have a fade out/fade in effect at two points: Sunrise and Sunset. Mostly because there are things that happen at sunset and at sunrise as far as events, but I'd prefer not to have WHAM, suddenly there's an old lady in the middle of the street without a transition. Any way to do that?

 

Shove between lines 201 and 202 (hopefully, right below "@gametimeclock = GameTime::Window_Clock.new if USE_CLOCK") this line:

@gametimeclock.visible = false if USE_CLOCK

 

As for the second bit, I don't know.. those old ladies are very sneaky...

Why is there no seconds in this... :/

You can have a parallel process common event running that does this

Condition Branch: Script: GameTime::hour? == %% and GameTime::minute? == 59    #Where %% is equal to the hour before sunset/sunrise
 TINT!
 GameTime::change(1)
end
Condition Branch: Script: GameTime::hour? == %%              #Where %% is equal to the hour of sunset/sunrise
 UNTINT!
end

Do it again for opposite and banana's, there you go. Hypothetically.

Edited by Vlue

Share this post


Link to post
Share on other sites

It works like a charm :)

 

Now, on the subject of avoiding sneaky old ladies, I got around that by imitating Ultima VI and VII. With your time and weather scripts, I also incorporated Khas' pathfinder and Shaz's Remember Event Position scripts. I made it so that all events start at their 'doors' in cities. At morningtime, they appear and they have a pathfinder destination to their pre-determined places. Once they reach there (or close enough, I have them on a wait command as opposed to store XY to variables and check every second, otherwise it'd LAG everything to hell), another switch flips up and they become interactable (they're at their job, or hangout, etc)-- some events act differently during rain: the little girl skipping rope in the park will run and take refuge under the gazebo... and she'll stay there the rest of the time because she doesn't want to get wet.

At night-time, everybody goes home, and the people that should be out at night come out and take their places, etc.

 

It helps make the game world feel more alive, so it works.

  • Like 1

Share this post


Link to post
Share on other sites

Hehe, it's all about the details! :D

Share this post


Link to post
Share on other sites

I'm all about the little details. There's one entrance the player characters use to get into a city-- through an underground well. They'll arrive at the bottom of the well shaft, have a little cutscene, and then leave into the city. I've set up a little sunbeam/moonbeam effect which changes according to time and weather, as different amounts of light filter down from the top.

 

The player, honestly, is only going to see this once, unless he decides to come back and hide in the well for some reason. But my design philosophy is that the world should feel alive enough for the player to want to explore it.

  • Like 1

Share this post


Link to post
Share on other sites

Vlue, your script is awesome. I love this thing.

But I'm sort of wondering if there's some way to incorporate a week system within your day/night system (or even better a calendar system.)

I have a little event that's supposed to happen every week (such as a character getting a little bit of gold; weekly allowance sort of thing) but my little knowledge on how to do something like that doesn't serve me well here.

Edited by SolarDragonflies

Share this post


Link to post
Share on other sites

Try this:

Parallel Process Common Event

 

>Conditional Branch: Switch %% ON
 >Conditional Branch: Script: GameTime::hour? == 0 and GameTime::minute? == 0
   >Control Variable: %% Add 1 
   >Condition Branch: Variable %% > 6
     >Control Variable: %% = 0
   -EndCB
   >Control Switch: Switch %% OFF
 -EndCB
-EndCB
>Conditional Branch: Script: GameTime::hour? == 23 and GameTime::minute? == 59
 >Control Switch: Switch %% ON
-EndCB

 

%% just represents a number, use the same switch for each switch call, and same variable for each. Variable will be equal to the day of the week, 0-6.

(Put it in a code box just because it looks neater :D)

Share this post


Link to post
Share on other sites

That looks great, though I am afraid of having too many paralell processes running in the background XD I do know that past a point, no new parallel processes will start up.

Share this post


Link to post
Share on other sites

Really you say? Interesting limitation...

Anywho, plop this under the game time script and edit WEEK_VAR to whatever variable id you want, does the same thing


module GameTime
WEEK_VAR = 1
class << self
alias s_update update
end
def self.update
 s_update
 @checked = false if @checked.nil?
 if !@checked
   if $game_time == 0
     $game_variables[WEEK_VAR] += 1
     if $game_variables[WEEK_VAR] > 6
       $game_variables[WEEK_VAR] = 0
     end
     @checked = true
   end
 end
 if $game_time == 1439
   @checked = false
 end
end
end

  • Like 1

Share this post


Link to post
Share on other sites

Ooh, quick question- how could I incorporate the day of the week displayed on the little timer HUD? It'd be nice to do "Saturday" "Sunday" etc, depending on the number of the day of the week--- but that'd be asking for too much, wouldn't it? :P

Share this post


Link to post
Share on other sites

Ooh, quick question- how could I incorporate the day of the week displayed on the little timer HUD? It'd be nice to do "Saturday" "Sunday" etc, depending on the number of the day of the week--- but that'd be asking for too much, wouldn't it? :P

 

Ah, you're lucky you're striped! Here ya go~

module GameTime
 WEEK_VAR = 1
 class Window_Clock < Window_Base
   def initialize
     case CLOCK_POSITION
     when 1
       super(0,0,175,56)
     when 2
       super(369,0,175,56)
     when 3
       super(0,360,175,56)
     when 4
       super(369,360,175,56)
     end
   end
   def update
     self.contents.clear
     self.contents.draw_text(0,0,100,24,GameTime::time?)
     day = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
     self.contents.draw_text(100,0,60,24,day[$game_variables[WEEK_VAR]].to_s)
   end
 end
end

  • Like 1

Share this post


Link to post
Share on other sites

Excellent script - however I do seem to have a problem. I read on the first page the module to add into make this compatible with the Khas Light effects however I seem to be having a problem. It seems that once I added this script in along with the module, khas stopped working all together. I can't manually call the effect on a screen and the light comments don't seem to work. Now I imagine this might have something to do with the position of the script? Is there a certain position this script should be placed in and is there another position that Khas should be placed in?

 

My second question is if this script is compatible with your climate script as well as the Khas script to.

  • Like 1

Share this post


Link to post
Share on other sites

Hale, the way I managed to make it work was to pause the time tinting in the rooms that I wanted to have a steady tint.

  • Like 1

Share this post


Link to post
Share on other sites

Excellent script - however I do seem to have a problem. I read on the first page the module to add into make this compatible with the Khas Light effects however I seem to be having a problem. It seems that once I added this script in along with the module, khas stopped working all together. I can't manually call the effect on a screen and the light comments don't seem to work. Now I imagine this might have something to do with the position of the script? Is there a certain position this script should be placed in and is there another position that Khas should be placed in?

 

My second question is if this script is compatible with your climate script as well as the Khas script to.

 

The way it's set up, if you wanted to call it manually (which I'm assuming you mean your own tinting) would require you to pause tinting, and then change it because it's constantly changing the tint otherwise, so if you made a change it will just get changed back. The comments are working for me... The order I have it in is GameTime, GameTime Khas Patch, Khas Lighting Effects, though their position shouldn't matter.

 

All my scripts are compatible with each other, in the sense that they won't explode when all being used. :D

Though I'm not sure about the natural tint effects of rain.

 

And while writing this the striped one answered, oh well, still replying.

Share this post


Link to post
Share on other sites

 

Hale, the way I managed to make it work was to pause the time tinting in the rooms that I wanted to have a steady tint.

Excellent script - however I do seem to have a problem. I read on the first page the module to add into make this compatible with the Khas Light effects however I seem to be having a problem. It seems that once I added this script in along with the module, khas stopped working all together. I can't manually call the effect on a screen and the light comments don't seem to work. Now I imagine this might have something to do with the position of the script? Is there a certain position this script should be placed in and is there another position that Khas should be placed in?

 

My second question is if this script is compatible with your climate script as well as the Khas script to.

 

The way it's set up, if you wanted to call it manually (which I'm assuming you mean your own tinting) would require you to pause tinting, and then change it because it's constantly changing the tint otherwise, so if you made a change it will just get changed back. The comments are working for me... The order I have it in is GameTime, GameTime Khas Patch, Khas Lighting Effects, though their position shouldn't matter.

 

All my scripts are compatible with each other, in the sense that they won't explode when all being used. :D

Though I'm not sure about the natural tint effects of rain.

 

And while writing this the striped one answered, oh well, still replying.

 

 

Thanks to both of you. That did it. I should have thought to pause the tint. Alright seems to be in working order. I suppose the next thing to check would be to see if the climate script works with Khas. Thanks again. This beats my old time system by far which was done with events. It is actually on this forums but modified by me to work with Khas. Lol. Finally able to scratch that :)

 

Another question. I was also reading in the thread a few people wanted to flip switches on at different point in time. I also read how we can do this with the conditional branch. However if we wanted couldn't we take it up a notch and essentially flip the switch in the khas module (for those using it)?

 

when MIDNIGHT_TIME .. PRESUNRISE_TIME
	  $game_map.effect_surface.change_color(tint,MIDNIGHT_TONE.red,MIDNIGHT_TONE.green,MIDNIGHT_TONE.blue,MIDNIGHT_TONE.gray)
	  $game_switches[MIDNIGHT] == true


	when PRESUNRISE_TIME .. SUNRISE_TIME
	  $game_map.effect_surface.change_color(tint,PRESUNRISE_TONE.red,PRESUNRISE_TONE.green,PRESUNRISE_TONE.blue,PRESUNRISE_TONE.gray)
	  $game_switches[MIDNIGHT] == false
	  $game_switches[sUNRISE] == true

 

Or is that totally off. Obviously i know you will have to declare the constants but couldn't that technically be done?

Edited by HalestormXV

Share this post


Link to post
Share on other sites

Another question. I was also reading in the thread a few people wanted to flip switches on at different point in time. I also read how we can do this with the conditional branch. However if we wanted couldn't we take it up a notch and essentially flip the switch in the khas module (for those using it)?

 

when MIDNIGHT_TIME .. PRESUNRISE_TIME
	  $game_map.effect_surface.change_color(tint,MIDNIGHT_TONE.red,MIDNIGHT_TONE.green,MIDNIGHT_TONE.blue,MIDNIGHT_TONE.gray)
	  $game_switches[MIDNIGHT] == true


	when PRESUNRISE_TIME .. SUNRISE_TIME
	  $game_map.effect_surface.change_color(tint,PRESUNRISE_TONE.red,PRESUNRISE_TONE.green,PRESUNRISE_TONE.blue,PRESUNRISE_TONE.gray)
	  $game_switches[MIDNIGHT] == false
	  $game_switches[sUNRISE] == true

 

Or is that totally off. Obviously i know you will have to declare the constants but couldn't that technically be done?

 

At first glance it should work fine, yes!

Though you would use "=" and not "=="

Edited by Vlue

Share this post


Link to post
Share on other sites

Yeah saw that after i typed it and forgot to edit it :P. You really would just have to make sure to turn the previous switch off so that you don't have two switches on at the same time. I am going to do a quick write up and I will edit this post with it. See if it looks like it will work.

 

EDIT: Added Switched. I think I got them all. I left the "Midnight Switch" on through the Midnight to Presunrise phase because I couldn't really think of anything clever to name the in between. I haven't tested this yet at least. But it should technically work, no?

 

  MIDNIGHT_SWITCH = #
 SUNRISE_SWITCH = #
 MORNING_SWITCH = #
 NOON_SWITCH = #
 DUSK_SWITCH = #
 EVENING_SWITCH = #
 SUNSET_SWITCH = #

 def self.init
	$game_time = 0
	$game_time_surface = $game_map.effect_surface
 end
	def self.tint(tint = 60)
	if USE_TINT != true then return end
	for i in NOTINTMAPS
	  if $game_map.map_id == i
			$game_map.effect_surface.change_color(0,10,10,10,25)
			return
	  end
	end
	if SceneManager::scene_is?(Scene_Map) then else return end
	case $game_time
	when PRESUNRISE_TIME .. SUNRISE_TIME
	  $game_map.effect_surface.change_color(tint,PRESUNRISE_TONE.red,PRESUNRISE_TONE.green,PRESUNRISE_TONE.blue,PRESUNRISE_TONE.gray)
	  $game_switches[MIDNIGHT_SWITCH] = false
	  $game_switches[sUNRISE_SWITCH] = true
	when SUNRISE_TIME .. NOONSTART_TIME
	  $game_map.effect_surface.change_color(tint,SUNRISE_TONE.red,SUNRISE_TONE.green,SUNRISE_TONE.blue,SUNRISE_TONE.gray)
	  $game_switches[sUNRISE_SWITCH] = false
	  $game_switches[MORNING_SWITCH] = true
	when NOONSTART_TIME .. NOONEND_TIME
	  $game_map.effect_surface.change_color(tint,NOONSTART_TONE.red,NOONSTART_TONE.green,NOONSTART_TONE.blue,NOONSTART_TONE.gray)
	  $game_switches[MORNING_SWITCH] = false
	  $game_switches[NOON_SWITCH] = true
	when NOONEND_TIME .. PRESUNSET_TIME
	  $game_map.effect_surface.change_color(tint,NOONEND_TONE.red,NOONEND_TONE.green,NOONEND_TONE.blue,NOONEND_TONE.gray)
	  $game_switches[NOON_SWITCH] = false
	  $game_switches[DUSK_SWITCH] = true
	when PRESUNSET_TIME .. SUNSET_TIME
	  $game_map.effect_surface.change_color(tint,PRESUNSET_TONE.red,PRESUNSET_TONE.green,PRESUNSET_TONE.blue,PRESUNSET_TONE.gray)
	  $game_switches[DUSK_SWITCH] = false
	  $game_switches[EVENING_SWITCH] = true
	when SUNSET_TIME .. 1440
	  $game_map.effect_surface.change_color(tint,SUNSET_TONE.red,SUNSET_TONE.green,SUNSET_TONE.blue,SUNSET_TONE.gray)
	  $game_switches[EVENING_SWITCH] = false
	  $game_switches[sUNSET_SWITCH] = true
	when 0 .. MIDNIGHT_TIME
	  $game_map.effect_surface.change_color(tint,SUNSET_TONE.red,SUNSET_TONE.green,SUNSET_TONE.blue,SUNSET_TONE.gray)
	  $game_switches[sUNSET_SWITCH] = false
	  $game_switches[MIDNIGHT_SWITCH] = true
	when MIDNIGHT_TIME .. PRESUNRISE_TIME
	  $game_map.effect_surface.change_color(tint,MIDNIGHT_TONE.red,MIDNIGHT_TONE.green,MIDNIGHT_TONE.blue,MIDNIGHT_TONE.gray)
	end
 end
end

 

 

EDIT 2: Just tested it. Yes it works. However keep in mind it will only switch the switch on once the tint occurs (and this only applies if you are using the Khas Patch). So for example if you start your game in a room where you have tinting disabled the switch will not turn on until the first form of tinting occurs. Byebye conditional branch lol

Edited by HalestormXV
  • Like 1

Share this post


Link to post
Share on other sites

What Hath Vlue Wrought? With the day system, now I can implement weekly schedules in NPCs.

 

Mwa hah hah.

  • Like 1

Share this post


Link to post
Share on other sites

Try this:

Parallel Process Common Event

 

>Conditional Branch: Switch %% ON
 >Conditional Branch: Script: GameTime::hour? == 0 and GameTime::minute? == 0
>Control Variable: %% Add 1
>Condition Branch: Variable %% > 6
  >Control Variable: %% = 0
-EndCB
>Control Switch: Switch %% OFF
 -EndCB
-EndCB
>Conditional Branch: Script: GameTime::hour? == 23 and GameTime::minute? == 59
 >Control Switch: Switch %% ON
-EndCB

 

%% just represents a number, use the same switch for each switch call, and same variable for each. Variable will be equal to the day of the week, 0-6.

(Put it in a code box just because it looks neater :D)

Thanks Vlue, I've been testing through this and it's what I was looking for; It does the job wonderfully but only partially it seems.

I'm a tiny bit stuck or atleast confused on how to call this common event up properly via a NPC I assigned though.

(I want to talk to this one guy, and after he'll begin to deliver me some amount of gold automatically every gameweek. (as an example)

Up to now though I've only really ever been able to successfully get him to give me (random amount of gold) after one week is over and then it'd stop after that and won't repeat when the next gameweek comes around, when really the process should continue running throughout the game.) I think I must be doing something a tiny bit wrong because it's definitely working partially. D:

Edited by SolarDragonflies

Share this post


Link to post
Share on other sites

Thanks Vlue, I've been testing through this and it's what I was looking for; It does the job wonderfully but only partially it seems.

I'm a tiny bit stuck or atleast confused on how to call this common event up properly via a NPC I assigned though.

(I want to talk to this one guy, and after he'll begin to deliver me some amount of gold automatically every gameweek. (as an example)

Up to now though I've only really ever been able to successfully get him to give me (random amount of gold) after one week is over and then it'd stop after that and won't repeat when the next gameweek comes around, when really the process should continue running throughout the game.) I think I must be doing something a tiny bit wrong because it's definitely working partially. D:

 

Hmm, do you have it as a parallel process common event? Or maybe the variable for day of the week isn't properly resetting back to zero, make sure if it does that.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
Top ArrowTop Arrow Highlighted