Jump to content

Custom recipe - character specific? [short, easy question]


Recommended Posts

For Don't Starve Together, I have a recipe, as a part of character mod. It's placed in modmain.lua. 

 

looks like this:

local someitem_recipe = Recipe("someitem", {Ingredient("rocks", 10), Ingredient("log", 25), Ingredient("twigs", 8)}, RECIPETABS.TOWN, TECH.NONE)someitem_recipe.sortkey = 1someitem_recipe.atlas = resolvefilepath("images/inventoryimages/someitem.xml")STRINGS.RECIPE_DESC.SOMEITEM = "bla blablabla blah!"
Like this, if mod is enabled, everyone on the server can make it. And the deal is - to make it ONLY the character the recipe comes from specific.So no other characters can craft it.
 
I guess it's very simple, so sorry for stupid question -.-
Link to comment
Share on other sites

@Foxrai, Look at DST RoG Characters. The IsRecipeValid part, and then you add a tag to the character prefab like AddTag("someitem_builder").

 

But you shouldn't set the sortkey to 1, there. Set it to -50 or something, because sortkeys are what are used to send the recipes to the host (e.g. a client says "build recipe 21!" and the host says "okay, let's look up 21... that's a firepit, building it...". So by setting your sortkey to 1, you're preventing people from building whatever was recipe #1 before).

Link to comment
Share on other sites

@Foxrai, Look at DST RoG Characters. The IsRecipeValid part, and then you add a tag to the character prefab like AddTag("someitem_builder").

 

But you shouldn't set the sortkey to 1, there. Set it to -50 or something, because sortkeys are what are used to send the recipes to the host (e.g. a client says "build recipe 21!" and the host says "okay, let's look up 21... that's a firepit, building it...". So by setting your sortkey to 1, you're preventing people from building whatever was recipe #1 before).

 

DST ROG... ok will check that out. I kinda compared only Wickerbottom.

So when the character has for example tag: book_builder, then only this character will be able to build "book" item? 

 

So in general - the safest way is to set sortkey for like 50 or 100? And It will show up under everything else?

Like any high numer shot, so nothing in different mod will argue with it?

Link to comment
Share on other sites

DST ROG... ok will check that out. I kinda compared only Wickerbottom.

So when the character has for example tag: book_builder, then only this character will be able to build "book" item? 

 

So in general - the safest way is to set sortkey for like 50 or 100? And It will show up under everything else?

Like any high numer shot, so nothing in different mod will argue with it?

 

 

or just do your steam id :p

Link to comment
Share on other sites

Sorry for interfering in OPs topic but I feel my problem sorta relates, how would I go about this with items already implemented in the game? Like I want my character to make Purplegems only in the pseudoscience machine and thats going swell, except now people who want to make purple gems normally can't because I moved it to pseudoscience.

 

I only WANT HER to make purple gem with this recipe, and no one else. Everyone else uses the default recipe in the default tab.

 

So what I'm using is WebWeb the mighty spider mod and based on what I found i made this:

-- This initializes for both clients and the hostlocal common_postinit = function(inst) 	-- Minimap icon	inst.MiniMapEntity:SetIcon( "char.tex" )	inst:AddTag("ancientbuilder")	local purplegem_recipe    purplegem_recipe = Recipe("purplegem", {Ingredient("flint", 10),Ingredient("nightmarefuel",2),Ingredient("goldnugget",7)}, RECIPETABS.ANCIENT, TECH.ANCIENT_TWO ,nil,nil,nil,3)    purplegem_recipe.sortkey = -73

Weird that the recipe isn't in the modmain but when I played it worked perfectly.

In her modmain I added:

local Ingredient = GLOBAL.Ingredientlocal RECIPETABS = GLOBAL.RECIPETABSRECIPETABS = GLOBAL.RECIPETABSRecipe = GLOBAL.RecipeIngredient = GLOBAL.IngredientTECH = GLOBAL.TECH

Yet again, sorry for interfering.

Edited by rons0n
Link to comment
Share on other sites

@rezecib,

 

Looks like this now:

 

local common_postinit = function(inst)     inst.soundsname = "wendy"    inst:AddTag("sanityorb_builder")end

and recipe is modified to this:

 

someitem_recipe.sortkey = -8812221 (are you sure I add "-" in it?) 

 

Doesn't seems to work :/ But I must admin I haven't found RecipeIsValid part for DST ROG characters.. :/ they are pretty plain comparing to normal DS characters in DST..

 

 

Link to comment
Share on other sites

@Foxrai, No, not their prefab files in the game files, the mod I wrote, "DST RoG Characters".

 

@rons0n, No, this is a separate issue. You cannot have two recipes for the same prefab. You need to make it a recipe for a proxy prefab that then removes itself and gives a purple gem.

 

@rezecib Before I delete this post and my previous post, both being unrelated to this topic, I promise it wasn't intended :-(. Is there a mod with a proxy prefab so I may use it to experiment?

