Gumps System Time Reactions Script

Script: Gumps System Time Reactions Script

Version: 1.0.0

Author: Gump

Description: This script provides a method of enabling a switch or setting a variables value at specific system times. The "system time" is the time on the computer that a player is playing your game on. So based on their current system time, you could have something happen in your game. This script is simplistic and provides the function of triggering a switch or setting a variable value at any specific date or time. This can be used to really do anything you can imagine for a time event. Something special on certain days, enabling certain things at certain times, all of that can be done with ease here. Just flip the switch and make the events! The 'simplistic' limitation at work here is you are only able to set a maximum of one switch and one variable for each defined time event. This should be enough to trigger any sort of secret/special thing via common event or whatnot. 🙂

Instructions: Please review the script header and all comments.

Legal Terms of Use:

  • You May freely use this script in any free or commercial game.
  • Providing credit for the use of this script in your game is optional.
Script (inside spoiler):
Spoiler
#===============================================================================# * Gumps System Time Reactions Script# * Version: 1.0.0# * Author: Matt 'Gump' Sully#-------------------------------------------------------------------------------# * Description:# > This Script provides a simple way of having reactions in your game based# on the current system time of the computer your game is being played on.# > This can allow you to have specific things happen at specific times, or# possibly insert nice time related secrets into your game!#-------------------------------------------------------------------------------# * LEGAL:# > You may freely use this script in any free or commercial game.# > If you use this script, providing credit is not required.#-------------------------------------------------------------------------------# * Instructions:# > You must define Realtimes with Actions in The "Definitions" part of the# Settings. # > First you define the required time, then you define the action.# > You can either turn on/off a single switch, or change the value of a single# variable, or both.# > Available Time properties are called using :symbols. The following Table# Shows you what symbols are available and their valid range.# :second = 0 - 59# :minute = 0 - 59# :hour = 0 - 23# :day = 1 - 31# :month = 1 - 12 # :year = 0 - 99# > Avaialble Action properties: These also use :symbols.# :game_switch = [switch_id, true/false]# :game_variable = [variable_id, value]## Sample Configs:#--------------------------------------------# > This configuration will turn switch 75 ON when it is Hour 1, Minute 27.## Timevents['sample_time'] = {}# Timevents['sample_time'][:minute] = 27# Timevents['sample_time'][:hour] = 1# Actions['sample_time'] = {}# Actions['sample_time'][:game_switch] = [75, true]## > This configuration will turn switch 71 ON and SET variable 55 to a value of# 115 when it is Month 5, Day 15, Hour 7, Minute 15, Second 5.## Timevents['easter_egg_417'] = {}# Timevents['easter_egg_417'][:second] = 5# Timevents['easter_egg_417'][:minute] = 15# Timevents['easter_egg_417'][:hour] = 7# Timevents['easter_egg_417'][:day] = 15# Timevents['easter_egg_417'][:month] = 5# Actions['easter_egg_417'] = {}# Actions['easter_egg_417'][:game_switch] = [71, true]# Actions['easter_egg_417'][:game_variable] = [55, 115]## > Oh, and you see How each of these events have different names? One is# 'sample_time' and one is 'easter_egg_417'. These names are simply put here for# your convenience as a developer. Choose a name for your time event that will# relate to your game/situation. Your name doesn't have to be a 'string'. It can# be a :symbol or an integer if desired.##===============================================================================##-------------------------------------------------------------------------------# * Initializing Warp Core... Don't touch the next few lines please.module GUMPSRTR # Don't touch this line sir or madam. Timevents = {} # Don't touch this line sir or madam. Actions = {} # Don't touch this line sir or madam. @system_time = {} # Don't touch this line sir or madam. @rtr_event_que = [] # Don't touch this line sir or madam. # # Initialization Complete. I hope you didn't touch those lines... # #-------------------------------------------------------------------------- # * SETTINGS #--------------------------------------------------------------------------- # The Check Delay is the delay time in FRAMES before each system time Check. # Normally, your game will process 60 frames per second. # Default Value: 20 #--------------------------------------------------------------------------- CHECK_DELAY_FRAMES = 20 # # # #------------------------------------------------------------------- # * DEFINITIONS SETTINGS: # > This is where you define the times and the actions to take! # > Definitions are important. With no definitions, there is no time. # > There is 1 sample definition here by default, and you should # probably remove it and replace it with your own set. #------------------------------------------------------------------- # *** INSERT YOUR DEFINITIONS UNDER THIS LINE! *** # Timevents['sample_time'] = {} Timevents['sample_time'][:minute] = 27 Timevents['sample_time'][:hour] = 1 Actions['sample_time'] = {} Actions['sample_time'][:game_switch] = [75, true] # # *** INSERT YOUR DEFINITIONS ABOVE THIS LINE! *** #-------------------------------------------------------------------------- # * END OF SETTINGS! DON'T EDIT BELOW THIS LINE UNLESS YER SCRIPTIN' #-------------------------------------------------------------------------- def self.get_system_time @system_time[:second] = Time.now.strftime('%S').to_i @system_time[:minute] = Time.now.strftime('%M').to_i @system_time[:hour] = Time.now.strftime('%H').to_i @system_time[:day] = Time.now.strftime('%d').to_i @system_time[:month] = Time.now.strftime('%m').to_i @system_time[:year] = Time.now.strftime('%y').to_i end def self.check_for_timevent break_op = false evkeys = Timevents.keys ackeys = Actions.keys index = 0 self.get_system_time for i in 0...evkeys.size key = evkeys[index] data = Timevents[key] subindex = 0; dtkeys = data.keys for i in 0...dtkeys.size kread = dtkeys[subindex] crc = data[kread] if @system_time[kread] == crc @rtr_event_que << key if subindex >= dtkeys.size - 1 else break_op = true end subindex += 1 break if break_op end index += 1 break if break_op end self.initialize_queued_events if @rtr_event_que.size > 0 end def self.initialize_queued_events return if @rtr_event_que.size < 0 index = 0 for i in 0...@rtr_event_que.size key = @rtr_event_que[index] p "Error: Undefined actions for #{key} in Gump Realtime Reaction Script" if $TEST && Actions[key].nil? data = Actions[key] subindex = 0; symbols = data.keys for i in 0...symbols.size tmp1 = symbols[subindex] if symbols[subindex] == :game_switch res = Actions[key][tmp1] switch = res[0] value = res[1] if value != true && value != false p "Error in Gump Realtime Reaction Script: Invalid Switch Parameter. Must be true or false" if $TEST end next if value != true || false $game_switches[switch] = value elsif symbols[subindex] == :game_variable res = Actions[key][tmp1] var_id = res[0] value = res[1] $game_variables[var_id] = value end subindex += 1 end index += 1 end @rtr_event_que.clear end endclass Scene_Map < Scene_Base alias :gump_rtr_update_78932trh0 :update def update(*args) gump_rtr_update_78932trh0 update_systemtime_reactions_gump end def update_systemtime_reactions_gump @gumprtr_delay ||= 0 @gumprtr_delay += 1 if @gumprtr_delay >= GUMPSRTR::CHECK_DELAY_FRAMES @gumprtr_delay = 0 GUMPSRTR.check_for_timevent end endend
Some possible things you could do with this script:

  • MMORPG-style "events". (Server wide 'events' that happen in certain times, such as a Christmas event, Halloween event, etc).
  • Change a big aspect of your game at a certain time
  • Hide secrets or easter eggs that have a specific system time requirement
  • And a lot more too. These are just the few I thought of!
