• Do not use Discord to host any images you post, these links expire quickly! You can learn how to add images to your posts here.
[v13+] Unreal Time System

Resource [v13+] Unreal Time System 1.1.1

ChampChar110

Trainer
Member
Joined
Oct 2, 2022
Posts
85
Hello, can you add an option in the option menu to be able to deactivate this system if the player wish to? When trun off, the game should use the player's pc time instead.
You can do it.

Paste it at the bottom of the script:
Expand Collapse Copy
class PokemonSystem
  attr_accessor :unreal_time_usage

  alias org_init initialize
  def initialize
    org_init
    @unreal_time_usage = 0
  end
end

MenuHandlers.add(:options_menu, :unreal_time_usage, {
  "name" => _INTL("Use Unreal Time"),
  "order" => 85,
  "type" => EnumOption,
  "parameters" => [_INTL("In-Game Time"), _INTL("Real Time")],
  "description" => _INTL("Choose which aspect is sped up."),
  "get_proc" => proc { next $PokemonSystem.unreal_time_usage },
  "set_proc" => proc { |value, scene| $PokemonSystem.unreal_time_usage = value }
})

On pbGetTimeNow, on the first line that should look like that:
return Time.now if !$PokemonGlobal || !UnrealTime::ENABLED
Replace !UnrealTime::ENABLED with $PokemonSystem.unreal_time_usage == 1

Now it keeps counting the in-game (unreal) time, so you can switch back without losing time.
If you want it to stop counting, replace if UnrealTime::ENABLED with $PokemonSystem.unreal_time_usage == 0
 

CelestialFearow

Venipede User
Member
Joined
Jul 24, 2020
Posts
200
You can do it.

Paste it at the bottom of the script:
Expand Collapse Copy
class PokemonSystem
  attr_accessor :unreal_time_usage

  alias org_init initialize
  def initialize
    org_init
    @unreal_time_usage = 0
  end
end

MenuHandlers.add(:options_menu, :unreal_time_usage, {
  "name" => _INTL("Use Unreal Time"),
  "order" => 85,
  "type" => EnumOption,
  "parameters" => [_INTL("In-Game Time"), _INTL("Real Time")],
  "description" => _INTL("Choose which aspect is sped up."),
  "get_proc" => proc { next $PokemonSystem.unreal_time_usage },
  "set_proc" => proc { |value, scene| $PokemonSystem.unreal_time_usage = value }
})

On pbGetTimeNow, on the first line that should look like that:
return Time.now if !$PokemonGlobal || !UnrealTime::ENABLED
Replace !UnrealTime::ENABLED with $PokemonSystem.unreal_time_usage == 1

Now it keeps counting the in-game (unreal) time, so you can switch back without losing time.
If you want it to stop counting, replace if UnrealTime::ENABLED with $PokemonSystem.unreal_time_usage == 0
Thanks alot! :)
 

TheBUSHMANOG

Rookie
Member
Joined
Feb 25, 2024
Posts
5
Really want to get this awesome script working but I seem to be having some trouble seeing any changes. I've added it into scripts above main, and I've played around with time proportion, however I haven't seen any map change to night. Does anyone have advice on how to make sure I've set this up properly, or to work out what else I need to add or change?
 

-FL-

Pokémon Island Creator
Member
Joined
Aug 28, 2022
Posts
306
Really want to get this awesome script working but I seem to be having some trouble seeing any changes. I've added it into scripts above main, and I've played around with time proportion, however I haven't seen any map change to night. Does anyone have advice on how to make sure I've set this up properly, or to work out what else I need to add or change?
Just putting it above main works. I generally do one of these thing to test, of both:
  • Set PROPORTION as 3600, and wait 15 seconds in a example map (like city). 3600 mean than a second in real time is an hour in game.
  • Put print pbGetTimeNow in a event as a script command. This line will print the time in game.
 

TheBUSHMANOG

Rookie
Member
Joined
Feb 25, 2024
Posts
5
Just putting it above main works. I generally do one of these thing to test, of both:
  • Set PROPORTION as 3600, and wait 15 seconds in a example map (like city). 3600 mean than a second in real time is an hour in game.
  • Put print pbGetTimeNow in a event as a script command. This line will print the time in game.
Hey, thank you for this. I've followed your instructions and got this error:

