Is there a way to show the player’s playtime on the screen whilst they are playing? Im guessing i will need a plugin.
Show playtime on screen whilst playing
RPG Maker MZ SupportYou don't need a plugin to show it on screen, but if you want to make something elegant (such as having its own window) a plugin will indeed make it easier.
If you just want to show the playtime on screen something like this will do :
This will show the played time in the top right corner.
You can edit
If you want to include a window to it, it's a little more complicated, you would have to use Window_Base to create your own window menu
If you just want to show the playtime on screen something like this will do :
JavaScript:
(function() {
// Create a new sprite to display playtime
var createPlaytimeDisplay = function() {
var sprite = new Sprite(new Bitmap(200, 50)); //Size of the display
sprite.bitmap.fontSize = 24;
sprite.x = Graphics.width - 210; // Set 10 pixels from the right border (200 for the sprite size, 10 margin)
sprite.y = 10; // Set 10 pixels from the top
// Add sprite to the SceneManager
SceneManager._scene.addChild(sprite);
// Update the sprite (function)
sprite.update = function() {
var playtime = $gameSystem.playtime();
var hours = Math.floor(playtime / 60 / 60);
var minutes = Math.floor(playtime / 60) % 60;
var seconds = playtime % 60;
this.bitmap.clear();
this.bitmap.drawText(hours.padZero(2) + ':' + minutes.padZero(2) + ':' + seconds.padZero(2), 0, 0, 200, 50, 'right');
};
// Update playtime sprite with sprite data
SceneManager._scene._playtimeSprite = sprite;
};
// Update sprite on the map
var _Scene_Map_updateMain = Scene_Map.prototype.updateMain;
Scene_Map.prototype.updateMain = function() {
_Scene_Map_updateMain.call(this);
if (this._playtimeSprite) {
this._playtimeSprite.update();
} else {
createPlaytimeDisplay();
}
};
})();
This will show the played time in the top right corner.
You can edit
sprite.x and sprite.y to fit whatever place you want it.If you want to include a window to it, it's a little more complicated, you would have to use Window_Base to create your own window menu
Yes and no
you have direct access to the playtime by variable (it's in the game data section of control variable) and can use that to place the time into any show text.
however to constantly display that value, you'll need a HUD-type plugin because the maker has no default ways for constantly displaying anything
you have direct access to the playtime by variable (it's in the game data section of control variable) and can use that to place the time into any show text.
however to constantly display that value, you'll need a HUD-type plugin because the maker has no default ways for constantly displaying anything
You can sassign playtime to the variable in common event, and use HUD Maker to create a window that displays the playtime all the time.
How would i assign the window though once i have made it?
Honestly, I don't know.
I've been trying to extend the Window_Base class, but I keep getting error messages. ^^
Someone else will need to help for this.
Roughly based on a different plugin I wrote, for playtime on the pause menu (link to post):
(I haven't tested this, so it might need some corrections.)
[Edit: corrected
JavaScript:
/*:
* @target MZ
* @plugindesc Adds an always-on playtime window to the map scene.
* @author Caethyril
* @url https://forums.rpgmakerweb.com/threads/170629/
* @help Free to use and/or modify for any project, no credit required.
*/
void (() => {
'use strict';
// Define Window_CaePlaytime > Window_Gold.
const W = globalThis.Window_CaePlaytime = function() { this.initialize(...arguments); };
const P = W.prototype = Object.create(Window_Gold.prototype);
P.constructor = W;
// Define static properties.
/** Text format: %1 = core playtime text. */
W.FORM = "%1";
/** Text alignment. */
W.ALIGN = "center";
/** Background type: 0 = Normal, 1 = Dim, 2 = Transparent. */
W.BG_TYPE = 0;
// Define own methods.
/** Init window background type */
P.initialize = function() {
Window_Gold.prototype.initialize.apply(this, arguments);
this.setBackgroundType(this.constructor.BG_TYPE);
};
/** Redraws window contents. */
P.refresh = function() {
const rect = this.itemLineRect(0);
this.contents.clear();
this.drawText(this.value(), rect.x, rect.y, rect.width, this.constructor.ALIGN);
this._cache = $gameSystem.playtime();
};
/** Runs every mechanical frame. */
P.update = function() {
Window_Gold.prototype.update.apply(this, arguments);
if ($gameSystem.playtime() !== this._cache)
this.refresh();
};
/** Value to draw. */
P.value = function() {
return this.constructor.FORM.format($gameSystem.playtimeText());
};
// Patch - add playtime window to map scene.
const alias = Scene_Map.prototype.createAllWindows;
Scene_Map.prototype.createAllWindows = function() {
// add first => under others
this.addWindow(
this._playtimeWindow = new Window_CaePlaytime(
this.playtimeWindowRect()
)
);
alias.apply(this, arguments);
};
// New - generates bounds for playtime window.
Scene_Map.prototype.playtimeWindowRect = function() {
// Start with gold window bounds.
const r = this.goldWindowRect();
// Move to bottom-left of screen.
r.x = 0;
r.y = Graphics.boxHeight - r.height;
return r;
};
})();
[Edit: corrected
this.initialize.apply(...arguments) to this.initialize(...arguments). 😴]That is code you would put in a file as a plugin 🤣
thanks but unfortunately i got a syntax error and it didnt work 🙁
it gave me a syntax error for some reason but thanks anyway
Oops, I had a small typo that was initialising the window as a rectangle instead of...uh...a window. That caused a Type Error: "
I've corrected the code in my previous post, it seems to work for me now! 👋
(I've also attached the working plugin as a file this time, in case you got a Syntax Error due to saving the code incorrectly.)
_createAllParts is not a function".I've corrected the code in my previous post, it seems to work for me now! 👋
(I've also attached the working plugin as a file this time, in case you got a Syntax Error due to saving the code incorrectly.)
You are a genius TYSM
EDIT: How do I get rid of the window around it and just have it show the playtime?
Shh... my head was not right yesterday xD
You can simply get rid of the create window part.
I'm not going to edit caethyril's code, it's more advanced than mine. ^^
Here is my solution :
JavaScript:
(() => {
class Window_Playtime extends Window_Base {
constructor(rect) {
super(rect);
this.opacity = 255;
this.contentsOpacity = 255;
this.initializePlaytimeDisplay();
}
initializePlaytimeDisplay() {
this.sprite = new Sprite(new Bitmap(this.width, this.height));
this.sprite.bitmap.fontSize = 24;
this.addChild(this.sprite);
this.updatePlaytime();
}
updatePlaytime() {
const playtime = $gameSystem.playtime();
const hours = Math.floor(playtime / 60 / 60).padZero(2);
const minutes = Math.floor(playtime / 60 % 60).padZero(2);
const seconds = (playtime % 60).padZero(2);
this.sprite.bitmap.clear();
this.sprite.bitmap.drawText(`${hours}:${minutes}:${seconds}`, 0, 0, this.width, this.height, 'center');
}
update() {
super.update();
this.updatePlaytime();
}
}
const _Scene_Map_createAllWindows = Scene_Map.prototype.createAllWindows;
Scene_Map.prototype.createAllWindows = function () {
_Scene_Map_createAllWindows.call(this);
this.createPlaytimeWindow();
};
Scene_Map.prototype.createPlaytimeWindow = function () {
const rect = new Rectangle(Graphics.width - 220, 20, 200, 50); // Define the rectangle for the window
this._playtimeWindow = new Window_Playtime(rect); // Create the new window
this.addWindow(this._playtimeWindow); // Add the window to the scene
};
const _Scene_Map_terminate = Scene_Map.prototype.terminate;
Scene_Map.prototype.terminate = function () {
if (this._playtimeWindow) {
this.removeWindow(this._playtimeWindow); // Remove the window from the scene
this._playtimeWindow = null; // Nullify the reference
}
_Scene_Map_terminate.call(this);
};
})();
JavaScript:
() => {
class Sprite_Playtime extends Sprite {
constructor() {
const width = 200;
const height = 50;
super(new Bitmap(width, height));
this.bitmap.fontSize = 24;
this.x = Graphics.width - width - 20; // 20 pixels from the right
this.y = 20; // 20 pixels from the top
this.updatePlaytime();
}
updatePlaytime() {
const playtime = $gameSystem.playtime();
const hours = Math.floor(playtime / 60 / 60).padZero(2);
const minutes = Math.floor(playtime / 60 % 60).padZero(2);
const seconds = (playtime % 60).padZero(2);
this.bitmap.clear();
this.bitmap.drawText(`${hours}:${minutes}:${seconds}`, 0, 0, this.bitmap.width, this.bitmap.height, 'center');
}
update() {
super.update();
this.updatePlaytime();
}
}
const _Scene_Map_createAllWindows = Scene_Map.prototype.createAllWindows;
Scene_Map.prototype.createAllWindows = function () {
_Scene_Map_createAllWindows.call(this);
this.createPlaytimeSprite();
};
Scene_Map.prototype.createPlaytimeSprite = function () {
this._playtimeSprite = new Sprite_Playtime();
this.addChild(this._playtimeSprite); // Add the sprite to the scene
};
const _Scene_Map_terminate = Scene_Map.prototype.terminate;
Scene_Map.prototype.terminate = function () {
if (this._playtimeSprite) {
this.removeChild(this._playtimeSprite); // Remove the sprite from the scene
this._playtimeSprite = null; // Nullify the reference
}
_Scene_Map_terminate.call(this);
};
const _Scene_Map_update = Scene_Map.prototype.update;
Scene_Map.prototype.update = function () {
_Scene_Map_update.call(this);
if (this._playtimeSprite) {
this._playtimeSprite.update(); // Update the playtime sprite
}
};
})();
Should be a plugin so add
//================================================================
// * Plugin Name : Playtime_Display
// - Last updated : 27/07/2024
// - Curent Version : 0.1
//================================================================
/*:
* @target MZ
* @plugindesc v2 Shows current playtime in the top right corner
* @Help Allows to show current playtime in the top right corner
*/
// * Plugin Name : Playtime_Display
// - Last updated : 27/07/2024
// - Curent Version : 0.1
//================================================================
/*:
* @target MZ
* @plugindesc v2 Shows current playtime in the top right corner
* @Help Allows to show current playtime in the top right corner
*/
For my code, I think you could just edit this line:
JavaScript:
W.BG_TYPE = 0;
JavaScript:
W.BG_TYPE = 2;
Just to be clear, whether something is a plugin or not has nothing to do with whether there's a template header in the file 😉
There's certainly nothing wrong with doing that, it prevents the little incompatibility message in the plugin manager and shows a description in the list; but it's not required for it to work.
My point above was that any code which isn't a single script call you insert on the fly is, necessarily, pasted into a file and included as a plugin.
Is posible make a modification on play Time plugin to make the timer reset when all actors die in the map?
@LeashaX - you could reset the frame count when everyone dies, i.e. in a Script command:
This happens automatically on new game: it's the value used by the core
If you need an independent, "fake playtime" value, I suggest looking for a different plugin. (Technically this would be doable with a bunch of pictures, some variables, and a parallel event...but that's pushing it.) In that case, feel free to start a new thread~ 👋
Since it looks like this thread was solved 4 months ago:
JavaScript:
Graphics.frameCount = 0;
playtime method, so it will be reflected everywhere else that value is shown.If you need an independent, "fake playtime" value, I suggest looking for a different plugin. (Technically this would be doable with a bunch of pictures, some variables, and a parallel event...but that's pushing it.) In that case, feel free to start a new thread~ 👋
Since it looks like this thread was solved 4 months ago:
This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.
Original thread: https://forums.rpgmakerweb.com/threads/show-playtime-on-screen-whilst-playing.170629/