Why did you do all the extra stuff? I already did this with a very easy set-up with my conditional check's script. You can set-up it up however you want with as many variables and switches as you want, just using a conditional statement.
Why did you do all the extra stuff? I already did this with a very easy set-up with my conditional check's script. You can set-up it up however you want with as many variables and switches as you want, just using a conditional statement.
Hey good job on that script I didn't know about it.

This one is more time-specific and will offer easy access to everything within the included Time class in RGSS3 in later versions, along with compatibility with my game time script that I am working on. Though you could do some of the same things with both scripts mine appears to have a different focus than yours. Two crafting scripts can exist next to eachother, I'm sure we'll be just fine.

Edit: From your Script:

# Note: Set these just before your check, if needed, but remember that ## each check is a new time stamp. Meanning if you are working in minutes ## there is a greater chance it will change while you are checking. #My script does not have this limitation because it functions via scene_map update, not relying on a series of conditional branches in an event and it sets the system time to a variable hash, then does its checking against that hash. This way a time event can't be missed if its setup. By default an average of 3 checks will be run by my script every second, and the refresh/delay rate for checking is a configurable setting.

I really like some of the features of your script, it really adds a lot of versatility in eventing various checks against the party and some other interesting things. I may contact you about using this commercially. 🙂
I guess I could update that comment as well. A lot more can be done with that. But I see your point, it is very tedious setting it all up in event(s). 

👍 btw! I was just curious as to why you created a new class(module method(s)) for it, but I get it now. Good job.
You know, couldn't this script be used to make a game where the in-game time matches the real time of the player? This definitely has some interesting potential.
You know, couldn't this script be used to make a game where the in-game time matches the real time of the player? This definitely has some interesting potential.
Hmm yes, With hourly delcared events setup within the script I suppose you could use it to adjust screen effects and things of that nature. My first reaction to your post was "well no, thats what not what was intended" but after thinking for a moment, I'm going to have to say yes.

Original thread: https://forums.rpgmakerweb.com/threads/gumps-system-time-reactions-script.20997/