Notices
For all updates, view the main page.

Scripts & Tutorials This forum is for scripts and code, as well as all kinds of tutorials, software, tools and so forth. Remember to give credit!
The thread revival limit does not apply here.

Reply
 
Thread Tools
  #1    
Old August 3rd, 2012 (4:30 AM). Edited June 10th, 2014 by FL.
FL's Avatar
FL FL is offline
Pokémon Island Creator
 
Join Date: Sep 2010
Gender: Male
Posts: 1,630
Code:
#===============================================================================
# * Unreal time system - by FL (Credits will be apreciated)
#===============================================================================
#
# This script is for Pokémon Essentials. It makes the time in game have its
# own clock that only pass when you are in game instead of using real time
# (like Harvest Moon and Zelda: Ocarina of Time).
#
#===============================================================================
#
# To this script works, put it above main. If you wish to some parts still use
# real time like the Trainer Card start time and Pokémon Trainer Memo, 
# just change 'pbGetTimeNow' to 'Time.now' in their scripts (in this example, 
# PokemonMap and PokeBattle_Pokemon scripts sections).
#
# This script use the Ruby Time class that can only hold years around 
# 1970-2038 range. If you wish to have other years values, sum/subtract when
# displaying the year. Examples: 
# If you wants year 1000, start in 1970 and, when displaying year name use 
# 'pbGetTimeNow.year-970'. 
# If you wants year 5000, start in 1970 and, when displaying year name use 
# 'pbGetTimeNow.year+3030'.
# 
# Some time methods:
# 'pbGetTimeNow.year', 'pbGetTimeNow.mon' (the numbers from 1-12), 
# 'pbGetTimeNow.day','pbGetTimeNow.hour', 'pbGetTimeNow.min', 
# 'pbGetTimeNow.sec', 'pbGetAbbrevMonthName(pbGetTimeNow.mon)',
# 'pbGetTimeNow.strftime("%A")' (displays weekday name),
# 'pbGetTimeNow.strftime("%I:%M %p")' (displays Hours:Minutes pm/am)
# 
#===============================================================================

# Set false to disable this system (returns Time.now)
NTN_ENABLED=true 

# Make this true to time only pass at field (Scene_Map) 
# A note to scripters: To make time pass on other scenes, put line
# '$PokemonGlobal.addNewFrameCount' near to line 'Graphics.update'
NTN_TIMESTOPS=true 

# Make this true to time pass in battle, during turns and command selection.
# This won't affect the Pokémon and Bag submenus.
# Only works if NTN_TIMESTOPS=true.
NTN_BATTLEPASS=true

# Make this true to time pass when the Dialog box or the main menu are open.
# This won't affect the submenus like Pokémon and Bag.
# Only works if NTN_TIMESTOPS=true.
NTN_TALKPASS=true

# Time proportion here. 
# So if it is 100, one second in real time will be 100 seconds in game.
# If it is 60, one second in real time will be one minute in game.
NTS_TIMEPROPORTION=60

# Choose switch number that when true the time won't pass (or -1 to cancel). 
# Only works if NTN_TIMESTOPS=true.
NTN_SWITCHSTOPS=-1

# Choose variable(s) number(s) that can hold time passage (or -1 to cancel).
# The time in this variable isn't affected by NTS_TIMEPROPORTION.
# Example: When the player sleeps you wish to the time in game advance
# 8 hours, so put in NTN_EXTRASECONDS a game variable number and sum 
# 28800 (60*60*8) in this variable every time that the players sleeps.
NTN_EXTRASECONDS=-1
NTN_EXTRADAYS=-1

# Initial values
NTN_INITIALYEAR=2000 # Can ONLY holds around range 1970-2038
NTN_INITIALMONTH=1
NTN_INITIALDAY=1
NTN_INITIALHOUR=12
NTN_INITIALMINUTE=0

