MV plugin for changing message font constantly like undertale?

as the title says! i'm looking for a plugin that'd change the game font constantly, whether it changes a certain word or changes the entire sentence in each message box,, like undertale when the message font constantly switches up when you talk to sans or papyrus..

just in case i might not be clear, this is what i mean! (images below)

if there's any tutorials or plugins for this,, let me know and thanks in advance..
I figured out how to do this at one point… but it’s a bit of an involved process. However, if you do exactly as I did, you can use escape codes to change the font from inside show text commands (so you can change the font of the whole message or just one word of it, up to you!)

As always, you should make a backup of your project before doing anything complex or weird to the game. This is both complex AND weird, as far as the things I’ve done go. Make a backup.

If you’re ready to put a terribly frustrating amount of work into making the font as flexible as you want it to be, here is how I did it:




Step one: secure your .ttf file

To start, of course, you’ll download the fonts you want to use. These come in the form of a .ttf file. I got mine from Google Fonts.
While you’re there, make sure you copy the embed link. It will look something like this:
HTML:
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>

In the font folder you downloaded, you’ll see a folder called “static”. You’ll need to use the .ttf files from the static folder, as variable fonts don’t seem to work in RPG Maker, as far as my efforts went.

Select one of the .ttf files from the static folder and copy/paste it into your project’s font folder.




Step 2: Create a .css file

Open a text document (I use Notepad) and paste this into it:

CSS:
@font-face {
  font-family: "CustomFont";
  src: url("CustomFontFileName.ttf");
}

You’ll need to edit two things:
1 - CustomFont
Replace this with the name of the font family. You choose the name yourself, just keep in mind that this will be what you type into the escape code in show text commands to call on your custom font, so make it something you will remember. (Also, if you don’t already know, avoid using any spaces or special symbols in your file names. You can use dashes, underscores, and capitalization to make it easier for you to read)
2 - CustomFontFileName
Replace this with the EXACT file name of the ttf file you added to your font folder.

Important: keep the quotation marks in this script! It won’t work if you remove them.

For example, I was using Winky Rough font. I named the family name WinkyRough and the actual text file I took from the static folder was WinkyRough-Black.ttf
So, my .css file looked like this:

CSS:
@font-face {
  font-family: "WinkyRough";
  src: url("WinkyRough-Black.ttf");
}

If you’re using more than one custom font, you can add them all to the same file, one after another, using the format we have here and replacing the font family and file name for each new font.

Once you’ve added all your fonts, save this file as customfonts.css and add it to the fonts folder in your project.
Note: You can name the file whatever you want, but for the purposes of this example, I will be using customfonts as the file name. If you change the file name, make sure to replace “customfonts” with your own file name in the steps below, as well! No matter what you name it, it must end with .css



Step 3: Add your embedded link

In your project folder, you will see an html file called “index”. Open this file in any text editor (such as Notepad).

At the bottom of the head (the top paragraph between <head> and </head>) start a new line ABOVE </head> and paste the embed link you copied from Google Fonts there.
If you’re using more than one font, add all of the embedded links here.

While we’re editing index.html, we will also prepare the engine to read the .css file we created in the last step.

In the head (same section as before), you will see this line:

HTML:
<link rel="stylesheet" type="text/css" href="fonts/gamefont.css">

Directly below that line, add this:

HTML:
<link rel="stylesheet" type="text/css" href="fonts/customfonts.css">

(Remember: if you decided not to use customfonts as the .css file name, you MUST replace it with the file name you decided to use!)

Save it.

The hard part is done!



Final step: Add my lazily contrived plugin to your project

Copy/paste this code into a text editor (Notepad) and save it as a .js file

JavaScript:
/*:
 * @plugindesc Change fonts mid-message
 *
 * @help
 * Use the escape code \font[FontName] in Show Text commands.
 * - Font will remain active until changed again or reset.
 */

