Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Day-Night Clock update won't work

Hi there.
I use the Dynamic Day and Night System (DDNS) by Blizzard in my game and tried to edit a script for an HUD to make clock where you can see, what daytime it is.

But in my game, it won't update on the map, only if I call the menu and go back to the game by pressing "esc" the clock will update.

Is there anyone who can help me, fixing my problem?
It is important to make it compatible with the DDNS and to have it fade away when the Player reaches the area where the clock is displayed.

To make it easier for you, I uploaded a small demo with the graphics and the scripts... I would appreciate it, if you'll take the HUD Script I took, so I can learn what I've done wrong.... ^^

Hope you can help me fixing this problem...

Heres the demo: http://www.mediafire.com/?i4tumzkv0wd

Greetings,
Darkwonder ^^

P.S. Sorry for my bad english... ^^'
 
I improved on it some, I separated updating the hud graphics from determining if it's a new hour (it was getting stuck in a loop before with two methods calling each other), and fixed the code that caused the clock sound effect ($game_system.se_play expects an RPG::Audio_File, not a sound name, so it crashed). It does update the hud on the map now. You still need to do something to make the hour change only occur at the initial change of an hour, not for the entire second following the change in time.

I also changed the indentation, it was hard to read :M

[rgss]#_______________________________________________________________________________
# MOG XAS Time Hud V1.0
#_______________________________________________________________________________
# By Moghunter, edited by Darkseed
#
#_______________________________________________________________________________
 
module XAS_TIME
  # Variablen für Tag und Nacht
  TAG = 16 #=600 Sekunden
  NACHT = 17 #=420 Sekunden
  TAGZ = 40 #Variable zum abfragen für den Updateprozess Tag
  NACHTZ = 41 #Variable zum abfragen für den Updateprozess Nacht
  #Position
  XASTIME_X = 450
  XASTIME_Y = -16
  #ID vom Schalter der alles ausstellt
  DISABLE_STATUS_TIME_SWITCH = 77
  #HUD transparent machen bei Heldenkontakt
  FADE = true