def pbGetTimeNow
  return Time.now if !NTN_ENABLED
  
  if(NTN_TIMESTOPS)
    # Sum the extra values to newFrameCount
    if(NTN_EXTRASECONDS>0)
      $PokemonGlobal.newFrameCount+=(
        pbGet(NTN_EXTRASECONDS)*Graphics.frame_rate)/NTS_TIMEPROPORTION
      $game_variables[NTN_EXTRASECONDS]=0
    end  
    if(NTN_EXTRADAYS>0)
      $PokemonGlobal.newFrameCount+=((60*60*24)*
        pbGet(NTN_EXTRADAYS)*Graphics.frame_rate)/NTS_TIMEPROPORTION
      $game_variables[NTN_EXTRADAYS]=0
    end
  elsif(NTN_EXTRASECONDS>0 && NTN_EXTRADAYS>0)
    # Checks to regulate the max/min values at NTN_EXTRASECONDS
    while (pbGet(NTN_EXTRASECONDS)>=(60*60*24))
      $game_variables[NTN_EXTRASECONDS]-=(60*60*24)
      $game_variables[NTN_EXTRADAYS]+=1
    end
    while (pbGet(NTN_EXTRASECONDS)<=-(60*60*24))
      $game_variables[NTN_EXTRASECONDS]+=(60*60*24)
      $game_variables[NTN_EXTRADAYS]-=1
    end  
  end  
  start_time=Time.utc(NTN_INITIALYEAR,NTN_INITIALMONTH,NTN_INITIALDAY,
    NTN_INITIALHOUR,NTN_INITIALMINUTE)
  time_played=(NTN_TIMESTOPS && $PokemonGlobal) ? 
    $PokemonGlobal.newFrameCount : Graphics.frame_count
  time_played=(time_played*NTS_TIMEPROPORTION)/Graphics.frame_rate
  time_jumped=0
  time_jumped+=pbGet(NTN_EXTRASECONDS) if NTN_EXTRASECONDS>-1 
  time_jumped+=pbGet(NTN_EXTRADAYS)*(60*60*24) if NTN_EXTRADAYS>-1 
  time_ret = nil
  # To prevent crashes due to year limit, every time that you reach in year 
  # 2036 the system will subtract 6 years (to works with leap year) from
  # your date and sum in $PokemonGlobal.extraYears. You can sum your actual
  # year with this extraYears when displaying years.
  loop do
    extraYears=($PokemonGlobal) ? $PokemonGlobal.extraYears : 0
    time_fix=extraYears*60*60*24*(365*6+1)/6
    time_ret=start_time+(time_played+time_jumped-time_fix)
    break if time_ret.year<2036
    $PokemonGlobal.extraYears+=6
  end
  return time_ret
end

if NTN_ENABLED
  class PokemonGlobalMetadata
    attr_accessor :newFrameCount
    attr_accessor :extraYears 
    
    def addNewFrameCount
      self.newFrameCount+=1 if !(
        NTN_SWITCHSTOPS>0 && $game_switches[NTN_SWITCHSTOPS])
    end
    
    def newFrameCount
      @newFrameCount=0 if [email protected]
      return @newFrameCount
    end
    
    def extraYears
      @extraYears=0 if [email protected]
      return @extraYears
    end
  end  

  if NTN_TIMESTOPS  
    class Scene_Map
      alias :updateold :update
    
      def update
        $PokemonGlobal.addNewFrameCount
        updateold
      end
    
      if NTN_TALKPASS  
        alias :miniupdateold :miniupdate
        
        def miniupdate
          $PokemonGlobal.addNewFrameCount 
          miniupdateold
        end
      end
    end  
  
    if NTN_BATTLEPASS
      class PokeBattle_Scene
        alias :pbGraphicsUpdateold :pbGraphicsUpdate
        
        def pbGraphicsUpdate
          $PokemonGlobal.addNewFrameCount 
          pbGraphicsUpdateold
        end
      end
    end
  end
end
__________________
Reply With Quote

Relevant Advertising!

  #2    
Old December 22nd, 2014 (9:28 AM).
Qwertyis666's Avatar
Qwertyis666 Qwertyis666 is offline
Dragon Trainer Since 1996
 