(function() {
  const alias_processEscapeCharacter = Window_Message.prototype.processEscapeCharacter;

  Window_Message.prototype.processEscapeCharacter = function(code, textState) {
    if (code === 'FONT') {
      const fontName = this.obtainEscapeParam(textState);
      if (fontName) {
        this.contents.fontFace = fontName;
      }
      return;
    }
    alias_processEscapeCharacter.call(this, code, textState);
  };

  Window_Base.prototype.obtainEscapeParam = function(textState) {
    const regExp = /^\[([^\]]+)\]/;
    const arr = regExp.exec(textState.text.slice(textState.index));
    if (arr) {
      textState.index += arr[0].length;
      return arr[1];
    } else {
      return '';
    }
  };
})();

You can name it anything you want, I named it CustomFonts.js
Place that file into your project’s plugin folder.
Add the plugin to your game via the editor.




Now you are ready.

To change the font of your text, use this escape code in the show text command:

Code:
\font[CustomFont]

Replace CustomFont with whatever you named the font family in your .css file.

Ex:
Code:
\font[WinkyRough]


This will change the font permanently– that is to say, all following text will display in this font until you use another escape code to change it back to normal.

To return to the standard game font, you will use this escape code exactly:

Code:
\font[GameFont]

So, as an example/test you could do a show text command like this:

Code:
This text is the standard font.
\font[CustomFont] This text appears in your custom font!
\font[GameFont] The text is standard font again!


So this is my overly complicated way of replicating Undertale's ability to swap fonts at will! I hope it helps!
I know that in my project, I was using a lot of Yanfly's plugins, including Message Core, so it should be compatible with them. If you're using Message Core or any other plugins that alter the behavior of text/show message commands, place my plugin BELOW them.
(By the way: this bad attempt at a plugin is free to use in any game, commercial or otherwise, I do not require credit for it, I don't care if you modify it or redistribute it, do what you want)
if its randomized, it needs to go differently.

I do have a loadFont function in my base, so it only need to draw
a randomized font during typing on some points or check per word
and automatic change the font.

if that is something you seek, the above code wont work,
with YEP_MessageCore and YEP_LoadCustomFonts, you only
need a randomize font that change words instead of manually inputting
so whenever you talk to the same person, it always randomize fonts
of the words.
I figured out how to do this at one point… but it’s a bit of an involved process. However, if you do exactly as I did, you can use escape codes to change the font from inside show text commands (so you can change the font of the whole message or just one word of it, up to you!)

As always, you should make a backup of your project before doing anything complex or weird to the game. This is both complex AND weird, as far as the things I’ve done go. Make a backup.

If you’re ready to put a terribly frustrating amount of work into making the font as flexible as you want it to be, here is how I did it:




Step one: secure your .ttf file

To start, of course, you’ll download the fonts you want to use. These come in the form of a .ttf file. I got mine from Google Fonts.
While you’re there, make sure you copy the embed link. It will look something like this:
HTML:
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>

In the font folder you downloaded, you’ll see a folder called “static”. You’ll need to use the .ttf files from the static folder, as variable fonts don’t seem to work in RPG Maker, as far as my efforts went.

Select one of the .ttf files from the static folder and copy/paste it into your project’s font folder.




Step 2: Create a .css file

Open a text document (I use Notepad) and paste this into it:

CSS:
@font-face {
  font-family: "CustomFont";
  src: url("CustomFontFileName.ttf");
}

You’ll need to edit two things:
1 - CustomFont
Replace this with the name of the font family. You choose the name yourself, just keep in mind that this will be what you type into the escape code in show text commands to call on your custom font, so make it something you will remember. (Also, if you don’t already know, avoid using any spaces or special symbols in your file names. You can use dashes, underscores, and capitalization to make it easier for you to read)
2 - CustomFontFileName
Replace this with the EXACT file name of the ttf file you added to your font folder.

Important: keep the quotation marks in this script! It won’t work if you remove them.

For example, I was using Winky Rough font. I named the family name WinkyRough and the actual text file I took from the static folder was WinkyRough-Black.ttf
So, my .css file looked like this:

CSS:
@font-face {
  font-family: "WinkyRough";
  src: url("WinkyRough-Black.ttf");
}

If you’re using more than one custom font, you can add them all to the same file, one after another, using the format we have here and replacing the font family and file name for each new font.

Once you’ve added all your fonts, save this file as customfonts.css and add it to the fonts folder in your project.
Note: You can name the file whatever you want, but for the purposes of this example, I will be using customfonts as the file name. If you change the file name, make sure to replace “customfonts” with your own file name in the steps below, as well! No matter what you name it, it must end with .css



Step 3: Add your embedded link

In your project folder, you will see an html file called “index”. Open this file in any text editor (such as Notepad).

At the bottom of the head (the top paragraph between <head> and </head>) start a new line ABOVE </head> and paste the embed link you copied from Google Fonts there.
If you’re using more than one font, add all of the embedded links here.

While we’re editing index.html, we will also prepare the engine to read the .css file we created in the last step.

In the head (same section as before), you will see this line:

HTML:
<link rel="stylesheet" type="text/css" href="fonts/gamefont.css">

Directly below that line, add this:

HTML:
<link rel="stylesheet" type="text/css" href="fonts/customfonts.css">

(Remember: if you decided not to use customfonts as the .css file name, you MUST replace it with the file name you decided to use!)

Save it.

The hard part is done!



Final step: Add my lazily contrived plugin to your project

Copy/paste this code into a text editor (Notepad) and save it as a .js file

JavaScript:
/*:
 * @plugindesc Change fonts mid-message
 *
 * @help
 * Use the escape code \font[FontName] in Show Text commands.
 * - Font will remain active until changed again or reset.
 */

(function() {
  const alias_processEscapeCharacter = Window_Message.prototype.processEscapeCharacter;

  Window_Message.prototype.processEscapeCharacter = function(code, textState) {
    if (code === 'FONT') {
      const fontName = this.obtainEscapeParam(textState);
      if (fontName) {
        this.contents.fontFace = fontName;
      }
      return;
    }
    alias_processEscapeCharacter.call(this, code, textState);
  };

  Window_Base.prototype.obtainEscapeParam = function(textState) {
    const regExp = /^\[([^\]]+)\]/;
    const arr = regExp.exec(textState.text.slice(textState.index));
    if (arr) {
      textState.index += arr[0].length;
      return arr[1];
    } else {
      return '';
    }
  };
})();

