Jump to content

Unable to add custom recipe tab


Recommended Posts

Welp, time for the last mod i'll be porting.....It has a hiccup. The game doesn't seem fond of the old code i've used to give my Tiny Tina mod her custom recipe tab Ordinance. It's her character perk, she needs it.

 

so far it uses this code, directly in the tina prefab itself

    STRINGS.TABS.Ordinance = "Ordinance"	local ordinancetab = {str = "Ordinance", sort=999, icon = "ordinance.tex", icon_atlas = "images/hud/ordinance.xml"}	inst.components.builder:AddRecipeTab(ordinancetab)		local bunnybomb = Ingredient( "bunnybomb", 1)	bunnybomb.atlas = "images/inventoryimages/bunnybomb.xml"	local s01Recipe = Recipe("gunpowder", {Ingredient("rottenegg", 1), Ingredient("charcoal", 1), Ingredient("nitre", 1)}, ordinancetab, {SCIENCE = 2})		local s02Recipe = Recipe("bunnybomb", {Ingredient("rabbit", 1), Ingredient("rope", 1), Ingredient("nitre", 2)}, ordinancetab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})	s02Recipe.atlas = "images/inventoryimages/bunnybomb.xml"		local s03Recipe = Recipe("stickybomb", {Ingredient("flint", 6), Ingredient("gunpowder", 1), Ingredient("boards", 1)}, ordinancetab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})	s03Recipe.atlas = "images/inventoryimages/stickybomb.xml"		local s04Recipe = Recipe("george", {Ingredient("gears", 1), Ingredient("gunpowder", 1)}, ordinancetab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})	s04Recipe.atlas = "images/inventoryimages/george.xml"		local s05Recipe = Recipe("snailbomb", {Ingredient("slurtle_shellpieces", 4), Ingredient("slurtleslime", 2)}, ordinancetab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})	s05Recipe.atlas = "images/inventoryimages/snailbomb.xml"		local s06Recipe = Recipe("badonkadonk", {bunnybomb, Ingredient("manrabbit_tail", 1), Ingredient("gunpowder", 2)}, ordinancetab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})	s06Recipe.atlas = "images/inventoryimages/badonkadonk.xml"	local s07Recipe = Recipe("grenadeegg", {Ingredient("bird_egg", 1), Ingredient("gunpowder", 1)}, ordinancetab, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})	s07Recipe.atlas = "images/inventoryimages/grenadeegg.xml"	end

 

Now that's some code I partially copied from Wickerbottom, but seeing now, Wickerbottom doesn't use that kind of code anymore...

 

What can I do to fix this? I need to get her custom tab in, and is it possible to only make players playing as her have access to the tab? I can't exactly program her bombs to only be usable by her, since they're mostly activated by being lit by fire (as well ghost players can haunt them to detonate them)

Link to comment
Share on other sites

@1337gamer15@RedMattis, Recipes definitely have to be handled pretty differently now. I found that most of the really weird bugs with DST RoG Characters was due to having Recipe(...) calls in the character prefabs.

 

I looked at how Wickerbottom handles it, and it looks like now the book recipes are declared in the global recipe table, but Wickerbottom has a "bookbuilder" tag that causes it to show up. If you use the same approach, then add something like this to the modmain, that might work:

AddClassPostConstruct("widgets/crafttabs", function(self)    if self.owner:HasTag("bombbuilder") then        --Not sure exactly what to do here, I've been looking at crafttabs.lua and it's... pretty complicated    endend)

But this definitely looks like one mod support feature that got broken in the rewrite and will need to be fixed by Peter at some point.

 

An easier way to do it that would be incompatible with any other mods that do the same thing would be to provide a replacement for crafttabs.lua, which adds something close to this just below the bookbuilder part:

    if owner:HasTag("bombbuilder") then        table.insert(tabnames, CUSTOM_RECIPETABS.BOMBS)    end
Link to comment
Share on other sites

@rezecib I keep getting

[string "../mods/tinatogether/modmain.lua"]:336: attempt to index global 'CUSTOM_RECIPETABS' (a nil value)

seems the game doesn't know i'm declaring the custom recipe tab.... want me to just send her files so you can have a closer look? I'm kinda unsure as to where exactly to put these codes, but everything i've worked with is in either the modmain.lua or tina.lua in prefabs

 

grab her here so you can check the code https://www.mediafire.com/?7g049636p9vgst2

Link to comment
Share on other sites