Join Date: Feb 2014
Location: Quebec, Canada
Gender: Male
Posts: 60
Hi, I just found this awesome script and he work fine but I have a little question:
how exaclty can you pass time with a event? I want the time to pass went you go to bed(the player will choose between morning or night) and when you heal your pokemon in a Pokecenter(pass 6h).

Thanks in advance and sorry for my bad english.
__________________
Pokemon Korano (First demo playable now )
The first demo have 3 gym and full of new cool features

I need a new tileset and OW sprite so if you are a Spriter, PM me
Reply With Quote
  #3    
Old December 23rd, 2014 (5:18 AM).
FL's Avatar
FL FL is offline
Pokémon Island Creator
 
Join Date: Sep 2010
Gender: Male
Posts: 1,630
Quote:
Originally Posted by Qwertyis666 View Post
Hi, I just found this awesome script and he work fine but I have a little question:
how exaclty can you pass time with a event? I want the time to pass went you go to bed(the player will choose between morning or night) and when you heal your pokemon in a Pokecenter(pass 6h).

Thanks in advance and sorry for my bad english.
Quote:
Originally Posted by FL View Post
When the player sleeps you wish to the time in game advance
# 8 hours, so put in NTN_EXTRASECONDS a game variable number and sum
# 28800 (60*60*8) in this variable every time that the players sleeps.
NTN_EXTRASECONDS=-1
NTN_EXTRADAYS=-1
So, if you make NTN_EXTRASECONDS=87 and sum 21600 into variable 87, the time will pass six hours.
__________________
Reply With Quote
  #4    
Old December 23rd, 2014 (10:01 AM).
Qwertyis666's Avatar
Qwertyis666 Qwertyis666 is offline
Dragon Trainer Since 1996
 
Join Date: Feb 2014
Location: Quebec, Canada
Gender: Male
Posts: 60
Quote:
Originally Posted by FL View Post
So, if you make NTN_EXTRASECONDS=87 and sum 21600 into variable 87, the time will pass six hours.

Ok, thanks (I guess I did not notice that comment part).
I just don't understand what is ''sum''? example in 28800, 60*60*8 is the sum?

And what if I want the player to choose to skip to the morning or the night?
Do the script will be difficult to call?

Thanks in advance and sorry for my bad english.
__________________
Pokemon Korano (First demo playable now )
The first demo have 3 gym and full of new cool features

I need a new tileset and OW sprite so if you are a Spriter, PM me
Reply With Quote
  #5    
Old December 26th, 2014 (4:01 AM).
FL's Avatar
FL FL is offline
Pokémon Island Creator
 
Join Date: Sep 2010
Gender: Male
Posts: 1,630
Just add 21600 (6 hours in seconds) to variable 87, you can even use event scripts.

For forcing to the player pass the time until it reach into a certain time, there serveral ways, three examples (the first is the worst) that make the player going into 6:00:00 PM (both are doable with events, but I use scripts for better performance).

Code:
hour = 18 # 0..23
min = 0
sec = 0 
timeNow = pbGetTimeNow
while (timeNow.hour != hour &&
    timeNow.min != min && 
    timeNow.sec != sec)
  $game_variables[87]+=1
  timeNow = pbGetTimeNow
end
Code:
hour = 18 # 0..23
min = 0
sec = 0
timeNow = pbGetTimeNow
secInDay = 60*60*24
timeDifference = Time.new(
  timeNow.year, timeNow.mon, timeNow.day,
  hour, min, sec)
timeDifference += secInDay # Add a day
secondsAdded = (timeDifference-timeNow)%secInDay
$game_variables[87]+=secondsAdded
Code:
hour = 18 # 0..23
min = 0
sec = 0
timeNow = pbGetTimeNow
secInDay = 60*60*24
secNow = pbGetTimeNow.hour*60*60+pbGetTimeNow.min*60+pbGetTimeNow.sec
secWished = hour*60*60+min*60+sec
timeDifference += secInDay # Add a day
secondsAdded = secWished-secNow
secondsAdded +=secInDay if secondsAdded<0
$game_variables[87]+=secondsAdded
All untested.
__________________
Reply With Quote
  #6    
