[XP] Global Day-and-Night System for RMX-OS

Started by Blizzard, December 28, 2009, 12:32:04 pm

Previous topic - Next topic

Blizzard

December 28, 2009, 12:32:04 pm Last Edit: March 23, 2019, 11:34:13 am by Blizzard
Global Day-and-Night System for RMX-OS
Authors: Blizzard
Version: 1.2
Type: RMX-OS plugin
Key Term: RMX-OS Plugin



Introduction

This script utilizes ATES to allow a serverside globally controlled Day-and-Night System in the game

This script is to be distributed under the same terms and conditions like the script it was created for: RMX-OS.


Features


  • easy to configure
  • globally controlled time



Screenshots

N/A for this sort of script.


Demo

N/A


Script

Just make a new script above main and paste this code into it.
Spoiler: ShowHide
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
# Global Day-and-Night System for RMX-OS by Blizzard
# Version: 1.2
# Type: RMX-OS Add-on
# Date: 28.12.2009
# Date v1.01: 3.1.2010
# Date v1.02: 23.4.2010
# Date v1.03: 24.5.2010
# Date v1.1: 14.3.2013
# Date v1.11: 30.3.2013
# Date v1.2: 12.6.2013
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#
#  This script is to be distributed under the same terms and conditions like
#  the script it was created for: RMX-OS.
#
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#
# Information:
#
#   This script must be placed below RMX-OS and requires RMX-OS to work
#   properly. This script utilizes ATES to allow a serverside globally
#   controlled Day-and-Night System in the game and requires ATES. It must be
#   placed below ATES.
#   
# Notes:
#   
#   - Adding this script can cause save data corruption in the server's
#     database.
#   - This is only a global day and night system that counts the time. Calender
#     features will work, but nothing else will.
#   - You can't use [] for the START configuration, you have to set up a start
#     date, because the weekday is important.
#   
#   
# If you find any bugs, please report them here:
# http://forum.chaos-project.com
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=

if !defined?(RMXOS) || RMXOS::VERSION < 2.0
  raise 'ERROR: The "Global DNS" requires RMX-OS 2.0 or higher.'
elsif !$ates || $ates < 1.01
  raise 'ERROR: The "Global DNS" requires ATES 1.01 or higher.'
end

$rmxos_gdns = 1.2

#==============================================================================
# module RMXOS::Options
#==============================================================================

module RMXOS::Options

  # additional ATES settings that should be stored
  SAVE_DATA[Game_System].push('@ates')
  SAVE_DATA[Game_System].push('@show_clock')
  SAVE_DATA[Game_ATES] = ['@active']
  SAVE_DATA[Game_ATES] = ['@tinting']
  SAVE_DATA[Game_ATES] = ['@time']
  SAVE_DATA[Game_ATES] = ['@weather']
  SAVE_DATA[Game_ATES] = ['@frame_count']
  SAVE_DATA[Game_ATES] = ['@current_times']
  SAVE_DATA[Game_ATES] = ['@tone']
  SAVE_DATA[Game_ATES] = ['@map_type']
  SAVE_DATA[Game_ATES] = ['@show_weather']
  SAVE_DATA[Game_ATES] = ['@terrain']
  SAVE_DATA[Game_ATES] = ['@temp']
  SAVE_DATA[Game_ATES] = ['@holiday']
  SAVE_DATA[Game_ATES] = ['@time_index']
 
end

#==============================================================================
# RMXOS::Network
#==============================================================================

class RMXOS::Network
 
  alias check_game_gdns_later check_game
  def check_game(message)
    if message =~ /\AGDNS\t(.+)\t(.+)\t(.+)\t(.+)/
      if $game_system != nil && $game_system.ates != nil
        day = $1.to_i
        month = $2.to_i
        year = $3.to_i
        time = $4.to_i
        hour_length = ATES::LENGTH / 24.0
        hours = (hour_length > 0 ? (time / hour_length) : 0)
        minute_length = hour_length / 60.0
        minutes = (minute_length > 0 ? (time / minute_length) : 0)
        $game_system.ates.time = ATES::Time.new(0, 0, day, month, year, ATES::START[3])
        ATES.advance(minutes, 0, 0, 0, 0)
      end
      return true
    end
    return check_game_gdns_later(message)
  end
   
end

