Accurate Playtime

ChampX

Veteran
Veteran
Joined
Aug 14, 2016
Messages
187
Reaction score
120
First Language
English
Primarily Uses
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.

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.

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.2: ResetPlaytime command
* Version 1.1: Addresses bug fix to saves not storing time correctly after multiple saves
*/

(function()
{
    var startTime = 0;
    var loadedTime = 0;

    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();
            loadedTime = 0;
        }
    };

    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 += saveTime;
    };

    Game_System.prototype.onAfterLoad = function()
    {
        _GameSystem_onAfterLoad.call(this);
        loadedTime = this._playtime;
        startTime = Date.now();
    };

    Game_System.prototype.playtime = function()
    {
        return Math.floor((Date.now() - startTime + loadedTime) / 1000);
    };

})();
 
Last edited:

JohnOminae

Villager
Member
Joined
Mar 13, 2012
Messages
28
Reaction score
17
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
162
Reaction score
17
First Language
Vietnam
Primarily Uses
RMMV
Does this plugin reduce lag for weak devices?
 

ChampX

Veteran
Veteran
Joined
Aug 14, 2016
Messages
187
Reaction score
120
First Language
English
Primarily Uses
@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
16
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
187
Reaction score
120
First Language
English
Primarily Uses
Updated to address bug fix regarding time not storing properly after multiple saves
 

Ace of Spades

Veteran
Veteran
Joined
Jan 19, 2017
Messages
68
Reaction score
96
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.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

i watched the sonic movie it was pretty good i hope they make a sequel
tomorrow I'ma go on a cruise for the first time ever... lets hope I'll survive the experience!
Omg! 8 years in this forum :o
Ksi
Streaming the last of the RMN Valentiny event games so feel free to drop on by and watch me cry (whether that's from laughter, rage or sheer pain, who knows?)
Today I went to sleep without setting an alarm, so I could sleep more than 2 hours. I woke up after 2 hours.

Forum statistics

Threads
94,315
Messages
919,843
Members
124,064
Latest member
kt040
Top