Old December 26th, 2014 (9:18 AM).
Qwertyis666's Avatar
Qwertyis666 Qwertyis666 is offline
Dragon Trainer Since 1996
 
Join Date: Feb 2014
Location: Quebec, Canada
Gender: Male
Posts: 60
Quote:
Originally Posted by FL View Post
Just add 21600 (6 hours in seconds) to variable 87, you can even use event scripts.

For forcing to the player pass the time until it reach into a certain time, there serveral ways, three examples (the first is the worst) that make the player going into 6:00:00 PM (both are doable with events, but I use scripts for better performance).

Code:
hour = 18 # 0..23
min = 0
sec = 0 
timeNow = pbGetTimeNow
while (timeNow.hour != hour &&
    timeNow.min != min && 
    timeNow.sec != sec)
  $game_variables[87]+=1
  timeNow = pbGetTimeNow
end
Code:
hour = 18 # 0..23
min = 0
sec = 0
timeNow = pbGetTimeNow
secInDay = 60*60*24
timeDifference = Time.new(
  timeNow.year, timeNow.mon, timeNow.day,
  hour, min, sec)
timeDifference += secInDay # Add a day
secondsAdded = (timeDifference-timeNow)%secInDay
$game_variables[87]+=secondsAdded
Code:
hour = 18 # 0..23
min = 0
sec = 0
timeNow = pbGetTimeNow
secInDay = 60*60*24
secNow = pbGetTimeNow.hour*60*60+pbGetTimeNow.min*60+pbGetTimeNow.sec
secWished = hour*60*60+min*60+sec
timeDifference += secInDay # Add a day
secondsAdded = secWished-secNow
secondsAdded +=secInDay if secondsAdded<0
$game_variables[87]+=secondsAdded
All untested.

Thanks! I used to make work the time pass in a Pokecenter meanwhile, basicly when you heal your Pokemon in a Pokecenter, one hour pass per Pokemon in your team (If you have 2 poke, 2 hours pass, etc) Anyways these script will help me alot since I try so many things to skip to a specific time and none of them work.

Thanks again FL and sorry for my bad english
Reply With Quote
  #7    
Old June 17th, 2015 (10:44 AM).
mcscottyg mcscottyg is offline
 
Join Date: Jun 2015
Gender: Male
Posts: 3
When you say paste this script above main, do you mean make a new script above main, or paste this within the main script?
Reply With Quote
  #8    
Old June 17th, 2015 (11:30 AM).
---- ---- is offline
 
Join Date: Jan 2013
Posts: 66
Quote:
Originally Posted by mcscottyg View Post
When you say paste this script above main, do you mean make a new script above main, or paste this within the main script?
Above. Never ever ever ever paste anything in to Main.
Reply With Quote
  #9    
Old June 17th, 2015 (12:45 PM).
mcscottyg mcscottyg is offline
 
Join Date: Jun 2015
Gender: Male
Posts: 3
Thanks got it working well now
Reply With Quote
  #10    
Old June 24th, 2015 (2:19 PM).
FL's Avatar
FL FL is offline
Pokémon Island Creator
 
Join Date: Sep 2010
Gender: Male
Posts: 1,630
Quote:
Originally Posted by mcscottyg View Post
When you say paste this script above main, do you mean make a new script above main, or paste this within the main script?
Make a new script above main, but both actually work.
__________________
Reply With Quote
  #11    
Old November 9th, 2015 (9:24 AM).
AndromedaKerova AndromedaKerova is offline
 
Join Date: Aug 2015
Gender: Female
Posts: 25
I went into the printable version, copied the code and added it to my game as instructed but for some reason it seems to DISABLE the day/night system instead of speeding it up. The tones of the game no longer change no matter how long I leave it running for.
Reply With Quote
  #12    
Old November 14th, 2015 (3:05 PM).
FL's Avatar
FL FL is offline
Pokémon Island Creator
 