#==============================================================================
# Game_ATES
#==============================================================================

class Game_ATES
 
  alias init_gdns_later initialize
  def initialize
    init_gdns_later
    @tinting = true
    @active = true
    if $game_system != nil && $game_system.ates != nil
      @time = $game_system.ates.time
    end
  end
 
  def update # prevent ATES from updating in-game and messing up everything
  end
 
end


Make a new file with an .rb extension in the Extensions folder of RMX-OS and copy-paste this script into it.
Spoiler: ShowHide
module RMXOS
 
  def self.load_current_extension
    return GlobalDNS
  end
 
  module Data
    GlobalDNSTimeNow = '    > Global DNS Current Time: TIME'
  end
 
end

#======================================================================
# module GlobalDNS
#======================================================================

module GlobalDNS
 
  VERSION = 1.2
  RMXOS_VERSION = 2.0
  SERVER_THREAD = true
 
  # START Configuration
  MIDNIGHT_TIME = 0 # seconds after midnight when in game midnight starts (between 0 and 86400, use a divider of LENGTH!)
  UPDATE_INTERVAL = 1 # how often is time data sent to clients (lower values can increase server load!)
  # make sure THESE variables match the ones in the ATES script)
  LENGTH = 144 # how many seconds does a full day take (between 24 and 86400, use a divider of 86400!)
  START = [24, 11, 2007] # the first day in the game [DAY, MONTH, YEAR] set this option to [] if you want the game to start "now"
  # END Configuration
 
  def self.initialize
    @mutex = Mutex.new
    @client_times = {}
    @server_start = Time.now
    @start_time = START.clone
    if START.size != 3
      time = Time.utc(START[2], START[1], START[0])
      @start_time = [time.day, time.month, time.year]
    end
    self.update_time
    puts RMXOS::Data.args(RMXOS::Data::GlobalDNSTimeNow, {'TIME' => self.time_to_timestring})
  end
 
  def self.mutex
    return @mutex
  end
 
  def self.main
    while RMXOS.server.running
      @mutex.synchronize {
        self.server_update
      }
      sleep(0.1)
    end
  end
 
  def self.server_update
    self.update_time
    logged_in_clients = RMXOS.clients.get
    time = Time.now
    @client_times.each_key {|client|
      if time - @client_times[client] > UPDATE_INTERVAL
        self.send_time(client, time)
      end
    }
    (@client_times.keys - logged_in_clients).each {|key| @client_times.delete(key)}
    (logged_in_clients - @client_times.keys).each {|key| @client_times[key] = time}
  end
 
  def self.client_update(client)
    case client.message
    when /\ALRQ\Z/, /\AENT\Z/, /\AMEX\Z/ # send DNS time on load request, enter server and exit map
      self.send_time(client)
    end
    return false
  end
 
  def self.send_time(client, time = Time.now)
    begin
      client.send('GDNS', @start_time[0], @start_time[1], @start_time[2], (@time + MIDNIGHT_TIME).to_i)
      @client_times[client] = time
    rescue
      @client_times.delete(client)
    end
  end
 
  def self.update_time
    @time = Time.now - @server_start
  end
 
  def self.time_to_timestring(time = @time)
    hour_length = LENGTH / 24.0
    hours = (hour_length > 0 ? (time / hour_length) : 0)
    minute_length = hour_length / 60.0
    minutes = (minute_length > 0 ? (time % hour_length / minute_length) : 0)
    return sprintf('%02d:%02d', hours.to_i, minutes.to_i)
  end
 
end




Instructions

In the script in the first comment.


Compatibility

Requires RMX-OS to work.
Requires ATES to work.


Credits and Thanks


  • Boris "Blizzard" Mikić



Author's Notes

If you find any bugs, please report them here:
http://forum.chaos-project.com

That's it! N-Joy! =D
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Ryex

darn you beat me to it :P.
oh well i bet you did it better anyway
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Jackolas

:bow: this is great!!  :bow:

ATES for RMX-OS

I failed big time trying to get ATES to work on my game :P

Blizzard

December 28, 2009, 01:01:07 pm #3 Last Edit: December 28, 2009, 01:03:10 pm by Blizzard
Lol! I made this for Auspiex. There will be another few scripts/RMX-OS plugins coming which I will make because of Auspiex.