end
$mog_rgss_xas_time = true
#####################
# Window_Status_Map #
#####################
class Window_Time < Window_Base
  def initialize
    super(0, 0, 640, 480)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.windowskin = RPG::Cache.windowskin("")    
    self.contents.font.bold = true
    self.contents.font.name = "Georgia"
    self.opacity = 255
    @old_day = $game_variables[XAS_TIME::TAGZ]
    @old_night = $game_variables[XAS_TIME::NACHTZ]
    refresh
  end
 
  def refresh(time_bitmap_name = "Uhr1")
    self.contents.clear
    draw_mapzeit(@actor, 0, 0, time_bitmap_name)
  end
 
  def update
    if XAS_TIME::FADE == true
      x = ($game_player.real_x - $game_map.display_x) / 4
      y = ($game_player.real_y - $game_map.display_y) / 4
      time_size_x = 184
      time_size_y = 149
      oc_range_x = time_size_x + XAS_TIME::XASTIME_X
      oc_range_y = time_size_y + XAS_TIME::XASTIME_Y
      if x < oc_range_x and x > XAS_TIME::XASTIME_X - 5 and
          y > XAS_TIME::XASTIME_Y and y < oc_range_y
        self.contents_opacity -= 10 if  self.contents_opacity > 120
      else
        self.contents_opacity += 10 if  self.contents_opacity < 255
      end
    end
    @old_day = $game_variables[XAS_TIME::TAGZ]
    @old_night = $game_variables[XAS_TIME::NACHTZ]
    bitmap_name = update_time
    if @old_day != $game_variables[XAS_TIME::TAGZ] or
        @old_night != $game_variables[XAS_TIME::NACHTZ]
      $game_system.se_play(RPG::AudioFile.new('033-switch02', 100))
      refresh(bitmap_name)
    end
  end
 
  def update_time
    if $game_variables[XAS_TIME::TAG] == 1 and $game_variables[XAS_TIME::NACHT] == 0
      bitmap_name = "Uhr1"
      $game_variables[XAS_TIME::TAGZ] += 1
      $game_variables[XAS_TIME::NACHTZ] = 0
    elsif $game_variables[XAS_TIME::TAG] == 120 and $game_variables[XAS_TIME::NACHT] == 0
      bitmap_name = "Uhr2"
      $game_variables[XAS_TIME::TAGZ] += 1
    elsif $game_variables[XAS_TIME::TAG] == 240 and $game_variables[XAS_TIME::NACHT] == 0
      bitmap_name = "Uhr3"
      $game_variables[XAS_TIME::TAGZ] += 1
    elsif $game_variables[XAS_TIME::TAG] == 360 and $game_variables[XAS_TIME::NACHT] == 0
      bitmap_name = "Uhr4"
      $game_variables[XAS_TIME::TAGZ] += 1
    elsif $game_variables[XAS_TIME::TAG] == 480 and $game_variables[XAS_TIME::NACHT] == 0
      bitmap_name = "Uhr5"
      $game_variables[XAS_TIME::TAGZ] += 1
    elsif $game_variables[XAS_TIME::TAG] == 550 and $game_variables[XAS_TIME::NACHT] == 0
      bitmap_name = "Uhr6"
      $game_variables[XAS_TIME::TAGZ] += 1
    elsif $game_variables[XAS_TIME::TAG] == 0 and $game_variables[XAS_TIME::NACHT] == 1
      bitmap_name = "Uhr7"
      $game_variables[XAS_TIME::NACHTZ] += 1
      $game_variables[XAS_TIME::TAGZ] = 0
    elsif $game_variables[XAS_TIME::TAG] == 0 and $game_variables[XAS_TIME::NACHT] == 84
      bitmap_name = "Uhr8"
      $game_variables[XAS_TIME::NACHTZ] += 1
    elsif $game_variables[XAS_TIME::TAG] == 0 and $game_variables[XAS_TIME::NACHT] == 168
      bitmap_name = "Uhr9"
      $game_variables[XAS_TIME::NACHTZ] += 1
    elsif $game_variables[XAS_TIME::TAG] == 0 and $game_variables[XAS_TIME::NACHT] == 252
      bitmap_name = "Uhr10"
      $game_variables[XAS_TIME::NACHTZ] += 1
    elsif $game_variables[XAS_TIME::TAG] == 0 and $game_variables[XAS_TIME::NACHT] == 336
      bitmap_name = "Uhr11"
      $game_variables[XAS_TIME::NACHTZ] += 1
    elsif $game_variables[XAS_TIME::TAG] == 0 and $game_variables[XAS_TIME::NACHT] == 420
      bitmap_name = "Uhr12"
      $game_variables[XAS_TIME::NACHTZ] += 1
    else $game_variables[XAS_TIME::TAG] == 0 and $game_variables[XAS_TIME::NACHT] == 420
      bitmap_name = "Uhr1"
    end
    return bitmap_name
  end
 
  def draw_mapzeit(actor, x, y, bitmap_name)
    bitmapzi = RPG::Cache.picture(bitmap_name)
    cw = bitmapzi.width
    ch = bitmapzi.height
    src_rect = Rect.new(0, 0, cw, ch)
    self.contents_opacity = 180
    self.contents.blt(x , y , bitmapzi, src_rect)
  end
end
###############
# Game_Player #
###############
class Game_Player < Game_Character
  attr_accessor :wref
end
#############
# Scene_Map #
#############
class Scene_Map
  alias mogtime_main main
  def main
    @sttime = Window_Time.new
    @sttime.x = XAS_TIME::XASTIME_X
    @sttime.y = XAS_TIME::XASTIME_Y
    @sttime.z = 7901
    if $game_switches[XAS_TIME::DISABLE_STATUS_TIME_SWITCH] == false
      @sttime.visible = true  
    else
      @sttime.visible = false  
    end    
    mogtime_main
    @sttime.dispose
  end
  alias mogtime_update update
  def update
    if $game_switches[XAS_TIME::DISABLE_STATUS_TIME_SWITCH] == false
      @sttime.visible = true  
    else
      @sttime.visible = false  
    end      
    @sttime.update
    mogtime_update
  end
end
[/rgss]
 
Hi BwdYeti

Thanx for ya help.. ^^ It now works for me, but I can't get it fixed, that the sound won't repeat, after the clock is updating... also the clock will fade if it's updating the time... is this normal? Can someone help me with this??? Because now it lags a short while when the clock is updating it's time. ^^
Would be very nice, if you can help me.. ^^

Greetings and happy 4th Advent to all ^^
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top