@1337gamer15, Which approach are you using? I would recommend using the less compatible approach for now, because that will be much easier to get working, and the current difficult situation should be temporary.

 

But the fix for your error is obviously to prepend CUSTOM_RECIPETABS with GLOBAL. (GLOBAL.CUSTOMRECIPETABS). Almost all of the time, that's the fix for "attempt to index global ____" (the rest of the time, it's because you made a typo in the variable name or something).

Link to comment
Share on other sites

Tried the less compatible approach, the recipes are placed in tina's prefab

   STRINGS.TABS.ORDINANCE = "Ordinance"	local ordinance = {str = "Ordinance", sort=999, icon = "ordinance.tex", icon_atlas = "images/hud/ordinance.xml"}	--inst.components.builder:AddRecipeTab(GLOBAL.CUSTOM_RECIPETABS.ORDINANCE)		local bunnybomb = Ingredient( "bunnybomb", 1)	bunnybomb.atlas = "images/inventoryimages/bunnybomb.xml"		local s01Recipe = Recipe("bunnybomb", {Ingredient("rabbit", 1), Ingredient("rope", 1), Ingredient("nitre", 2)}, CUSTOM_RECIPETABS.ORDINANCE, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})	s01Recipe.atlas = "images/inventoryimages/bunnybomb.xml"		local s02Recipe = Recipe("stickybomb", {Ingredient("flint", 6), Ingredient("gunpowder", 1), Ingredient("boards", 1)}, CUSTOM_RECIPETABS.ORDINANCE, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})	s02Recipe.atlas = "images/inventoryimages/stickybomb.xml"		local s03Recipe = Recipe("george", {Ingredient("gears", 1), Ingredient("gunpowder", 1)}, CUSTOM_RECIPETABS.ORDINANCE, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})	s03Recipe.atlas = "images/inventoryimages/george.xml"		local s04Recipe = Recipe("snailbomb", {Ingredient("slurtle_shellpieces", 4), Ingredient("slurtleslime", 2)}, CUSTOM_RECIPETABS.ORDINANCE, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})	s04Recipe.atlas = "images/inventoryimages/snailbomb.xml"		local s05Recipe = Recipe("badonkadonk", {bunnybomb, Ingredient("manrabbit_tail", 1), Ingredient("gunpowder", 2)}, CUSTOM_RECIPETABS.ORDINANCE, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})	s05Recipe.atlas = "images/inventoryimages/badonkadonk.xml"	local s06Recipe = Recipe("grenadeegg", {Ingredient("bird_egg", 1), Ingredient("gunpowder", 1)}, CUSTOM_RECIPETABS.ORDINANCE, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})	s06Recipe.atlas = "images/inventoryimages/grenadeegg.xml"    inst:AddTag("bombzerker")

and in the crafttabs under widgets I added

if owner:HasTag("bombzerker") then    table.insert(tabnames, GLOBAL.CUSTOM_RECIPETABS.ORDINANCE)end

it gives me this

[string "scripts/components/builder_replica.lua"]:143: attempt to index field '?' (a nil value)
Link to comment
Share on other sites

@1337gamer15, You have to place the recipes in the modmain, because if recipes are in Tina's prefab, then the recipe list will change when she gets spawned, causing client and host recipe lists to go out of sync, which causes a lot of weird bugs with player_classified.

 

Are you adding ORDINANCE to GLOBAL.CUSTOM_RECIPETABS first? This is how it's defined in constants.lua now:

CUSTOM_RECIPETABS ={    BOOKS = { str = "BOOKS", sort = 999, icon = "tab_book.tex" },}
Link to comment
Share on other sites

did this in the modmain

