Scripts:Time of Day

From OHRRPGCE-Wiki
Jump to navigationJump to search

This is an example script that will allow you to change the palette to make it appear as if it is a certain time of day. The script will not automatically cycle through the different times of day; it is up to you to decide how you want to do this.

Script[edit]

# TIME OF DAY
# Original author: Moogle1

global variable(1, last r)
global variable(2, last g)
global variable(3, last b)
global variable(4, time of day)


plotscript, startup, begin 
 # we'll make it 5:00am so you can see the script's effect
 # you'll probably want to change that, though
 fade to time of day(5)
end


plotscript, load game script, begin 
 ratio r := 0  # Force the script to re-run
 fade to time of day(time of day)
end

plotscript, fade to time of day, time=12, begin
 variable(ratio r)
 variable(ratio g)
 variable(ratio b)
 if (time >> 12) then (time := 24 -- time)
 if (time >> 8) then
 (
   ratio r := 100
   ratio g := 100
   ratio b := 100
 )
 if (time << 4) then
 (
   ratio r := 25
   ratio g := 30
   ratio b := 35
 )
 if (time == 4) then
 (
   ratio r := 45
   ratio g := 35
   ratio b := 40
 )
 if (time == 5) then
 (
   ratio r := 60
   ratio g := 50
   ratio b := 45
 )
 if (time == 6) then
 (
   ratio r := 70
   ratio g := 60
   ratio b := 55
 )
 if (time == 7) then
 (
   ratio r := 90
   ratio g := 80
   ratio b := 70
 )
 if (time == 8) then
 (
   ratio r := 100
   ratio g := 100
   ratio b := 90
 )
 
 # check to see if fading is necessary
 if (last r <> ratio r, or, last g <> ratio g, or, last b <> ratio b) then
 (
   reset palette
   variable(ctr)
   for (ctr, 0, 255) do
   (
     variable(col, r, g, b)
     col := getcolor(ctr)
     r := extractcolor(col, color:red) * ratio r / 100
     g := extractcolor(col, color:green) * ratio g / 100
     b := extractcolor(col, color:blue) * ratio b / 100
     setcolor(ctr, rgb(r, g, b))
   )
   # "update palette" can be used instead of a fade, and doesn't cause a pause
   fade screen in
 )
 last r := ratio r
 last g := ratio g
 last b := ratio b
 
 time of day := time
end

Usage[edit]

Set startup as the new game script and load game script as the load game script. You can call fade to time of day, either from a text box or another script, to change the time of day. If you do, the resulting palette will be used when loading the game.

If you're familiar with palettes, you might consider changing around the RGB ratios in do fade. The settings provided will give you an orange-ish tint at sunset/sunrise and a bluish tint at night.

Finally, the script will start your game with the 5:00am palette. Change the line that says fade to time of day(5) to whatever time you want.