Join Date: Sep 2010
Gender: Male
Posts: 1,630
Quote:
Originally Posted by AndromedaKerova View Post
I went into the printable version, copied the code and added it to my game as instructed but for some reason it seems to DISABLE the day/night system instead of speeding it up. The tones of the game no longer change no matter how long I leave it running for.
In NTS_TIMEPROPORTION put 2000 and waits a minute.
__________________
Reply With Quote
  #13    
Old December 12th, 2015 (12:25 AM).
TamerX34 TamerX34 is offline
 
Join Date: Nov 2008
Gender:
Posts: 3
Is it possible to create a Persona 3/4 time system from this script?
Reply With Quote
  #14    
Old December 12th, 2015 (1:05 AM).
Telemetius's Avatar
Telemetius Telemetius is offline
Tele*
 
Join Date: Nov 2014
Location: Italy
Gender: Male
Nature: Relaxed
Posts: 182
Quote:
Originally Posted by TamerX34 View Post
Is it possible to create a Persona 3/4 time system from this script?
Not the original poster but the persona 3/4 time system is pretty much not related to actual time (as in hours, minutes and seconds) but rather to a calendar that splits each day into Morning, Evening and Night (also Dark Hour if you consider it). Point is, every "piece" of the day has virtually unlimited actual time until the protagonist does something.
__________________

That way!
I thought..uhm, ok.
-----------------------------------------------------------------------------------------------
Beta 50%
Reply With Quote
  #15    
Old December 12th, 2015 (7:32 AM).
TamerX34 TamerX34 is offline
 
Join Date: Nov 2008
Gender:
Posts: 3
Quote:
Originally Posted by Telemetius View Post
Not the original poster but the persona 3/4 time system is pretty much not related to actual time (as in hours, minutes and seconds) but rather to a calendar that splits each day into Morning, Evening and Night (also Dark Hour if you consider it). Point is, every "piece" of the day has virtually unlimited actual time until the protagonist does something.
Would you know of a script that does this?
Reply With Quote
  #16    
Old December 12th, 2015 (8:29 AM).
Telemetius's Avatar
Telemetius Telemetius is offline
Tele*
 
Join Date: Nov 2014
Location: Italy
Gender: Male
Nature: Relaxed
Posts: 182
Quote:
Originally Posted by TamerX34 View Post
Would you know of a script that does this?
There's this project going on but the author is using VX ace.
__________________

That way!
I thought..uhm, ok.
-----------------------------------------------------------------------------------------------
Beta 50%
Reply With Quote
  #17    
Old December 14th, 2015 (12:03 AM).
Cilerba Cilerba is offline
the hearts of lonely people
Silver Tier
 
Join Date: Feb 2010
Location: Massachusetts
Age: 19
Gender: Male
Nature: Quiet
Posts: 1,172
Would I be able to get an example on how pbGetTimeNow.strftime("%I:%M %p") would be used?
__________________
Reply With Quote
  #18    
Old December 19th, 2015 (9:33 AM).
FL's Avatar
FL FL is offline
Pokémon Island Creator
 
Join Date: Sep 2010
Gender: Male
Posts: 1,630
Quote:
Originally Posted by Cilerba View Post
Would I be able to get an example on how pbGetTimeNow.strftime("%I:%M %p") would be used?
Call script:

Code:
t=pbGetTimeNow.strftime("%I:%M %p")
Kernel.pbMessage(_INTL("{1} is the time.",t))
OR, you can store in a variable, like 87 and call using '\v[87]' (without quotes) at message system after the script call:

Code:
t=pbGetTimeNow.strftime("%I:%M %p")
$game_variables[87]=t
__________________
Reply With Quote
  #19    
Old February 6th, 2016 (8:26 AM).
Phigo's Avatar
Phigo Phigo is offline
 
