FlipelyFlip

Playtime Window

20 posts in this topic

Heyey,

 

I'm posting this script, after I've found no script which do this (:

 

What does this script do?

The script adds a playtime window to the menu above the gold window.

 

How to use?

Simply plug'n'play. nothing to customize or anything else (:

 

Where is the script?

Here we go:

 

 

# This Script adds a playtime window to the menu (:

#==============================================================================
# ** Window Time
#------------------------------------------------------------------------------
#  Display Game Time
#==============================================================================
class Window_PlayTime < Window_Base
 def initialize(x, y)
super(x, y, 160, 60)
self.contents.font.bold = true
self.contents.font.size = 25
self.contents.font.color = normal_color
refresh
 end
 #--------------------------------------------------------------------------
 # * Refresh
 #--------------------------------------------------------------------------
 def refresh
self.contents.clear
@total_sec = Graphics.frame_count / Graphics.frame_rate
hour = @total_sec / 60 / 60
min = @total_sec / 60 % 60
sec = @total_sec % 60
ptime = sprintf("%02d:%02d:%02d", hour, min, sec)
self.contents.draw_text(4, 0, contents.width - 8, contents.height - 4, "Playtime: " + ptime, 2)
 end

 def update
super
if Graphics.frame_count / Graphics.frame_rate != @total_sec
  refresh
end
 end
end

class Scene_Menu < Scene_MenuBase

 #--------------------------------------------------------------------------
 # â— start
 #--------------------------------------------------------------------------
 alias flip_playtime_start start
 def start
flip_playtime_start
create_playtime_window
 end

 #--------------------------------------------------------------------------
 # â— create Playtime Window
 #--------------------------------------------------------------------------
 def create_playtime_window
@playtime_window = Window_PlayTime.new(0, 308)
 end
end

 

 

Little addition to this script, you can do it also with variables and you can also reset them. There is no window for. If wanted, just ask (:

Link

 

Terms of Use

Feel free to use it.

If you want to use it for a commercial RPG-Maker Game, just send me a message to know, there are no problems, I just want to know it (:

 

Credits

Took my VX-version script and rewrote some methodes to get work with Ace. Took me 5 minutes so not needed you lucky guys ;D

 

~Flip

Edited by FlipelyFlip

Share this post


Link to post
Share on other sites

Thanks for this! An under-stated staple for any game I believe. Any chance of this being tracked as a variable(s)? I have no idea how difficult it would be, but it would be very handy indeed.

Share this post


Link to post
Share on other sites

sure I can do (:

there is no problem (:

Just tell me how do you want it? in one variable or splitted in more than 1 variable? ^^

Share this post


Link to post
Share on other sites

sure I can do (:

there is no problem (:

Just tell me how do you want it? in one variable or splitted in more than 1 variable? ^^

Thank you! I found there is an entire game time variable, but I would love to have one for hours, minutes and seconds, but best of all would be if you could make them stop-watch like where I can reset the number of seconds (or whatever time base) to zero. I know I can reset the variable to zero, but then when it starts to count again it will just jump straight back to the total which I don't want.

 

Thanks heaps!

 

EDIT: But I guess the tricky part is resetting the time measurement for the sake of their own variables without actually resetting it for the overall game time displayed.

Edited by Tobyej

Share this post


Link to post
Share on other sites

This should do.

Use #reset_time(sec) to reset the displayed time only by sec (use "total" to reset to zero).

 

Oh, and Flipely. Sorry for me providing a solution when it's your script...

 

alias init initialize
def initialize(x, y)
 init(x, y)
 @offset = 0
end

alias refrs refresh
def refresh
 refrs
 variables
end

def variables
 $game_variables[1] = (@total_sec - @offset) / 60 / 60
 $game_variables[2] = (@total_sec - @offset) / 60 % 60
 $game_variables[3] = (@total_sec - @offset) % 60
end


def reset_time(index = "total")
 if index == "total"
  @offset = @total_sec
 else
  @offset += index
 end
end

 

Share this post


Link to post
Share on other sites

Thanks, but I got this error:

 

Script 'Time Variables' line 7: NameError occurred

undefined method 'refresh' for class 'object'

Share this post


Link to post
Share on other sites

Argh, I forgot to add that you have to either put this directly into Flipely's Window_PlayTime script or put it between this code:

class Window_PlayTime
end

Share this post


Link to post
Share on other sites

Ah, perhaps it's best if you merge it for me, it seems I REALLY don't know what I'm doing xD Errors in a different way no matter what I tried.

Share this post


Link to post
Share on other sites

Simply add my edit in one of these two ways:

1) (you'll have to do this after adding Flipely's script)

class Window_PlayTime
<<enter_my_script_here>>
end

2) Add Flipely's script.

Add my script just above the very last

end

Share this post


Link to post
Share on other sites

Hold on, do I have to edit any of the values in your script before it works? I can get the game to start but it breaks when I go to open the menu with a TypeError on line 15: nil can't be coerced into a Fixnum. Sorry for all this, but I just can't get it even when I follow exactly what you say.

Share this post


Link to post
Share on other sites

Your error sounds like you didn't add my script at the right place. Therefore, initialize wasn't changed and @offset wasn't set, thus resulting in an error at method reset_time.

I quickly joined both scripts for you, I hope Flipely doesn't have a problem with that.

€: Actually, it was my fault. I didn't realize that initialize calls refresh method. Anyways, I just moved the @offset = 0 one line higher and it should work now.

 

 

# This is an edit of a script by FlipelyFlip.
# although regendo made the edit, all credit goes to FlipelyFlip at
# rpgmakervxace.net
#=============================
#ORIGINAL SCRIPT BY FLIPELYFLIP
#=============================
# This Script adds a playtime window to the menu (:
#==============================================================================
# ** Window Time
#------------------------------------------------------------------------------
#  Display Game Time
#==============================================================================
class Window_PlayTime < Window_Base
 def initialize(x, y)
	super(x, y, 160, 60)
	self.contents.font.bold = true
	self.contents.font.size = 25
	self.contents.font.color = normal_color
	refresh
 end
 #--------------------------------------------------------------------------
 # * Refresh
 #--------------------------------------------------------------------------
 def refresh
	self.contents.clear
	@total_sec = Graphics.frame_count / Graphics.frame_rate
	hour = @total_sec / 60 / 60
	min = @total_sec / 60 % 60
	sec = @total_sec % 60
	ptime = sprintf("%02d:%02d:%02d", hour, min, sec)
	self.contents.draw_text(4, 0, contents.width - 8, contents.height - 4, "Playtime: " + ptime, 2)
 end
 def update
	super
	if Graphics.frame_count / Graphics.frame_rate != @total_sec
	  refresh
	end
 end
#================
#EDIT BY REGENDO
#================
alias init initialize
def initialize(x, y)
 @offset = 0
 init(x, y)
end

alias refrs refresh
def refresh
 refrs
 variables
end

def variables
 $game_variables[1] = (@total_sec - @offset) / 60 / 60
 $game_variables[2] = (@total_sec - @offset) / 60 % 60
 $game_variables[3] = (@total_sec - @offset) % 60
end


def reset_time(index = "total")
 if index == "total"
  @offset = @total_sec
 else
  @offset += index
 end
end
#=======================
#END OF REGENDO'S EDIT
#=======================
end
class Scene_Menu < Scene_MenuBase
 #--------------------------------------------------------------------------
 # â— start
 #--------------------------------------------------------------------------
 alias flip_playtime_start start
 def start
	flip_playtime_start
	create_playtime_window
 end
 #--------------------------------------------------------------------------
 # â— create Playtime Window
 #--------------------------------------------------------------------------
 def create_playtime_window
	@playtime_window = Window_PlayTime.new(0, 308)
 end
end

 

Edited by regendo

Share this post


Link to post
Share on other sites

Gah, got this error:

 

Name Error on line 64,

undefined method 'refresh' for class 'Scene_Menu'

 

It's the only script on a fresh project :(

Share this post


Link to post
Share on other sites

Alright! Got it to start without crashing and display time, but how exactly do I make the variable reset? I have the game_variables set to 28, 29, 30 which are the variables I want to use in my game, I have 28 set to 'game time' but when I activate the #reset_time(sec) code, the variable doesn't chang eand just keeps on counting.

 

Ah! Am I meant to link the variable to your code via script in the variable options?

 

Es tut mir leid ueber die kodf schmerz, ich bin neu zu RM. Und ich habe Deutsch gelernt fuer 2-3 jahre, aber nur fuer spass :) Gehe ich da im 2013.

Share this post


Link to post
Share on other sites

Kein Problem :) Ehrlich gesagt ist dein Anfänger-Deutsch besser als das Englisch von vielen Leuten hier...

Aber wir sollten lieber wieder zum Englischen zurückkehren, bevor sich noch wer beschwert.

Viel Spaß in Deutschland nächstes Jahr :thereisnothumbsupsmiley:

 

First, you need to go to the script and find the "variable" method where you change the $game_variables to whichever you want to use.

Then you call Window_PlayTime#reset_time like this

@what_did_you_call_the_window.reset_time(3600)

This displays one hour less than it actually is.

Replace "@what_did_you_call_the_window" with the name, as you can find it where you create the window.

Example taken from the code:

@playtime_window = Window_PlayTime.new(0, 308)

In this case, it's @playtime_window.reset_time(seconds)

Share this post


Link to post
Share on other sites

@Tobyej so I got it :D

 

I have the script done (:

 

It's easy working (:

 

 

#============================================================================
# * PlayTime Variable Thing oO
#----------------------------------------------------------------------------
# made by FlipelyFlip
#============================================================================
# Easy-working. Just Plug'n'Play (:
# Only define the Module if you do not agree with the standard-settings
# Just set the ResetSwitch to on to reset the variables to Zero!!
# Please Credit me if you use it, because it was a hard work to make it work 
#============================================================================
module Flip
 VarIDSec = 3    # VarID for the Seconds
 VarIDMin = 2    # VarID for the Minutes
 VarIDHour = 1   # VarID for the Hours
 ResetSwitch = 1 # SwitchID for Reseting.
end

class Game_Map

 #--------------------------------------------------------------------------
 # sets the timer to variables
 # * timer is counting further, but if variables are resetet, playtime and
 # @var_dude aren't the same anymore (:
 #--------------------------------------------------------------------------
 def set_timer_to_variables
   @var_dude = Graphics.frame_count / Graphics.frame_rate # Sets @var_dude equal
   # to playtime for checking it later
   $game_variables[Flip::VarIDSec] += 1 # adds a second to variable seconds
   if $game_variables[Flip::VarIDSec] >= 60 # checks if seconds are higher
  # or equal 60
  $game_variables[Flip::VarIDMin] += 1 # adds a minute to variable minute
  $game_variables[Flip::VarIDSec] -= 60 # subs the minute form the seconds
   end # same here below with minutes to hours (:
   if $game_variables[Flip::VarIDMin] >= 60
  $game_variables[Flip::VarIDHour] += 1
  $game_variables[Flip::VarIDMin] -= 60
   end
 end

 #--------------------------------------------------------------------------
 # update method. Nothing intressiting (:
 #--------------------------------------------------------------------------
 alias flip_update_var_timer update
 def update(main = false)
   flip_update_var_timer(main)
   reset_variable_timer
 end

 #--------------------------------------------------------------------------
 # resets the variable timer and also checks to add to the variable the seconds
 #--------------------------------------------------------------------------
 def reset_variable_timer
   if $game_switches[Flip::ResetSwitch] # checks if resetswitch is true
  $game_variables[Flip::VarIDSec] = 0 # resets all 3 variables
  $game_variables[Flip::VarIDMin] = 0
  $game_variables[Flip::VarIDHour] = 0
  $game_switches[Flip::ResetSwitch] = false # set the resetswitch to false
   end
   if @var_dude != Graphics.frame_count / Graphics.frame_rate # checks if
  # a second has past to update the timer
  set_timer_to_variables # calls method to set the timer (:
   end
 end
end

 

Instructions how it works is in the script. It's just plug and play and don't need the PlayTime Window Script above (:

 

@regendo: thx für die Vertretung. Hab deins zwar nich getestet, dürfte aber wsl auch funken, wenn ich mich jetz nich irre^^ ;)

(for all non-german speakers: thx for the representation. I haven't tested your script-edit yet, but I think it should work either^^

 

~Flip

Tobyej likes this

Share this post


Link to post
Share on other sites

I don't know why I thought of a bunch of kids jumping around and screaming when I read "Play time window". But little snippets like this are always welcome, thanks.

Share this post


Link to post
Share on other sites

Hell yeah! This works a treat ^^ It's something that I am totally surprised is missing from the editor in the first place, considering how staple it is for almost every game made after the 80s (I guess they tried with the timer thing, but it's just not right at all, especially with the number in the corner of the screen).

 

Thanks guys!

Share this post


Link to post
Share on other sites

Great little script. I appreciate you sharing it.

It really adds a nice looking feature to my new game I'm making.

Many thanks and keep up the good work. :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.