Help - Search - Members - Calendar
Full Version: [Eventing]Extremely Simple Day/Night
RPG RPG Revolution Forums > Game Engines > RPG Maker XP Discussion > RPG Maker XP Tutorials
Nuque
Okay, are you someone who just wants a watch and for their maps to get darker through the day? Then this is for you.

Steps 1 + 2 are parallel process common events with a switch activation
For steps 1 + 2 create an autorun map event that turns on a switch and then erases itself
For step 3 place the script anywhere, I put it below the default scripts and before main. Just copy and paste

[Show/Hide] Core System
Step 1: Minutes and Hours
CODE

Put in the following commands in a common event: (Dont forget a switch to activate it!!)

@>Control Variables:[0002:Hours] = 10 (When you want day to start. This is also when the screen will become daytime)
@>Loop
@>Wait 1 frame(s)
@>Control Variables: [0003: Seconds] += 1
@>Conditional Branch: [0003: Seconds] = 25
@>Control Variables: [0001: Minutes] += 1
@>Control Variables: [0003: Seconds] = 0
@>Conditional Branch: Variable [0001: Minutes] == 60
@>Control Variable: [0001: Minutes] == 0
@>Control Variable: [0002: Hours] += 1
@>
: Branch End
@>Conditional Branch: Variable [0002: Hours] ==13
@>Condition Branch: [0004: AM/PM] = 1
@>Control Variables: [0002: Hours] = 1
@>Control Variables: [0004: AM/PM] = 2
@>Control Switches: [0001: PM] = OFF
Else
@>Control Variables: [0002: Hours] = 1
@>Control Variables: [0004: AM/PM] = 1
@>Control Switches: [0001: PM] = ON
: Branch End
@>
: Repeat Above
@>





Step 2: Day and Night
CODE


Put in the following in a common event: (Dont forget a switch to activate it!!)

@>Loop
@>Condition Branch: Switch [0001: PM] = ON
@>Conditional Branch Variable [0002: Hours] = 10 < make this number when night starts! (here its 10 pm)
@>Change Screen Color Tone: (-187, -119, -34, 68)
@>Control Switches: [0002: Night] = ON
@>
: Branch End
@>
: Branch End
@>Condition Branch: Switch [0001: PM] = OFF
@>Conditional Branch Variable [0002: Hours] = 6 < make this number when morning starts! (here its 6 am)
@>Change Screen Color Tone: ( 0, 34, 0, 0)
@>Control Switches: [0002: Night] = OFF
@>
: Branch End
@>
: Branch End
@>Condition Branch: Switch [0001: PM] = ON
@>Conditional Branch Variable [0002: Hours] = 10 < make this number when day starts! (here its 10 am)
@>Change Screen Color Tone: ( 0, 0, 0, 0)
@>
: Branch End
@>
: Branch End
@> Wait: 1 frame(s)
@>
: Repeat Above
@>

Cool, aint it?

Test it out, its awesome!!!!
Heres a screenie to look at:



Note that the hud is optional and does not have to be used, instead you can use a watch on the menu screen, an item, or a map event.
This is covered in the next spoiler tag.



[Show/Hide] Watch/Hud
Option A: Watch On Menu Screen

Edit def refresh in Window_PlayTime to look like this:
CODE

def refresh
self.contents.clear
self.contents.font.color = system_color
self.contents.draw_text(4, 0, 120, 32, "Time")
@total_sec = Graphics.frame_count / Graphics.frame_rate
hour = $game_variables[2]
min = $game_variables[1]
text = sprintf("%02d:%02d", hour, min)
self.contents.font.color = normal_color
self.contents.draw_text(4, 32, 120, 32, text, 2)
end

If it shows 0s, change these lines:
hour = $game_variables[2] Change 2 to your hour variable
min = $game_variables[1] Change 1 to your minute variable


Option B: Hud
CODE

