Lucemodok 24 Report post Posted February 5 (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 by Lucemodok 5 1 1 Share this post Link to post Share on other sites
Combustiblemon 44 Report post Posted February 7 Great. Can we use even Wingdings or foreign language fonts? Share this post Link to post Share on other sites
Lucemodok 24 Report post Posted February 7 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 Share this post Link to post Share on other sites
Cunning fox 706 Report post Posted February 27 (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 by Cunning fox 1 Share this post Link to post Share on other sites
TheSkylarr 18 Report post Posted February 27 What exactly does resolvefilepath() do? I've seen it thrown around, along with softresolvefilepath(), and I'm clueless. Share this post Link to post Share on other sites
Cunning fox 706 Report post Posted February 27 (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 by Cunning fox Share this post Link to post Share on other sites
Garamonde 38 Report post Posted March 5 (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 by Garamonde Inserted a few missing words. Share this post Link to post Share on other sites
Cunning fox 706 Report post Posted March 5 (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 by Cunning fox 1 1 Share this post Link to post Share on other sites