You can name it anything you want, I named it CustomFonts.js
Place that file into your project’s plugin folder.
Add the plugin to your game via the editor.




Now you are ready.

To change the font of your text, use this escape code in the show text command:

Code:
\font[CustomFont]

Replace CustomFont with whatever you named the font family in your .css file.

Ex:
Code:
\font[WinkyRough]


This will change the font permanently– that is to say, all following text will display in this font until you use another escape code to change it back to normal.

To return to the standard game font, you will use this escape code exactly:

Code:
\font[GameFont]

So, as an example/test you could do a show text command like this:

Code:
This text is the standard font.
\font[CustomFont] This text appears in your custom font!
\font[GameFont] The text is standard font again!


So this is my overly complicated way of replicating Undertale's ability to swap fonts at will! I hope it helps!
I know that in my project, I was using a lot of Yanfly's plugins, including Message Core, so it should be compatible with them. If you're using Message Core or any other plugins that alter the behavior of text/show message commands, place my plugin BELOW them.
(By the way: this bad attempt at a plugin is free to use in any game, commercial or otherwise, I do not require credit for it, I don't care if you modify it or redistribute it, do what you want)
oh my god youre a LIFE SAVER!! this took me so long but i'm so glad it worked in the end! thank you for your time!!
oh my god youre a LIFE SAVER!! this took me so long but i'm so glad it worked in the end! thank you for your time!!
I'm glad it worked for your project! May your creativity flourish!

Original thread: https://forums.rpgmakerweb.com/threads/plugin-for-changing-message-font-constantly-like-undertale.179044/