class Window_YourHUD < Window_Base
def initialize
super(0, 416, 640, 64)
self.contents = Bitmap.new(640 - 32, 64 - 32)
refresh
end
def refresh
self.contents.clear
reset_variables
return if !@actor
draw_actor_hp(@actor, 0, 0)
draw_actor_sp(@actor, 160, 0)
self.contents.font.color = system_color
self.contents.draw_text(320, 0, 60, 32, "Time")
@total_sec = Graphics.frame_count / Graphics.frame_rate
hour = $game_variables[2]
min = $game_variables[1]
text = sprintf("%02d:%02d", hour, min)
self.contents.font.color = normal_color
self.contents.draw_text(400, 0, 60, 32, text, 2)
end
def reset_variables
@actor = $game_party.actors[0]
@old_hp = @actor ? @actor.hp : 0
@old_maxhp = @actor ? @actor.maxhp : 0
@old_sp = @actor ? @actor.sp : 0
@old_maxsp = @actor ? @actor.maxsp : 0
end
def update
super
refresh if (@actor = $game_party.actors[0] or
@old_hp = @actor ? @actor.hp : 0 or
@old_maxhp = @actor ? @actor.maxhp : 0 or
@old_sp = @actor ? @actor.sp : 0 or
@old_maxsp = @actor ? @actor.maxsp : 0)
end
end
class Scene_Map
alias yourhud_main main
alias yourhud_update update
def main
@yourhud = Window_YourHUD.new
yourhud_main
@yourhud.dispose
end
def update
@yourhud.update
yourhud_update
end
end


If there is an error, change the lines
hour = $game_variables[2]
min = $game_variables[1]
to
hour = $game_variables[y] y = your hour variable
min = $game_variables[x] x = your min. variable





Addon 1 : Bed System (Map Event)
CODE

@>Change Screen Color Tone: ( 0, 34, 0, 0)
@>Wait: 20 frame(s)
@>Play ME: '014-Inn01", 100, 100
@>Control Variables: [0002: Hours] = 7 <<This is your time when waking up
@>Control Variables: [0001: Minutes] = 30 << This is your minutes, together its 7:30
@>Control Variables: [0003: Seconds] = 0
@>Control Variables: [0004: AM/PM] = 2
@>Wait: 60 frame(s)
@>Change Screen Color Tone: (0, 0, 0, 0)
@>


Coming Soon:

1. Weather System - just needs to be added (extremely buggy, ill post it, but you have to help me out!)
2. Houses dont get dark until bedtime (9:30?) - to be done
3. Bed System - DONE!
4. Lightning in my weather system (also easily done)

Sorry if im lazy, ill get these done eventually.




!!!!NEW!!!!
Demo Available!!!
punk13
Looks cool 1) in common events do you mean the ones in the database or make an event on the map
2) does the code go under main?

sorry i just got back into rpgmaker after a 2 year rest.
Nuque
here are some answers fer ya

1. An parallel process event in the database. Then make a autorun map event that turns your switch on and then erases itself.

2. The code can go anywhere you want it to go. I have it after all of the default scripts. But it HAS to be AFTER MAIN.
Night_Runner
Edited: Have you tried this while changing maps? I had a go at the whole loop thing using common events and my loops broke sad.gif

I like your scripting though, I have no idea how to script, but I think I could learn alot from using yours smile.gif
Rukiri
Not bad, though this is simple...

Though XD a true day/night can be done by events, scripting is lame since not EVERYTHING needs to be scripted, menu's, movement sure, but battle systems can be evented with the help a few scripts, I prefer evented battles because it's your own and all an abs really is, is just detecting X/Y, now if you play LOG, Som, SD, you'll notice if you hit it at a high point in the sprite it'll move diagonal well that's natural in an abs and all it is, is X/Y detection.

Though for stretching an image... that might require a script"I'd ask for help on that one"

