• Hi, Guest!
    Some images might be missing as we move away from using embedded images, sorry for the mess!
    From now on, you'll be required to use a third party to host images. You can learn how to add images here, and if your thread is missing images you can request them here.
    Do not use Discord to host any images you post, these links expire quickly!
[v13+] Unreal Time System

Resource [v13+] Unreal Time System 1.1.1

roei110

Trainer
Member
Joined
Oct 2, 2022
Posts
69
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:
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
196
You can do it.

Paste it at the bottom of the script:
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
276
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
493
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
276
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
100
@-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
276
@-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
100
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:
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:
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:
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:
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
493
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!
 
Back
Top