Lucemodok Posted February 5, 2021 Share Posted February 5, 2021 (edited) Hello, I'm Lucemodok and today I learned from @zarklord_klei how to load fonts into DST. So, first you need to download your font, any font will do as long as you can read it. Second, you'll need BMFont, it's a way to convert font files to bitmap fonts, which is what DST uses. You'll then need to open BMFont and open the font settings to select a font. After that, you need to set your font configurations, this is what I used. Next, open the export options and use this configuration. This makes your font work with DST and have an outline. After that, select save bitmap font as... and save it as "font.fnt" in whatever folder you want, a png with the name "font_0.png" should also appear there. Convert the png into a tex with any tex conversion tool you have, rename it "font.tex" and zip it along with the fnt into "talkingfont_yourcharacter.zip" for the game to be able to read it. Create a fonts folder in your mod folder, and put the new zip into the folder. Here comes the coding part. -- modmain.lua Assets = { Asset("FONT", "fonts/talkingfont_yourcharacter.zip"), } GLOBAL.TALKINGFONT_YOURCHARACTER = "talkingfont_yourcharacter" AddSimPostInit(function() GLOBAL.TheSim:LoadFont(GLOBAL.resolvefilepath("fonts/talkingfont_yourcharacter.zip"), GLOBAL.TALKINGFONT_YOURCHARACTER) end) Put that in the bottom of your modmain.lua and put the following in your character's common_postinit function. inst.components.talker.font = TALKINGFONT_YOURCHARACTER You should be done with your fonts, now you should test for any crashes. Enjoy! Edited February 5, 2021 by Lucemodok 5 1 1 1 Link to comment Share on other sites More sharing options...
Combustiblemon Posted February 7, 2021 Share Posted February 7, 2021 Great. Can we use even Wingdings or foreign language fonts? Link to comment Share on other sites More sharing options...
Lucemodok Posted February 7, 2021 Author Share Posted February 7, 2021 3 hours ago, Combustiblemon said: Great. Can we use even Wingdings or foreign language fonts? Yes, any font will work. But I suggest readable ones Link to comment Share on other sites More sharing options...
Cunning fox Posted February 27, 2021 Share Posted February 27, 2021 (edited) The loading solution will crash if you leave the server/reload the current game, because the font needs to be loaded before mod assets are loaded My solution: local env = env _G.setfenv(1, _G) TALKINGFONT_WAYNE = "talkingfont_wayne" env.AddSimPostInit(function() TheSim:UnloadFont(TALKINGFONT_WAYNE) TheSim:UnloadPrefabs({"wayne_fonts"}) local Assets = { Asset("FONT", resolvefilepath("fonts/talkingfont_wayne.zip")), } local FontsPrefab = Prefab("wayne_fonts", function() return CreateEntity() end, Assets) RegisterPrefabs(FontsPrefab) TheSim:LoadPrefabs({"wayne_fonts"}) TheSim:LoadFont(resolvefilepath("fonts/talkingfont_wayne.zip"), TALKINGFONT_WAYNE) end) It's pretty hacky, so maybe there's other way to resolve reload crash? I've tried to add loading/unloading new font to global functions LoadFonts/UnloadFonts (see mainfunctions.lua), but then the font never even gets loaded. Maybe @zarklord_klei knows a better way of doing it? Edited February 27, 2021 by Cunning fox 2 Link to comment Share on other sites More sharing options...
Wonderlarr Posted February 27, 2021 Share Posted February 27, 2021 What exactly does resolvefilepath() do? I've seen it thrown around, along with softresolvefilepath(), and I'm clueless. Link to comment Share on other sites More sharing options...
Cunning fox Posted February 27, 2021 Share Posted February 27, 2021 (edited) 2 minutes ago, TheSkylarr said: What exactly does resolvefilepath() do? I've seen it thrown around, along with softresolvefilepath(), and I'm clueless. Resolves relative file path into absolute path This is used if you add asset that is not from the game, so you need to tell the engine where it is stored Example: resolvefilepath("anim/poop.zip") will return "../../mods/workshop-00000/anim/poop.zip" Edited February 27, 2021 by Cunning fox Link to comment Share on other sites More sharing options...
Garamonde Posted March 5, 2021 Share Posted March 5, 2021 (edited) Yes, I used this font code and my mod crashes the game upon world regen, which is a big problem because me and a friend I play with regenerate our worlds all the time. I reeeally hope someone comes up with a cleaner solution! Also, inserting that "hacky" code (and changing all the names to my character of course) gained this crash upon trying to create a new world: @Cunning fox Edited March 5, 2021 by Garamonde Inserted a few missing words. Link to comment Share on other sites More sharing options...
Cunning fox Posted March 5, 2021 Share Posted March 5, 2021 (edited) 7 hours ago, Garamonde said: Yes, I used this font code and my mod crashes the game upon world regen, which is a big problem because me and a friend I play with regenerate our worlds all the time. I reeeally hope someone comes up with a cleaner solution! Also, inserting that "hacky" code (and changing all the names to my character of course) gained this crash upon trying to create a new world: @Cunning fox Add _G = GLOBAL 7 hours ago, Garamonde said: Yes, I used this font code and my mod crashes the game upon world regen, which is a big problem because me and a friend I play with regenerate our worlds all the time. I reeeally hope someone comes up with a cleaner solution! Also, inserting that "hacky" code (and changing all the names to my character of course) gained this crash upon trying to create a new world: @Cunning fox The code I used changes mods's env to a global one, so you shouldn't use it if you're not experienced enough. Solution without changing env is: local _G = GLOBAL local TheSim = _G.TheSim _G.TALKINGFONT_WAYNE = "talkingfont_wayne" AddSimPostInit(function() TheSim:UnloadFont(_G.TALKINGFONT_WAYNE) TheSim:UnloadPrefabs({"wayne_fonts"}) local Assets = { Asset("FONT", _G.resolvefilepath("fonts/talkingfont_wayne.zip")), } local FontsPrefab = _G.Prefab("wayne_fonts", function() return _G.CreateEntity() end, Assets) _G.RegisterPrefabs(FontsPrefab) TheSim:LoadPrefabs({"wayne_fonts"}) TheSim:LoadFont(_G.resolvefilepath("fonts/talkingfont_wayne.zip"), _G.TALKINGFONT_WAYNE) end) Edited March 5, 2021 by Cunning fox 1 1 Link to comment Share on other sites More sharing options...
icantevenname Posted July 10, 2021 Share Posted July 10, 2021 (edited) On 3/5/2021 at 3:56 AM, Cunning fox said: Add _G = GLOBAL The code I used changes mods's env to a global one, so you shouldn't use it if you're not experienced enough. Solution without changing env is: local _G = GLOBAL local TheSim = _G.TheSim _G.TALKINGFONT_WAYNE = "talkingfont_wayne" AddSimPostInit(function() TheSim:UnloadFont(_G.TALKINGFONT_WAYNE) TheSim:UnloadPrefabs({"wayne_fonts"}) local Assets = { Asset("FONT", _G.resolvefilepath("fonts/talkingfont_wayne.zip")), } local FontsPrefab = _G.Prefab("wayne_fonts", function() return _G.CreateEntity() end, Assets) _G.RegisterPrefabs(FontsPrefab) TheSim:LoadPrefabs({"wayne_fonts"}) TheSim:LoadFont(_G.resolvefilepath("fonts/talkingfont_wayne.zip"), _G.TALKINGFONT_WAYNE) end) Is there a certain place it's supposed to go? I tried this and it crashed when going into a cave. Looked into it, the log says that "AddSimPostInit" isn't declared. Edited July 12, 2021 by icantevenname Link to comment Share on other sites More sharing options...
iiChriSii Posted August 5, 2021 Share Posted August 5, 2021 (edited) I open the font BMFont and my languague symbols (á à ả ã ạ....) disappeared. is that okay? Edited August 5, 2021 by iiChriSii Link to comment Share on other sites More sharing options...
iiChriSii Posted August 5, 2021 Share Posted August 5, 2021 4 hours ago, iiChriSii said: I open the font BMFont and my languague symbols (á à ả ã ạ....) disappeared. is that okay? I figured out . Link to comment Share on other sites More sharing options...
dinhkarate Posted January 23, 2022 Share Posted January 23, 2022 I've tried it but it just have a font.fnt in the folder but the png isn't appear there. Btw the link in the post is die Link to comment Share on other sites More sharing options...
Jokey boi Posted August 10, 2022 Share Posted August 10, 2022 On 1/23/2022 at 5:35 AM, dinhkarate said: I've tried it but it just have a font.fnt in the folder but the png isn't appear there. Btw the link in the post is die yeah the app is broken you can use hiero tho. if you have any problems understanding you can follow this tutorial Link to comment Share on other sites More sharing options...
-Variant Posted October 31, 2023 Share Posted October 31, 2023 Necro of a life time. There's another way to get to BMFont, here: https://www.angelcode.com/products/bmfont/ Hopefully this helps any lost souls trying to add fonts in the future. Link to comment Share on other sites More sharing options...
RexySeven Posted November 4, 2023 Share Posted November 4, 2023 On 10/31/2023 at 7:23 AM, -Variant said: Necro of a life time. There's another way to get to BMFont, here: https://www.angelcode.com/products/bmfont/ Hopefully this helps any lost souls trying to add fonts in the future. There's still no png when I'm saving bitmap as fnt Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now