Jump to content

Issues with Books Tab


Recommended Posts

I've made a mod that makes books usable and craftable by any character, but I can't seem to make the Book Tab appear for anybody.

It's also removed the Book Tab from Wickerbottom's HUD

 

I've tried to work around it by adding all the crafting options for books into the Magic Tab, but would really appreciate some help working this out.

local Ingredient = GLOBAL.Ingredientlocal RecipeTabs = GLOBAL.RECIPETABSlocal Tech = GLOBAL.TECH--Adds the flags required to read books and use the books tablocal function bookSmart(inst)	inst:AddTag("bookbuilder") --doesn't allow use of Books Tab for some reason?	inst:AddComponent("reader") end--Runs bookSmart for every character present in server filesfor k,prefabname in ipairs(GLOBAL.DST_CHARACTERLIST) do	AddPrefabPostInit(prefabname, bookSmart)endfor k,prefabname in ipairs(GLOBAL.MODCHARACTERLIST) do	AddPrefabPostInit(prefabname, bookSmart)end--Adds all the book recipes to the Magic TabAddRecipe("book_birds", {Ingredient("papyrus", 2), Ingredient("bird_egg", 2)}, RecipeTabs.MAGIC, Tech.MAGIC_THREE)AddRecipe("book_gardening", {Ingredient("papyrus", 2), Ingredient("seeds", 1), Ingredient("poop", 1)}, RecipeTabs.MAGIC, Tech.MAGIC_THREE)AddRecipe("book_sleep", {Ingredient("papyrus", 2), Ingredient("nightmarefuel", 2)}, RecipeTabs.MAGIC, Tech.MAGIC_THREE)AddRecipe("book_brimstone", {Ingredient("papyrus", 2), Ingredient("redgem", 1)}, RecipeTabs.MAGIC, Tech.MAGIC_THREE)AddRecipe("book_tentacles", {Ingredient("papyrus", 2), Ingredient("tentaclespots", 1)}, RecipeTabs.MAGIC, Tech.MAGIC_THREE)
Link to comment
Share on other sites

local function bookSmart(inst)	inst:AddTag("bookbuilder")	if GLOBAL.TheWorld.ismastersim then		inst:AddComponent("reader")	endendAddPlayerPostInit(bookSmart)

And put your mod as all_clients_require_mod = true

So they download it and run it the post init themselves.

 

Probably has to do with something nitpicky regarding tags and pristine state or whatever during the construction of the crafting tabs. If the mod is server only, then the tag doesn't propagate fast enough, before the construction of the client crafting tabs. And because those aren't generated again and again, like recipes, then when the tag updates, the crafting tab list won't.

 

If you use AddPrefabPostInit for everybody in CHARACTERLIST and MOD_CHARACTERLIST remember to put a low priority so your mod runs last and every character gets the chance to be postinited.

Edited by DarkXero
Link to comment
Share on other sites

Yeah I was using a low priority to make sure it worked with all the modded characters.

 

I already had it as a client run mod though, so why would it not execute before the tabs are built?
This is all just for my understanding more than anything.

 

Thanks for helping!

Link to comment
Share on other sites

I thought you were using the mod as server only.

 

With all_clients_require_mod = true, your code

--Adds the flags required to read books and use the books tablocal function bookSmart(inst)    inst:AddTag("bookbuilder") --doesn't allow use of Books Tab for some reason?    inst:AddComponent("reader") end --Runs bookSmart for every character present in server filesfor k,prefabname in ipairs(GLOBAL.DST_CHARACTERLIST) do    AddPrefabPostInit(prefabname, bookSmart)end for k,prefabname in ipairs(GLOBAL.MODCHARACTERLIST) do    AddPrefabPostInit(prefabname, bookSmart)end

runs fine for me.

 

And what does the ismastersim do exactly?

 

TheWorld.ismastersim returns true if the simulation the runs the code is the server one.

What this means is that client side, nobody would get a reader component.

Because they don't need one.

 

It wouldn't crash the game to add it though.

 

A crash would be generated, by say,

inst.components.sanity.hello

since inst.components.sanity is nil for clients, indexing a nil value crashes the game. Components exist mainly in the server, clients get stubs (as replicas, or net_variables in prefabs attached to entities like player_classified).

 

I already had it as a client run mod though, so why would it not execute before the tabs are built?

 

If you are certain of this then there's something amiss, as your code runs fine for me.

 

Did you start the game with Wilson or a character mod from a different mod?

Maybe that other mod had lower priority than yours.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...