Join Date: Oct 2015
Location: Austria
Gender: Male
Nature: Calm
Posts: 47
Is it possible to show the time on the loading screen?
I tried it with "pbGetTimeNow.strftime" but got an error in line 81 in the "Unreal Time Script". I guess this only works in-game, since the same line is used in the Pokégearscript to show the time on the Pokégear.
Is there another way to show the time on the loading screen?
__________________
Hyrule Total War
Reply With Quote
  #20    
Old February 6th, 2016 (2:52 PM).
FL's Avatar
FL FL is offline
Pokémon Island Creator
 
Join Date: Sep 2010
Gender: Male
Posts: 1,630
Quote:
Originally Posted by Phigo View Post
Is it possible to show the time on the loading screen?
I tried it with "pbGetTimeNow.strftime" but got an error in line 81 in the "Unreal Time Script". I guess this only works in-game, since the same line is used in the Pokégearscript to show the time on the Pokégear.
Is there another way to show the time on the loading screen?
pbGetTimeNow uses both $PokemonGlobal and $game_variables that aren't loaded yet. You need to change the 'def pbGetTimeNow' into

Code:
def pbGetTimeNow(pokemonGlobal=nil,game_variables=nil)
  pokemonGlobal||=$PokemonGlobal
  game_variables||=$game_variables
And change every other $PokemonGlobal on this method to pokemonGlobal and game_variables to $game_variables.

After that, you need to call, in the title screen (or PokemonLoadPanel) call this method with the two previous loaded arguments. For this, in 'def pbTryLoadFile' load these two variables (keep note on Marshal data order that can be seen in def pbStartLoadScreen) and by two more methods, PokemonLoadScene.pbStartScene and PokemonLoadPanel constructor. Assign into a global variable in this last one and call it into the draw method.
__________________
Reply With Quote
  #21    
Old April 21st, 2016 (11:17 AM).
Lucidious89 Lucidious89 is offline
 
Join Date: Apr 2014
Gender: Male
Posts: 127
Is there way to utilize this script to jump ahead by entire months at a time? I'm thinking about utilizing this for my birthsigns script. I tried a few things working off what you've already posted, but I kept on getting errors.
Reply With Quote
  #22    
Old April 23rd, 2016 (7:08 AM).
FL's Avatar
FL FL is offline
Pokémon Island Creator
 
Join Date: Sep 2010
Gender: Male
Posts: 1,630
Quote:
Originally Posted by Lucidious89 View Post
Is there way to utilize this script to jump ahead by entire months at a time? I'm thinking about utilizing this for my birthsigns script. I tried a few things working off what you've already posted, but I kept on getting errors.
If you put some variable in NTN_EXTRADAYS, like 97, just sum the day amount into this variable. Example: If you wish more two months, just sum 120 into variable 97.
__________________
Reply With Quote
  #23    
Old April 29th, 2016 (3:35 PM).
Lucidious89 Lucidious89 is offline
 
Join Date: Apr 2014
Gender: Male
Posts: 127
Quote:
Originally Posted by FL View Post
If you put some variable in NTN_EXTRADAYS, like 97, just sum the day amount into this variable. Example: If you wish more two months, just sum 120 into variable 97.
Thanks, ive got it working exactly how I want now. But I was wondering if there was a way to reset the current time through a script. Like lets say I go forward a few months, but then decide I want to change the time again to match the real-world time.
Reply With Quote
  #24    
Old April 30th, 2016 (1:45 AM).
Phigo's Avatar
Phigo Phigo is offline
 
Join Date: Oct 2015
Location: Austria
Gender: Male
Nature: Calm
Posts: 47
You can just set "NTN_ENABLED=true" to false.
__________________
Hyrule Total War
Reply With Quote
  #25    
Old April 30th, 2016 (3:46 AM).
Lucidious89 Lucidious89 is offline
 
Join Date: Apr 2014
Gender: Male
Posts: 127
Quote:
Originally Posted by Phigo View Post
You can just set "NTN_ENABLED=true" to false.
Will that work in a script? Im basically just trying to make a "reset time" button.
Reply With Quote
Reply
Quick Reply

Sponsored Links
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 2:19 AM.