EDIT: And the add-ons are always so small. :3
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Blizzard

v1.01 is out. It works properly with RMX-OS v1.08.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

crzyone9584

February 04, 2010, 11:40:17 pm #5 Last Edit: February 05, 2010, 12:23:27 am by crzyone9584
Is there a way to make a 12 hour clock instead of a 24 hour?

Blizzard

Why would somebody want that? Yes, you can do that by changing the 24.0 in line 61 to 12.0.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

crzyone9584

February 05, 2010, 12:09:17 pm #7 Last Edit: February 05, 2010, 12:34:15 pm by crzyone9584
Quote from: Blizzard on February 05, 2010, 10:42:21 am
Why would somebody want that? Yes, you can do that by changing the 24.0 in line 61 to 12.0.


Ummm, because its easier on my eyes so i don't have to remember 24 hour clock. and easier for people who don't know 24 hour clock lol. And easier to coordinate events on the server lol

(EDIT: Ok now im really confused i changed the 24.0 to 12.0 it was actually line 60 but now its either saying its 5:16 in the morning at night not sure lol. but the server is 10:34 lol so yea im mad confused.)

Blizzard

My bad. >.<
Don't worry if there's a line mismatch. It's probably because of the config or something else.

Anyway, change the 12.0 back to 24.0. Find this line (should be 64):

$game_system.ates.time = ATES::Time.new(minutes.to_i, hours.to_i)


Change it to this:

$game_system.ates.time = ATES::Time.new(minutes.to_i, hours.to_i % 12)
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Lost King

So I'm pretty sure the problem is coming from this. Anyway, when I go to start a game before anything else, the screen turns solid Yellow and all I can see is the chat box, my name, and the clock. I turn on ATES and to get rid of the yellow I need to turn ATES.tint_off, and while it fixes it, I'd rather like to have a distinguishable difference between night and day.
*Scribble Scribble* Oh right, not that sort of signature.

Blizzard

That can only happen if you didn't configure everything properly.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Lost King

What exactly do I need to do in configuration? My script setup is as follows:
RPG Maker defaults
ATES
RMX-OS Options
RMX-OS Script
RMX-OS ATES Plugin
RMX-OS Main

I've got the extension file saved in extensions as a .rb, it comes up as open with Ruby so that's saved correctly and I've got it included in the extentions box on the RMX-OS GUI. I changed the time settings in ATES to reflect that of an entire day but for some reason only the minutes show up on the clock and the hour is just 00.
*Scribble Scribble* Oh right, not that sort of signature.

crzyone9584

Quote
ATES
RMX-OS Options
RMX-OS Script
RMX-OS ATES Plugin
RMX-OS Main


Thats your problem right there. ATES needs to go under RMX-OS Script. and the ATES Plugin under ATES so should look like this

Quote
RMX-OS Options
RMX-OS Script
ATES
RMX-OS ATES Plugin
RMX-OS Main


Hope that helps. I fixed the yellow for me. Still trying to get the right time lol. for some reason when i change it to 12 hour clock its way to early or late as in at 12 it mid night and midnight is noon lol

Lost King

Well, changing the script order to that did nothing...
*Scribble Scribble* Oh right, not that sort of signature.

crzyone9584

Well thats what fixed my yellow.

also are you running the event that calls the script as auto run or parallel? maybe thats what fixed mine. although i changed both at the same time so im not sure what one fixed it make sure its not auto run event calling the ates system.

Lost King

I have it run as Parallel Process, but regardless of whether or not I even turn it on, it starts out yellow and stays yellow, I even do the ATES.make_it_night call and it just flashes the night color and goes back to yellow. The only fix I've found was using ATES.tint_off but that kind of makes the whole system lame if I have a clock but nothing to actually distinguish day from night.
*Scribble Scribble* Oh right, not that sort of signature.

Ryex

did you make sure to erase the parallel event?

ie

ATES.method_call
Erase Event

other wise the parallel process event loops and keeps calling ATES.method_call every frame.
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Lost King

Yes, I've tried it with and without erasing, I've also tried it as an action button event, ie talking to an NPC, but I still get no difference.
*Scribble Scribble* Oh right, not that sort of signature.

Ryex

I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Blizzard

It can only be yellow if your server configuration is not matched with the game configuration, that's what I was trying to say. -_-
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.