Link to comment
Share on other sites

@Foxrai, No, not their prefab files in the game files, the mod I wrote, "DST RoG Characters".

 

@rons0n, No, this is a separate issue. You cannot have two recipes for the same prefab. You need to make it a recipe for a proxy prefab that then removes itself and gives a purple gem.

 

 

Then I must be blind - only seeing MORE Rog characters... And nothing like you mentioned before in there :o

 

I added sanityorbbuilder tag to my character.. Just can't seem to figure out how to connect it with the recipe... I guess it needs something like "if has tag, then can build.."

 

sorry in advance :x

Link to comment
Share on other sites

--#rezecib This is a fix for the recipe problem; you can no longer put recipes in character prefabs-- because then when the host creates the game, some recipes won't be loaded;-- when they do get loaded later, further connections will have garbled net data because the-- new recipes change the size of the data (that's my guess)--The approach here is to instead associate a tag with each recipe, then modify the function-- that checks if they can see it to check for those tagsif not GLOBAL.TheNet:IsDedicated() then	local OldIsRecipeValid = GLOBAL.IsRecipeValid	local function IsRecipeValid(recipe)		return OldIsRecipeValid(recipe) and			((GLOBAL.ThePlayer and GLOBAL.ThePlayer:HasTag(recipe.name.."_builder")) or not recipe.tagneeded)	end	GLOBAL.IsRecipeValid = IsRecipeValidend--#rezecib Had to move all the recipes here to support the abovelocal Recipe = GLOBAL.Recipelocal RECIPETABS = GLOBAL.RECIPETABSlocal TECH = GLOBAL.TECHlocal recipes = {	Recipe("spidereggsack", {Ingredient("silk", 12), Ingredient("spidergland", 6), Ingredient("papyrus", 6)}, RECIPETABS.TOWN, TECH.NONE),	Recipe("wathgrithrhat", {Ingredient("goldnugget", 2), Ingredient("rocks", 2)}, RECIPETABS.WAR, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0}, nil, nil, nil, nil, true),	Recipe("spear_wathgrithr", {Ingredient("twigs", 2), Ingredient("flint", 2), Ingredient("goldnugget", 2)}, RECIPETABS.WAR, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0}, nil, nil, nil, nil, true),}--#rezecib this is a bit of a hack; hardcoding the sortkeys should avoid mod clashes-- due to different load order, but if a mod somehow declares sortkeys in this range in-- the same way, then problems will always occur with that modlocal sortkey = -9000for k,v in pairs(recipes) do	sortkey = sortkey - 1	v.sortkey = sortkey	v.tagneeded = trueend

I'll just leave this here. :razz:

Link to comment
Share on other sites

This type of Recipe adding works very poorly.

 

All mods that Overwrite the  local OldIsRecipeValid = GLOBAL.IsRecipeValid, will conflict with each other. Making it so only 1 Mod recipes work, while any other is overwriting.

 

Until Klei comes out with a better way to handle custom private character recipes, it is best to leave it open for all characters to craft.

Link to comment
Share on other sites

All mods that Overwrite the  local OldIsRecipeValid = GLOBAL.IsRecipeValid, will conflict with each other. Making it so only 1 Mod recipes work, while any other is overwriting.

 

 

Actually, no. Here, the old isRecipeValid is backed up in a variable, then used inside the function than overrides it, while adding custom verifications. That way, multiple mods may override isRecipeValid without conflicting with each others, as long as they use the old function inside the override.

That's the modding powers of Lua right there.

 

The main problem is sortkey overlap. That's why rezecib uses -9000 to index the sortkeys of his custom recipes, to avoid as much as possible conflicts between mods. It's indeed not very robust, but it'll do until Klei comes up with a proper API.

Link to comment
Share on other sites

--#rezecib This is a fix for the recipe problem; you can no longer put recipes in character prefabs-- because then when the host creates the game, some recipes won't be loaded;-- when they do get loaded later, further connections will have garbled net data because the-- new recipes change the size of the data (that's my guess)--The approach here is to instead associate a tag with each recipe, then modify the function-- that checks if they can see it to check for those tagsif not GLOBAL.TheNet:IsDedicated() then	local OldIsRecipeValid = GLOBAL.IsRecipeValid	local function IsRecipeValid(recipe)		return OldIsRecipeValid(recipe) and			((GLOBAL.ThePlayer and GLOBAL.ThePlayer:HasTag(recipe.name.."_builder")) or not recipe.tagneeded)	end	GLOBAL.IsRecipeValid = IsRecipeValidend--#rezecib Had to move all the recipes here to support the abovelocal Recipe = GLOBAL.Recipelocal RECIPETABS = GLOBAL.RECIPETABSlocal TECH = GLOBAL.TECHlocal recipes = {	Recipe("spidereggsack", {Ingredient("silk", 12), Ingredient("spidergland", 6), Ingredient("papyrus", 6)}, RECIPETABS.TOWN, TECH.NONE),	Recipe("wathgrithrhat", {Ingredient("goldnugget", 2), Ingredient("rocks", 2)}, RECIPETABS.WAR, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0}, nil, nil, nil, nil, true),	Recipe("spear_wathgrithr", {Ingredient("twigs", 2), Ingredient("flint", 2), Ingredient("goldnugget", 2)}, RECIPETABS.WAR, {SCIENCE = 0, MAGIC = 0, ANCIENT = 0}, nil, nil, nil, nil, true),}--#rezecib this is a bit of a hack; hardcoding the sortkeys should avoid mod clashes-- due to different load order, but if a mod somehow declares sortkeys in this range in-- the same way, then problems will always occur with that modlocal sortkey = -9000for k,v in pairs(recipes) do	sortkey = sortkey - 1	v.sortkey = sortkey	v.tagneeded = trueend