[Pokémon Essentials version 21.1]
[v21.1 Hotfixes 1.0.7]

Script error in event 11 (coords 14,9), map 32 (Route 1 Test)
Exception: NameError
Message: undefined local variable or method `pbGetTimeNo' for #<Interpreter @event_id: 11>

***Full script:
print pbGetTimeNo

Backtrace:
(eval):1:in `execute_script'
033:Interpreter:138:in `eval'
033:Interpreter:138:in `execute_script'
034:Interpreter_Commands:1177:in `command_355'
034:Interpreter_Commands:116:in `execute_command'
033:Interpreter:130:in `block in update'
033:Interpreter:86:in `loop'
033:Interpreter:86:in `update'
032:Scene_Map:167:in `block in update'
032:Scene_Map:166:in `loop'


Do you know any fixes for this?
 

wrigty12

Tester-Coder Hybrid
Member
Joined
Jul 24, 2022
Posts
547
Hey, thank you for this. I've followed your instructions and got this error:

[Pokémon Essentials version 21.1]
[v21.1 Hotfixes 1.0.7]

Script error in event 11 (coords 14,9), map 32 (Route 1 Test)
Exception: NameError
Message: undefined local variable or method `pbGetTimeNo' for #<Interpreter @event_id: 11>

***Full script:
print pbGetTimeNo

Backtrace:
(eval):1:in `execute_script'
033:Interpreter:138:in `eval'
033:Interpreter:138:in `execute_script'
034:Interpreter_Commands:1177:in `command_355'
034:Interpreter_Commands:116:in `execute_command'
033:Interpreter:130:in `block in update'
033:Interpreter:86:in `loop'
033:Interpreter:86:in `update'
032:Scene_Map:167:in `block in update'
032:Scene_Map:166:in `loop'


Do you know any fixes for this?
You've misspelled the function, missing the w
 

TheBUSHMANOG

Rookie
Member
Joined
Feb 25, 2024
Posts
5
You've misspelled the function, missing the w

Ah yes! Yeah that's working now thank you for spotting that. I'm not seeing any in game visual changes however (no darkening/changing tone of the screen). If I need to make any changes to the script/create something new I can learn to code it, but any advice would be appreciated!
 

-FL-

Pokémon Island Creator
Member
Joined
Aug 28, 2022
Posts
306
Ah yes! Yeah that's working now thank you for spotting that. I'm not seeing any in game visual changes however (no darkening/changing tone of the screen). If I need to make any changes to the script/create something new I can learn to code it, but any advice would be appreciated!
Did you tested in example maps, like Lappet Town? When it is 10:00 PM, this should be dark. If isn't, so there is some issue in Essentials.
 

TheBUSHMANOG

Rookie
Member
Joined
Feb 25, 2024
Posts
5
Did you tested in example maps, like Lappet Town? When it is 10:00 PM, this should be dark. If isn't, so there is some issue in Essentials.
Okay you're totally right. I just tested Lappet and it works fine but on any custom map (using custom tilesets) there doesn't seem to be a change. Do you have any ideas for a fix? Would it be a change with the tiles or something I'd need to program?
 

Jukes

Cooltrainer
Member
Joined
Jul 15, 2023
Posts
102
@-FL- is there a way for me to make it so SetEventTime uses the computer local time instead? or maybe a pbSetEventRealTime?

I'm struggling with making time based events in my game as this makes them move too fast
 

-FL-

Pokémon Island Creator
Member
Joined
Aug 28, 2022
Posts
306
@-FL- is there a way for me to make it so SetEventTime uses the computer local time instead? or maybe a pbSetEventRealTime?

I'm struggling with making time based events in my game as this makes them move too fast
Like I said (in a nutshell) in the description, you should change some 'pbGetTimeNow' to 'Time.now'. Change one in Interpreter script section and two others in Game Event script section. Untested.

I believe that a sngle pbSetEventRealTime? isn't possible, because, even if system "set" using real time, you also need to change the way that the system "get" the value (read).
 

Jukes

Cooltrainer
Member
Joined
Jul 15, 2023
Posts
102
Like I said (in a nutshell) in the description, you should change some 'pbGetTimeNow' to 'Time.now'. Change one in Interpreter script section and two others in Game Event script section. Untested.