GLOBAL.CUSTOM_RECIPETABS ={    ORDINANCE = { str = "ORDINANCE", sort = 999, icon = "ordinance.tex", icon_atlas = "images/hud/ordinance.xml" },}    STRINGS.TABS.ORDINANCE = "Ordinance"AddClassPostConstruct("widgets/crafttabs", function(self)    if self.owner:HasTag("bombzerker") then	    table.insert(tabnames, GLOBAL.CUSTOM_RECIPETABS.ORDINANCE)        --Not sure exactly what to do here, I've been looking at crafttabs.lua and it's... pretty complicated   endend)   	--local ordinancetab = {str = "Ordinance", sort=999, icon = "ordinance.tex", icon_atlas = "images/hud/ordinance.xml"}	--inst.components.builder:AddRecipeTab(GLOBAL.CUSTOM_RECIPETABS.ORDINANCE)		local bunnybomb = Ingredient( "bunnybomb", 1)	bunnybomb.atlas = "images/inventoryimages/bunnybomb.xml"		local s01Recipe = Recipe("bunnybomb", {Ingredient("rabbit", 1), Ingredient("rope", 1), Ingredient("nitre", 2)}, GLOBAL.CUSTOM_RECIPETABS.ORDINANCE, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})	s01Recipe.atlas = "images/inventoryimages/bunnybomb.xml"		local s02Recipe = Recipe("stickybomb", {Ingredient("flint", 6), Ingredient("gunpowder", 1), Ingredient("boards", 1)}, GLOBAL.CUSTOM_RECIPETABS.ORDINANCE, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})	s02Recipe.atlas = "images/inventoryimages/stickybomb.xml"		local s03Recipe = Recipe("george", {Ingredient("gears", 1), Ingredient("gunpowder", 1)}, GLOBAL.CUSTOM_RECIPETABS.ORDINANCE, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})	s03Recipe.atlas = "images/inventoryimages/george.xml"		local s04Recipe = Recipe("snailbomb", {Ingredient("slurtle_shellpieces", 4), Ingredient("slurtleslime", 2)}, GLOBAL.CUSTOM_RECIPETABS.ORDINANCE, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})	s04Recipe.atlas = "images/inventoryimages/snailbomb.xml"		local s05Recipe = Recipe("badonkadonk", {bunnybomb, Ingredient("manrabbit_tail", 1), Ingredient("gunpowder", 2)}, GLOBAL.CUSTOM_RECIPETABS.ORDINANCE, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})	s05Recipe.atlas = "images/inventoryimages/badonkadonk.xml"	local s06Recipe = Recipe("grenadeegg", {Ingredient("bird_egg", 1), Ingredient("gunpowder", 1)}, GLOBAL.CUSTOM_RECIPETABS.ORDINANCE, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0})	s06Recipe.atlas = "images/inventoryimages/grenadeegg.xml"

i've made sure tina has the bombzerker tag

 

now it gives me this

SpawnSaveRecord [nil, RandomTreeAndLeif] FAILED	error calling simpostinit in mod tinatogether (Tiny Tina): [string "scripts/mods.lua"]:105: attempt to call upvalue 'fn' (a table value)

is the simpostinit something i need to change? what to I change it to?

Edited by 1337gamer15
Link to comment
Share on other sites

@1337gamer15, Well, first, you're replacing CUSTOM_RECIPETABS there, which is not what you want to do (it will break Wickerbottom). Instead, do this:

GLOBAL.CUSTOM_RECIPETABS.ORDINANCE = { str = "ORDINANCE", sort = 999, icon = "ordinance.tex", icon_atlas = "images/hud/ordinance.xml" }

Also, the part after that isn't going to work. You saw the comment I put in it? That's saying it's not enough. By the time crafttabs has finished constructing, tabnames has already finished being used. So inserting the tab name at that point isn't going to do anything. Which is why I suggested the alternate approach of replacing crafttabs, and inserting that just after the corresponding book tab is inserted.

 

but... ugh, this is getting really frustrating.

Link to comment
Share on other sites

nope, not working, nothing's working..... I can't seem to get replacing the crafttabs to work either since the game seems to load the modmain before loading the modded crafttabs, so if i don't state the recipetab first, the game won't know what to do with the recipes in the modmain.,- I dunno, I don't even know how this works either... Tina seemed to work fine when I disabled her crafting tab, as well as her bombs (except the grenade egg), so I think I might just wait for Klei to be done with their holiday and ask Peter about a mod like this, we were able to give them custom crafting tabs in the standalone after all, so they might rework the game a little to better support that in a later update. I'll let ya know if I figure it out myself though.

Link to comment
Share on other sites

I managed to figure out how to do this for my character. This is what is in my modmain.lua. I hope this helps.

