ChampX

Veteran
Veteran
Joined
Aug 14, 2016
Messages
221
Reaction score
146
First Language
English
Primarily Uses
RMMV
RPG Maker MV is designed to run generally at 60 fps. As such, it keeps track of the total amount of play time a player has been playing by monitoring the total number of frames that have been run. This is all fine and dandy if the game is always running at 60 fps. If, however, the player is on a machine that is older and cannot run MV games at 60 fps, the accuracy of the total play time way off. If the game is running at 30 fps on average, then the play time recorded by MV will be HALF of the play time played in reality. The inverse is also true if the game was running at higher frame rates, which can happen on 144hz monitors.

This simple plug-n-play plugin addresses this issue by using real-time to keep track of the total play time played by the player instead of the total number of frames.

You can also reset the playtime as well, useful for those with games that start a little bit after the new game is launched. You can also pause and resume the playtime if you wish to avoid the game ticking up during cutscenes.

To use: Simply copy/paste the plugin code below into a text editor and save it as AccuratePlaytime.js (you can call it whatever you want actually as long as you include the .js). To reset the play time, type ResetPlaytime in a plugin command window. To pause the play time, type PausePlaytime and to resume the play time, type ResumePlaytime. Pausing will not persist if the game is saved then reloaded.

Terms: Use as you like. Free or commercial. Modify or extend as needed. Credit isn't even necessary though you are welcome to.

Code:
/*:
* @plugindesc Counts total playtime accurately regardless of framerate
* @help This plugin is plug-n-play and requires no parameters to set.
* To reset the play time, type ResetPlaytime in a plugin command window
* Version 1.3: Pause and ResumePlaytime commands added, also addressed a bug with doubling playtime
* Version 1.2: ResetPlaytime command
* Version 1.1: Addresses bug fix to saves not storing time correctly after multiple saves
*/

(function()
{
   
    var startTime = 0;
    var pausedTime = 0;
    var paused = false;
    
    var _DataManager_setupNewGame = DataManager.setupNewGame;
    var _GameSystem_initialize = Game_System.prototype.initialize;
    var _GameSystem_onBeforeSave = Game_System.prototype.onBeforeSave;
    var _GameSystem_onAfterLoad = Game_System.prototype.onAfterLoad;  
    var _GameInterpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
    Game_Interpreter.prototype.pluginCommand = function(command, args) 
    {
        _GameInterpreter_pluginCommand.call(this, command, args);
        if (command === 'ResetPlaytime') 
        {
            startTime = Date.now();
            $gameSystem._playtime = 0;
        }
        if (command === 'PausePlaytime')
        {
            if (paused) return;
            paused = true;
            pausedTime = Date.now() - startTime;
        }
        if (command === 'ResumePlaytime')
        {
            if (!paused) return;
            paused = false;
            startTime = Date.now() - pausedTime;
        }
    };
    DataManager.setupNewGame = function() 
    {
        _DataManager_setupNewGame.call(this);
        startTime = Date.now();
    };
    
    Game_System.prototype.initialize = function() 
    {
        _GameSystem_initialize.call(this);
        this._playtime = null;
    };
    Game_System.prototype.onBeforeSave = function() 
    {
        _GameSystem_onBeforeSave.call(this);
        var saveTime = Date.now() - startTime;
        this._playtime = paused ? this._playtime + pausedTime : this._playtime + saveTime;
        startTime = Date.now();
        pausedTime = 0;
    };
    Game_System.prototype.onAfterLoad = function() 
    {
        _GameSystem_onAfterLoad.call(this);
        startTime = Date.now();
    };
    Game_System.prototype.playtime = function() 
    {
        return Math.floor((paused ? (this._playtime + pausedTime) : (Date.now() - startTime + this._playtime)) / 1000);
    };

})();
 
Last edited:

JohnOminae

Villager
Member
Joined
Mar 13, 2012
Messages
28
Reaction score
26
First Language
English
Primarily Uses
Other
Thanks for this, ChampX! I can see this one being essential. Gonna try this out soon! :D
 

TenTranVN

Veteran
Veteran
Joined
Apr 13, 2017
Messages
175
Reaction score
19
First Language
Vietnam
Primarily Uses
RMMV
Does this plugin reduce lag for weak devices?
 

ChampX

Veteran
Veteran
Joined
Aug 14, 2016
Messages
221
Reaction score
146
First Language
English
Primarily Uses
RMMV
@TenTranVN No it doesn't reduce any lag. It instead just makes it so the playtime counter is accurate regardless of if there is lag or not.
 

SiiOs

Villager
Member
Joined
Oct 13, 2017
Messages
18
Reaction score
4
First Language
English
Primarily Uses
RMMV
Was just looking for something like this today and stumbled across the thread. Did as you said and it's working great. That inaccurate playtime was bugging me so bad. Thanks!
 

ChampX

Veteran
Veteran
Joined
Aug 14, 2016
Messages
221
Reaction score
146
First Language
English
Primarily Uses
RMMV
Updated to address bug fix regarding time not storing properly after multiple saves
 

Ace of Spades

Veteran
Veteran
Joined
Jan 19, 2017
Messages
162
Reaction score
238
First Language
English
Primarily Uses
Updated to address bug fix regarding time not storing properly after multiple saves
Thanks for the update, it seems to be working properly now. Quick question; I was wondering if there's a script call I can use to reset the time played back to 0. I'm using an evented title screen, so by the time the player starts their first game and gets past the title, there's already a minute or so on the save file. It'd be nice to be able to reset the timer after the opening cinematic, right after the player gains control of their character.
 

ChampX

Veteran
Veteran
Joined
Aug 14, 2016
Messages
221
Reaction score
146
First Language
English
Primarily Uses
RMMV
Added a bug fix to where time could potentially double on same slot sessions. Also added Pause and Resume Playtime commands.
 

Animebryan

Need more resources!
Veteran
Joined
Jul 31, 2012
Messages
460
Reaction score
245
First Language
English
Primarily Uses
RMMZ
Is this compatible with MZ?
 

ChampX

Veteran
Veteran
Joined
Aug 14, 2016
Messages
221
Reaction score
146
First Language
English
Primarily Uses
RMMV
@Animebryan I honestly do not know. Probably? I don't see why not as it isn't doing anything too special. I don't use MZ though.

If anyone wishes to test it out in MZ and if necessary make edits to make it compatible, be my guest!
 

Latest Threads

Latest Posts

Latest Profile Posts

So many ideas, so little energy.
SA57Face.pngSA57_IDLE.gifThis is just a "Chinese opera actor" who is totally not a serial killer. Now, we just need to clean up a pile of dead bodies found in his backyard. :kaojoy:
E7DsT3VXsAInVpu

working on my avatar, because i couldn't stand looking at it anymore :D
still not finished though...
alpacaraptors = love!

Forum statistics

Threads
113,585
Messages
1,076,023
Members
147,576
Latest member
Hubi
Top