I believe that a sngle pbSetEventRealTime? isn't possible, because, even if system "set" using real time, you also need to change the way that the system "get" the value (read).

I was able to accomplish this by doing the following

Change the SetEventTime in Interpreter to
Interpreter:
Expand Collapse Copy
def pbSetEventTime(*arg)
  $PokemonGlobal.eventvars = {} if !$PokemonGlobal.eventvars
  time = Time.now.to_i
  pbSetSelfSwitch(@event_id, "A", true)
  $PokemonGlobal.eventvars[[@map_id, @event_id]] = time
  arg.each do |otherevt|
    pbSetSelfSwitch(otherevt, "A", true)
    $PokemonGlobal.eventvars[[@map_id, otherevt]] = time
  end
end

And then changing the two expired? definitions in Game_Event to this


expired:
Expand Collapse Copy
def expired?(secs = 86_400)
  ontime = self.variable.to_i
  return false if !ontime
  return Time.now > Time.at(ontime + secs)
end

def expiredDays?(days = 1)
  ontime = self.variable.to_i
  return false if !ontime
  now = Time.now
  elapsed = (now.to_i - ontime) / 86_400
  elapsed += 1 if (now.hour * 3600) + (now.min * 60) + now.sec > (ontime % 86_400)
  return elapsed >= days
end



Now regardless of the unreal time it is forced to use the system clock
 

Bowlingsoup

Rookie
Member
Joined
Nov 30, 2022
Posts
4
Is there a way to force the weekday to be the same as the system it's running on? I changed the following script section:

Old Weekday Script:
Expand Collapse Copy
def pbIsWeekday(wdayVariable, *arg)
  timenow = pbGetTimeNow 
  wday = timenow.wday
  ret = false
  arg.each do |wd|
    ret = true if wd == wday
  end
  if wdayVariable > 0
    $game_variables[wdayVariable] = [
      _INTL("Sunday"),
      _INTL("Monday"),
      _INTL("Tuesday"),
      _INTL("Wednesday"),
      _INTL("Thursday"),
      _INTL("Friday"),
      _INTL("Saturday")
    ][wday]
    $game_map.need_refresh = true if $game_map
  end
  return ret
end

To the following:

New Script:
Expand Collapse Copy
def pbIsWeekday(wdayVariable, *arg)
  timenow = time.now
  wday = timenow.wday
  ret = false
  arg.each do |wd|
    ret = true if wd == wday
  end
  if wdayVariable > 0
    $game_variables[wdayVariable] = [
      _INTL("Sunday"),
      _INTL("Monday"),
      _INTL("Tuesday"),
      _INTL("Wednesday"),
      _INTL("Thursday"),
      _INTL("Friday"),
      _INTL("Saturday")
    ][wday]
    $game_map.need_refresh = true if $game_map
  end
  return ret
end