Great system overall, but I'll share my own tomorrow since I'm a bit busy now, also RMXP can be compared to Game Maker if you have pixel-movement added, I actually find XP's scripts to be better than GM, GM for rpg's is just not worth it in a long run.
Nuque
uh, Night_runner, quite frankly, you are completely wrong.

It is a parrallel process meaning that it works along side all other events. You activate the switch once,
and it goes on forever without ever being interrupted by anything. Tho only way that could happen is if you
turn off then turn on the switch in one event (Then it would restart)

Also, im not a scripter, I can only do basic stuff.
Im a developer, writer, spriter, and eventer
Night_Runner
No problems shantanu, but did you actually physically try it?
(Don't you hate it when the only thing someone congratulates you on is the bit you didn't do? Sorry, it just irritates me aswell...)

EDIT: Have it running, wait until like 11 or something, then teleport to another map, and you'll see what I mean (Hopefully)!
Libelnon
Hei - Shantanu - I wrote a tutorial on a event based time system, so have a look at it, the link is in my sig. It may allow you to do things you didn't know you could on time events, and compress that script for you. It's a good concept tho, If I can get it working it may appear in my present 'secret' project, not the one I talk about in my sig. tongue.gif

Edit
Ok, one very big problem here. If this event ran as a paralell process it would slow the game considerably as wait command practically freezes the game. You should instead put in a 'seconds' variable, and that adds 1 every frame (wait then doesn't freeze game as it is only one frame) and then when it gets to 25 (or 60) you add on another minite, also, your screen colour tone is a bit dark, try not to reduce blue much as 'night' black isn't pure - it's more like an incredibly dark purple colour.
Nuque
Libelnon, thank you, I think I will add that in to make the sytem less laggy. Ill add it now!


Night_Runner, you are not right.
I checked it seconds after your first post on this thread just to make sure. Now I am positive of one thing, and that is that it works
I think maybe you copied something wrong?
Night_Runner
Here's a link
Project2.zip

Sorry I'm so much trouble, hopefully someone will be able to resolve this for me sad.gif
Libelnon
Heh, just a note - When you use time scripts, I used one that it waits 2 frames then adds 1 seconds, and the game ran at half frame rate - that is the effect of wait commands on the game. Also, you should include a vairiable to decide if it is AM or PM in a 12 hour clock, as then you can take out the need for a long wait in the day script. Then you can say 'If variable AM/PM = 2 (PM) and variable Hours = 6 (nighttime) then activate switch 'night' and change screen colour tone to -20,-20,0,10.'
Nuque
Night_Runner, I checked that out, and there doesnt appear to be anything wrong with your common events. Perhaps the problem is something hard to notice. Try redoing the Day/Night system and trying again. It works perfectly fine in my project, and mine looks exactly like yours...

Libelnon, thanks for that! That even makes the system more customizable. I tested it and works pretty well. I think Ill put it in very
soon! You are turning out to be a real help.
hackje
ho do i add the script i've never used scripts before
Libelnon
do us a favour - PM me when you've fully updated it - I want to put it into my RPG, including the script. Does the script use windowskins? or has it got no background?
Oh, and another thing... You can do Lycanthropy with a script like this. If you set a switch for 'night', you can then remove the bitten player from the party and replace him/her with a werewolf character (Initialize, so that you don't get a lvl 1 lycan every night) and then when it's day again you can remove him from the party and replace him with (an initalized) player character. As for the bite, set up a skill that uses no MP, and call it 'Lycan Bite', and assign it a common event, in that event, you want to activate a switch called 'lycan ON'. You can cure yourself by turning that off, and the common event for day/night should check if that is on - I'll get u a full command list, just don't merge this with the night/day script, plz!
Nuque
Im pmed you, libelnon. I modified the events and now it is fully customizable! I also added a Night switch that is turned on when the screen gets dark.
Night_Runner
Where did you get that HUD from?
I get the overwhelming feeling that you didn't actually make it, but you didn't credit anyone else for it.....

@ hackje: It's easer to just tell you than to try and find it, lol
1. Highlight everything in that 'And lastly, a HUD' codebox, starting from class Window_...... down to that last end
2. Open the rpg maker xp project you want to put the script into, and that 3rd last icon along the top is the Script Editor (shortcut key F11), open it
3. On the left hand side it says Script >> Game_Temp, etc, scroll that side down to the bottom, and the last item there should be Main
4. Right click Main, and select insert
5. You can name your new new script whatever you like, and just paste the script you coppied into that massive blank section on the right hand side.
If you aren't too confident, download that Project 2 posted above, it has the script, and you can just check off that

EDIT: Actually, here's a more updated version, I edited the script a bit so it works with my sleeping system, that's all
Project1.zip
Achilles
Putting anything besides the time in the HUD was a little unnecessary since most people have their own HUDs they like to use for their character status, so having to go in and delete the hp/sp is a hassle. Good idea about the time though.
Omegas7
Nice, but you should move this to the tutorials section laugh.gif.
Libelnon
well, maybe when we have perfected this, we should make a tutorial, hmm?

also, shantantu, have a look at my tutorial - it could give you ideas to include in your tutorial.

EDIT:
Spotted a problem: if say... you rested, and it added on 80 seconds, 20 seconds would be shaved off - the conditional branches must be GREATER THAN or equal to, and the time should be minused rather than set.
Also, a 24 hour clock would be easier to understand.
Nuque
Bed System is now available!!!
And also...
After a long time I have released my very own Day/Night Demo. Go ahead and check it out!
Rukiri
Not bad at all, but you should go by a 24hr clock"not real time... that'd be forever"

Example.

Seconds =
CODE
var[001] Seconds + 1

wait 2 frames
condition brach
if var[001] Seconds >=60
var[001] Seconds = 0
var[002] Minutes = [001] + 1
ende case
wait 2 frames
if var[002] Munutes >=60
var[002] Minutes = 0
var[003] Hours = [003] + 1
end case
wait 2 frames


Just a clock timer, works great, but if you're going by real time, you need to have a wait 60; at the end of the event because 60/60=1 second;
Nuque
I updated it, and now it is a lot less clogged up.

Achilles had said that lots of people have their own huds, so I created a Window_PlayTime edit that shows my time variables.
Now you dont need a hud anymore!

Also Mystic, I dont completely understand everything you said. Do you mean that you want times like 17:00 or 23:20? I had that before, and now I have AM/PM. It doesnt show AM/PM, but there is a variable for it, so that there is a difference between 3:00 in the morning or night. Like this:

At 3:00 in the morning, var Hours is 3 and var AM/PM is 1

At 3:00 at night, var Hours is 3 and var AM/PM is 2

EDIT: Also is 'Mystic' a DBZ reference? Meaning Gohan's form in the end of the Buu Saga? I like DBZ too, bro
Rukiri
Yea, it's a reference.
IchigekiHissatsuShinigami
QUOTE (-Mystic- @ Nov 21 2008, 04:05 PM) *
Not bad at all, but you should go by a 24hr clock"not real time... that'd be forever"

Example.

Seconds =
CODE
var[001] Seconds + 1

wait 2 frames
condition brach
if var[001] Seconds >=60
var[001] Seconds = 0
var[002] Minutes = [001] + 1
ende case
wait 2 frames
if var[002] Munutes >=60
var[002] Minutes = 0
var[003] Hours = [003] + 1
end case
wait 2 frames


Just a clock timer, works great, but if you're going by real time, you need to have a wait 60; at the end of the event because 60/60=1 second;


Um i know that im not that great at this but i wana take a shot at it, lets see if i understand what this script does, every 60 seconds it turns into 1 min, but also restarts the seconds clock, right???? and the same with minutes and hours??? that way after 12 hrs itll be nite and then day again???
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2013 Invision Power Services, Inc.