local resolvefilepath = GLOBAL.resolvefilepathlocal TECH = GLOBAL.TECHlocal CUSTOM_RECIPETABS = GLOBAL.CUSTOM_RECIPETABSCUSTOM_RECIPETABS.BOOMERANGS = { str = "BOOMERANGS", sort = 998, icon = "boomerangtab.tex", icon_atlas = resolvefilepath("images/hud/boomerangtab.xml") }STRINGS.TABS.BOOMERANGS = "Boomerangs"local rakkyboomerang_recipe = Recipe("rakkyboomerang", { Ingredient("houndstooth", 2), Ingredient("log", 3) }, CUSTOM_RECIPETABS.BOOMERANGS, TECH.NONE, nil, nil, nil, nil, true)local rakkyboomerang_carrot_recipe = Recipe("rakkyboomerang_carrot", { Ingredient("carrot", 4), Ingredient("rope", 1), Ingredient("honey", 4) }, CUSTOM_RECIPETABS.BOOMERANGS, TECH.SCIENCE_TWO, nil, nil, nil, nil, true)local rakkyboomerang_feather_recipe = Recipe("rakkyboomerang_feather", { Ingredient("stinger", 4), Ingredient("feather_robin", 4), Ingredient("feather_crow", 4) }, CUSTOM_RECIPETABS.BOOMERANGS, TECH.SCIENCE_ONE, nil, nil, nil, nil, true)local rakkyboomerang_bat_recipe = Recipe("rakkyboomerang_bat", { Ingredient("monstermeat_dried", 4), Ingredient("livinglog", 2), Ingredient("tentaclespots", 1) }, CUSTOM_RECIPETABS.BOOMERANGS, TECH.MAGIC_TWO, nil, nil, nil, nil, true) -- TODO: Change "monstermeat_dried" to "batwing" when batilisks are re-implementedlocal rakkyboomerang_ruins_recipe = Recipe("rakkyboomerang_ruins", { Ingredient("nightmare_timepiece", 1), Ingredient("walrus_tusk", 2), Ingredient("nightmarefuel", 4) }, CUSTOM_RECIPETABS.BOOMERANGS, TECH.ANCIENT_FOUR, nil, nil, true, nil, true)rakkyboomerang_recipe.atlas = resolvefilepath("images/inventoryimages/rakkyboomerang.xml")rakkyboomerang_feather_recipe.atlas = resolvefilepath("images/inventoryimages/rakkyboomerang_feather.xml")rakkyboomerang_carrot_recipe.atlas = resolvefilepath("images/inventoryimages/rakkyboomerang_carrot.xml")rakkyboomerang_bat_recipe.atlas = resolvefilepath("images/inventoryimages/rakkyboomerang_bat.xml")rakkyboomerang_ruins_recipe.atlas = resolvefilepath("images/inventoryimages/rakkyboomerang_ruins.xml")-- Add new tabAddClassPostConstruct("widgets/crafttabs", function(class)    if class.owner:HasTag("boomerangbuilder") then        local v = CUSTOM_RECIPETABS.BOOMERANGS        local k = #class.tab_order + 1        local tab_bg =        {            normal = "tab_normal.tex",            selected = "tab_selected.tex",            highlight = "tab_highlight.tex",            bufferedhighlight = "tab_place.tex",            overlay = "tab_researchable.tex",        }                class.tabs.spacing = 750/k        local tab = class.tabs:AddTab(STRINGS.TABS[v.str], resolvefilepath("images/hud.xml"), v.icon_atlas or resolvefilepath("images/hud.xml"), v.icon, tab_bg.normal, tab_bg.selected, tab_bg.highlight, tab_bg.bufferedhighlight, tab_bg.overlay,                        function() --select fn                if not class.controllercraftingopen then                                        if class.craft_idx_by_tab[k] then                        class.crafting.idx = class.craft_idx_by_tab[k]                    end                    class.crafting:SetFilter(                        function(recipe)                            local rec = GLOBAL.AllRecipes[recipe]                            return rec and rec.tab == v                        end)                                                                                                                class.crafting:Open()                end            end,            function() --deselect fn                class.craft_idx_by_tab[k] = class.crafting.idx                class.crafting:Close()            end)        tab.filter = v        tab.icon = v.icon        tab.icon_atlas = v.icon_atlas or resolvefilepath("images/hud.xml")        tab.tabname = STRINGS.TABS[v.str]        class.tabbyfilter[v] = tab                table.insert(class.tab_order, tab)    endend)
Link to comment
Share on other sites

 

I managed to figure out how to do this for my character. This is what is in my modmain.lua. I hope this helps.

Is code missing in AddClassPostConstruct? I get "unexpected symbol near ' '" on the row just below AddClassPostConstruct when testing it.

 

Edit: nevermind copying code from the forum seems to create invisible weird symbols in Eclipse. weird.

Edited by RedMattis
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...