But it keeps showing the following error, whenever you're entering a map that has an event that's using Game Switch 19. (The one that's used for the standard Bug Catching contest).

[2024-06-02 13:28:34 +0200]
[Pokémon Essentials version 21.1]
[v21.1 Hotfixes 1.0.9]

Exception: NameError
Message: undefined local variable or method `time' for #<Game_Event>

Backtrace:
Overworld_Time:130:in `pbIsWeekday'
(eval):1:in `switchIsOn?'
Game_Event:82:in `eval'
Game_Event:82:in `switchIsOn?'
Game_Event:186:in `block in refresh'
Game_Event:184:in `each'
Game_Event:184:in `refresh'
[Overworld Shadows EX] script.rb:218:in `refresh'
Game_Event:28:in `initialize'
Game_Map:65:in `new'

Does anyone know what I'm doing wrong?
 

wrigty12

Tester-Coder Hybrid
Member
Joined
Jul 24, 2022
Posts
547
First, if you are forcing system weekday but otherwise time will pass using the unreal system, that's going to be confusing to the player. If I'm playing for 3 in-game days, but it's still Wednesday the entire time, that would feel broken.

Second, it's "Time.now", capital T
 
Last edited:

Bowlingsoup

Rookie
Member
Joined
Nov 30, 2022
Posts
4
First, if you are forcing system weekday but otherwise time will pass using the unreal system, that's going to be confusing to the player. If I'm playing for 3 in-game days, but it's still Wednesday the entire time, that would feel broken.

Second, it's "Time.now", capital T
Thank you for the quick reply and help!

I'm still fiddling with this Plugin to see if it makes sense/is balanced in my game. So I might just change the Bug Catching contest to a regular daily activity as a whole. But thank you for the heads-up!
 

Fil

Novice
Member
Joined
Jul 11, 2024
Posts
12
This script is amazing, but I am having hard time to make it works with Arcky's Pokémarts plugin (amazing too),
i suppose i have to change something here

Ruby:
Expand Collapse Copy
date = pbGetTimeNow.strftime("%Y-%m-%d")
  if stockWithLimit.any? {|item| item.is_a?(Array) }
    $ArckyGlobal.pokeMartTracker ||= {}
    $ArckyGlobal.pokeMartTracker[@map_id] ||= {}
    $ArckyGlobal.pokeMartTracker[@map_id][@event_id] ||= {}
    # get the days between the day that one item was out of stock and the day of checking again
    daysDiff = getPreviousRefreshDate(date)
    timeInDays = convertDays(refreshRate, daysDiff)
    if timeInDays.nil? && refreshRate != "never"
      $ArckyGlobal.pokeMartTracker[@map_id][@event_id] = {}
      daysDiff = getPreviousRefreshDate(date)
      timeInDays = convertDays(refreshRate, daysDiff)
    end
    # canRefresh is true if the daysDiff is equal to the refreshRate day requirement.
    pokeMartTracker = $ArckyGlobal.pokeMartTracker[@map_id][@event_id]
    pokeMartTracker = { :date => date, :refresh => timeInDays, :items => getItemList(stockWithLimit.drop(1)) } if pokeMartTracker.empty?
    pokeMartTracker[:refresh] = timeInDays if !pokeMartTracker.empty?
  else
    pokeMartTracker = nil
  end

I try to do a 2 day restock of the item, if i don't change anything the first day seems to work: the market guy tell me to came back tomorrow. The next day, however, there is no restock and he tells to came back "never."
Maybe the problem is down here?

Ruby:
Expand Collapse Copy
def convertDays(refreshRate, daysDiff)
  case refreshRate.downcase
  when "daily"
    days = 1
  when "2daily"
    days = 2
  when "weekly"
    days = 7
  when "random"
    unless $ArckyGlobal.pokeMartTracker[@map_id][@event_id].empty?
      refresh = $ArckyGlobal.pokeMartTracker[@map_id][@event_id][:refresh]
      case refresh
      when "in a week"
        days = 7
      when /in (\d+) days/
        days = refresh[/\d+/].to_i
      when "tomorrow"
        days = 1
      end
    else
      days = rand(1..7)
    end
  else
    days = -1
  end
  time = days - daysDiff
  case time
  when 1
    return "tomorrow"
  when 2..6
    return "in #{time.to_i} days"
  when 7
    return "in a week"
  else
    return "never"
  end
end

Sorry, i am very new to all of this.
 
Last edited:

-FL-

Pokémon Island Creator
Member
Joined
Aug 28, 2022
Posts
306
This script is amazing, but I am having hard time to make it works with Arcky's Pokémarts plugin (amazing too),
i suppose i have to change something here

I try to do a 2 day restock of the item, if i don't change anything the first day seems to work: the market guy tell me to came back tomorrow. The next day, however, there is no restock and he tells to came back "never."
Maybe the problem is down here?

Sorry, i am very new to all of this.
I don't know. Probably you need to change some Time.now to pbGetTimeNow. The script source can be easily accessed by browser?
 
Last edited:
  • Like
Reactions: Fil

Fil

Novice
Member
Joined
Jul 11, 2024
Posts
12
Hi, thanks for your reply 🍩
There is this:

Ruby:
Expand Collapse Copy
def getPreviousRefreshDate(date)
  pokeMartTracker = $ArckyGlobal.pokeMartTracker[@map_id][@event_id]
  return 0 if pokeMartTracker.empty?
  return (getDateFromString(date) - getDateFromString(pokeMartTracker[:date].to_s)) / (24 * 60 * 60)
end

def getDateFromString(date)
  dateArray = date.split('-')
  return Time.local(dateArray[0], dateArray[1], dateArray[2])
end

with one "return Time.local", could be it?
The script is here on this community, Arcky made a complete guide (a cool one), but the only way to see the entire script is download it.
 
Back
Top