What does the , nil, nil, nil, nil, true),  stand for in recipes that have  a tech level?

Edited by JadeKnightblazer
Link to comment
Share on other sites

@JadeKnightblazer, Look at recipe.lua:

Recipe = Class(function(self, name, ingredients, tab, level, placer, min_spacing, nounlock, numtogive)

So the four nils are placer, min_spacing, nounlock, and numtogive. Maybe there used to be another argument, but there isn't anymore. I just copied the recipe declaration from RoG's Wigfrid code, which has that at the end of its recipes.

Link to comment
Share on other sites

Does this method still work? I get an error complaining that "IsRecipeValid" isn't declared on the "local OldIsRecipeValid = GLOBAL.IsRecipeValidline

[00:00:03]: Mod: Seras	  Error loading mod![string "../mods/Seras/modmain.lua"]:114: variable 'IsRecipeValid' is not declaredLUA ERROR stack traceback:        =[C] in function 'error'        scripts/strict.lua(23,1)        ../mods/Seras/modmain.lua(114,1) in main chunk        =[C] in function 'xpcall'        scripts/util.lua(455,1) in function 'RunInEnvironment'        scripts/mods.lua(369,1) in function 'InitializeModMain'        scripts/mods.lua(350,1) in function 'LoadMods'        scripts/main.lua(246,1) in function 'ModSafeStartup'        scripts/main.lua(294,1)        =[C] in function 'SetPersistentString'        scripts/mainfunctions.lua(24,1) in function 'SavePersistentString'        scripts/modindex.lua(82,1)        =[C] in function 'GetPersistentString'        scripts/modindex.lua(69,1) in function 'BeginStartupSequence'        scripts/main.lua(293,1) in function 'callback'        scripts/modindex.lua(436,1)        =[C] in function 'GetPersistentString'        scripts/modindex.lua(416,1) in function 'Load'        scripts/main.lua(292,1) in main chunk	[00:00:03]: [string "../mods/Seras/modmain.lua"]:114: variable 'IsRecipeValid' is not declaredLUA ERROR stack traceback:        =[C] in function 'error'        scripts/strict.lua(23,1)        ../mods/Seras/modmain.lua(114,1) in main chunk        =[C] in function 'xpcall'        scripts/util.lua(455,1) in function 'RunInEnvironment'        scripts/mods.lua(369,1) in function 'InitializeModMain'        scripts/mods.lua(350,1) in function 'LoadMods'        scripts/main.lua(246,1) in function 'ModSafeStartup'        scripts/main.lua(294,1)        =[C] in function 'SetPersistentString'        scripts/mainfunctions.lua(24,1) in function 'SavePersistentString'        scripts/modindex.lua(82,1)        =[C] in function 'GetPersistentString'        scripts/modindex.lua(69,1) in function 'BeginStartupSequence'        scripts/main.lua(293,1) in function 'callback'        scripts/modindex.lua(436,1)        =[C] in function 'GetPersistentString'        scripts/modindex.lua(416,1) in function 'Load'        scripts/main.lua(292,1) in main chunk[00:00:03]: Error error! We tried displaying an error but TheFrontEnd isn't ready yet...	
Edited by RedMattis
Link to comment
Share on other sites

What are those four nils? What about recipe with _placer (for structure)? Thanks!
 

 


@JadeKnightblazer, Look at recipe.lua:
Recipe = Class(function(self, name, ingredients, tab, level, placer, min_spacing, nounlock, numtogive) 
So the four nils are placer, min_spacing, nounlock, and numtogive. Maybe there used to be another argument, but there isn't anymore. I just copied the recipe declaration from RoG's Wigfrid code, which has that at the end of its recipes.
Link to comment
Share on other sites

min_spacing, the room / distance required to be able to be placed on the ground. Either they can be pretty close or a lot of empty space.

 

nounlock, means the ability to learn how to craft without the need of a research lab after the first crafting.  If this is set to yes, then the play must always go to the research lab to craft (think of it like a crafting table).

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...