Jump to content

How does one disable a recipe for a single character?


Recommended Posts

I made new prefabs: primitive axe, primitive pickaxe and a primitive shovel and i made them craftable for only the character of my mod. But now i want to have the normal axe, pickaxe and shovel recipe disabled for only my character, 

Does anyone of you know how to achieve this?

Thanks in advance!

Link to comment
Share on other sites

@QuickShot010 Try this in the modmain:

GLOBAL.AllRecipes.axe.builder_tag = "ordinary_dude"
GLOBAL.AllRecipes.pickaxe.builder_tag = "ordinary_dude"
GLOBAL.AllRecipes.shovel.builder_tag = "ordinary_dude"

AddComponentPostInit("builder", function(self)
	if self.inst and self.inst.prefab ~= "my_mod_character" then
		self.inst:AddTag("ordinary_dude")
	end
end)

 

Edited by rezecib
buildertag -> builder_tag
Link to comment
Share on other sites

After seeing you post 3 times, I tried to see if I could figure something out. While I haven't tried it, this should work:

Readd the default axe/pickaxe/shovel recipes, but making them require a tag:

AddRecipe("axe", {Ingredient("twigs", 1),Ingredient("flint", 1)}, RECIPETABS.TOOLS, TECH.NONE, nil, nil, nil, nil, "noncaveman")
AddRecipe("pickaxe", {Ingredient("twigs", 2),Ingredient("flint", 2)}, RECIPETABS.TOOLS, TECH.NONE, nil, nil, nil, nil, "noncaveman")
AddRecipe("shovel", {Ingredient("twigs", 2),Ingredient("flint", 2)}, RECIPETABS.TOOLS, TECH.SCIENCE_ONE, nil, nil, nil, nil, "noncaveman")

then Add the "noncaveman" tag to every player that isnt the caveman:

AddPlayerPostInit(function(inst)--after a player loads
	if inst.prefab ~= "caveman" then --change "caveman" to whatever your character s prefab name is
		inst:AddTag("noncaveman")
	end
end)

 

Edited by Aquaterion
Link to comment
Share on other sites

Instead of messing with tags or recipes, this is my suggestion:

AddClassPostConstruct("components/builder_replica", function(self)
	if self.inst.IsPrimitiveFellow then
		local _CanLearn = self.CanLearn
		self.CanLearn = function(self, recipename)
			if recipename == "axe" or recipename == "pickaxe" or recipename == "shovel" then
				return false
			end
			return _CanLearn(self, recipename)
		end
	end
end)

You put this in modmain.

local function common_postinit(inst)
	inst.IsPrimitiveFellow = true
end

You enable this field in your character prefab.

Link to comment
Share on other sites

3 hours ago, rezecib said:

@QuickShot010 Try this in the modmain:


GLOBAL.AllRecipes.axe.builder_tag = "ordinary_dude"
GLOBAL.AllRecipes.pickaxe.builder_tag = "ordinary_dude"
GLOBAL.AllRecipes.shovel.builder_tag = "ordinary_dude"

AddComponentPostInit("builder", function(self)
	if self.inst and self.inst.prefab ~= "my_mod_character" then
		self.inst:AddTag("ordinary_dude")
	end
end)

 

I tried, but it seems like it's not working, is there something i need to change except "my_mod_character"?

 

2 hours ago, Aquaterion said:

After seeing you post 3 times, I tried to see if I could figure something out. While I haven't tried it, this should work:

Readd the default axe/pickaxe/shovel recipes, but making them require a tag:


AddRecipe("axe", {Ingredient("twigs", 1),Ingredient("flint", 1)}, RECIPETABS.TOOLS, TECH.NONE, nil, nil, nil, nil, "noncaveman")
AddRecipe("pickaxe", {Ingredient("twigs", 2),Ingredient("flint", 2)}, RECIPETABS.TOOLS, TECH.NONE, nil, nil, nil, nil, "noncaveman")
AddRecipe("shovel", {Ingredient("twigs", 2),Ingredient("flint", 2)}, RECIPETABS.TOOLS, TECH.SCIENCE_ONE, nil, nil, nil, nil, "noncaveman")

then Add the "noncaveman" tag to every player that isnt the caveman:


AddPlayerPostInit(function(inst)--after a player loads
	if inst.prefab ~= "caveman" then --change "caveman" to whatever your character s prefab name is
		inst:AddTag("noncaveman")
	end
end)

 

This would make my mod incompatible with other character mods though...

Link to comment
Share on other sites

3 minutes ago, QuickShot010 said:

I tried, but it seems like it's not working, is there something i need to change except "my_mod_character"?

 

This would make my mod incompatible with other character mods though...

it actually wouldn't, it checks every PLAYER, not characters, doesn't matter what character the player has, a player is a player.

Link to comment
Share on other sites

AddPlayerPostInit (and really anything that uses AddPrefabPostInitAny) is an abomination that should never be used, because it adds overhead to the addition of literally every prefab in the game. It's much better to do it in an AddComponentPostInit on a component that only players have, like builder.

Edited by rezecib
Link to comment
Share on other sites

8 minutes ago, Aquaterion said:

it actually wouldn't, it checks every PLAYER, not characters, doesn't matter what character the player has, a player is a player.

Oh i see that now! As @rezecib mentions using AddPlayerPostInit is an abomination, i am not sure why, but let's see how we can script this the most clean way! :)

7 minutes ago, rezecib said:

AddPlayerPostInit (and really anything that uses AddPrefabPostInitAny) is an abomination that should never be used, because it adds overhead to the addition of literally every prefab in the game. It's much better to do it in an AddComponentPostInit on a component that only players have, like builder.

So how would this be done?
Sorry for asking so many questions :D

 

Link to comment
Share on other sites

3 minutes ago, QuickShot010 said:

Oh i see that now! As @rezecib mentions using AddPlayerPostInit is an abomination, i am not sure why, but let's see how we can script this the most clean way! :)

So how would this be done?
Sorry for asking so many questions :D

 

check above, he already told you how to do it the first time

Link to comment
Share on other sites

4 minutes ago, QuickShot010 said:

So how would this be done?

Like I showed in the first code snippet instead of AddPlayerPostInit(function(inst), you do AddComponentPostInit("builder", function(self), and use self.inst instead of inst.

Link to comment
Share on other sites

5 minutes ago, Aquaterion said:

check above, he already told you how to do it the first time

Yes, but for some reason that doesn't work. I might be making an incredibly dumb mistake, but i just placed the code in my modmain and changed the "my_mod_character" with my prefab name: "drok".

EDIT: NVM, let me try what rezecib said just now :)

Edited by QuickShot010
Link to comment
Share on other sites

4 minutes ago, QuickShot010 said:

Yes, but for some reason that doesn't work. I might be making an incredibly dumb mistake, but i just placed the code in my modmain and changed the "my_mod_character" with my prefab name: "drok".

If you're using my recipe method, you gotta change the "ordinary_dude" to "noncaveman"

Link to comment
Share on other sites

@rezecib I used your code in the modmain but my character is still able to craft the recipes in game... I really have no idea what i'm doing wrong here. This is my modmain.lua:

PrefabFiles = {
	"drok",
	"wigstanstone",
	"wigstan",
	"wigstanfull",
	"javelin",
	"redpaint",
	"beefalo_hide",
	"paintedrock",
	"primitive_axe",
	"primitive_pickaxe",
}

Assets = {
    Asset( "IMAGE", "images/saveslot_portraits/drok.tex" ),
    Asset( "ATLAS", "images/saveslot_portraits/drok.xml" ),

    Asset( "IMAGE", "images/selectscreen_portraits/drok.tex" ),
    Asset( "ATLAS", "images/selectscreen_portraits/drok.xml" ),

    Asset( "IMAGE", "bigportraits/drok.tex" ),
    Asset( "ATLAS", "bigportraits/drok.xml" ),
	
	Asset( "IMAGE", "images/map_icons/drok.tex" ),
	Asset( "ATLAS", "images/map_icons/drok.xml" ),
	
	Asset( "IMAGE", "images/avatars/avatar_drok.tex" ),
    Asset( "ATLAS", "images/avatars/avatar_drok.xml" ),
	
	Asset( "IMAGE", "images/avatars/avatar_ghost_drok.tex" ),
    Asset( "ATLAS", "images/avatars/avatar_ghost_drok.xml" ),

    Asset( "SOUNDPACKAGE", "sound/drok.fev" ),
    Asset( "SOUND", "sound/drok.fsb" ),

    Asset( "ATLAS", "images/inventoryimages/paintedrock.xml" ),

}

RemapSoundEvent( "dontstarve/characters/drok/death_voice", "drok/characters/drok/death_voice" )
RemapSoundEvent( "dontstarve/characters/drok/hurt", "drok/characters/drok/hurt" )
RemapSoundEvent( "dontstarve/characters/drok/talk_LP", "drok/characters/drok/talk_LP" )
RemapSoundEvent( "dontstarve/characters/drok/emote", "drok/characters/drok/emote" )
RemapSoundEvent( "dontstarve/characters/drok/ghost_LP", "drok/characters/drok/ghost_LP" )
RemapSoundEvent( "dontstarve/characters/drok/yawn", "drok/characters/drok/yawn" )

local require = GLOBAL.require
local STRINGS = GLOBAL.STRINGS
local Ingredient = GLOBAL.Ingredient
local RECIPETABS = GLOBAL.RECIPETABS
 
RECIPETABS = GLOBAL.RECIPETABS
Recipe = GLOBAL.Recipe
Ingredient = GLOBAL.Ingredient
TECH = GLOBAL.TECH

GLOBAL.AllRecipes.axe.builder_tag = "ordinary_dude"
GLOBAL.AllRecipes.pickaxe.builder_tag = "ordinary_dude"
GLOBAL.AllRecipes.shovel.builder_tag = "ordinary_dude"

AddComponentPostInit("builder", function(self)
	if self.inst and self.inst.prefab ~= "drok" then
		self.inst:AddTag("ordinary_dude")
	end
end)

AddRecipe("redpaint", {Ingredient("ash", 2), Ingredient("rocks", 1), Ingredient("berries_cooked", 3)}, RECIPETABS.REFINE, TECH.SCIENCE_ONE, nil, nil, nil, nil, "redpaint_builder", "images/inventoryimages/redpaint.xml", "redpaint.tex")
AddRecipe("wigstan", {Ingredient("wigstanstone", 1, "images/inventoryimages/wigstanstone.xml"), Ingredient("redpaint", 2, "images/inventoryimages/redpaint.xml")}, RECIPETABS.REFINE, TECH.SCIENCE_ONE, nil, nil, nil, nil, "wigstan_builder", "images/inventoryimages/wigstan.xml", "wigstan.tex")
AddRecipe("wigstanfull", {Ingredient("wigstan", 1, "images/inventoryimages/wigstan.xml"), Ingredient("beefalowool", 5), Ingredient("rope", 3)}, RECIPETABS.REFINE, TECH.SCIENCE_TWO, nil, nil, nil, nil, "wigstanfull_builder", "images/inventoryimages/wigstanfull.xml", "wigstanfull.tex")
AddRecipe("paintedrock", {Ingredient("rocks", 3), Ingredient("redpaint", 3, "images/inventoryimages/redpaint.xml")}, RECIPETABS.TOWN, TECH.SCIENCE_TWO, "paintedrock_placer", nil, nil, nil, "paintedrock_builder", "images/inventoryimages/paintedrock.xml", "paintedrock.tex")
AddRecipe("beefalo_hide", {Ingredient("beefalowool", 6), Ingredient("houndstooth", 1), Ingredient("rope", 1)}, RECIPETABS.DRESS, TECH.SCIENCE_TWO, nil, nil, nil, nil, "beefalo_hide_builder", "images/inventoryimages/beefalo_hide.xml", "beefalo_hide.tex")
AddRecipe("javelin", {Ingredient("twigs", 2), Ingredient("rope", 1), Ingredient("houndstooth", 1)}, RECIPETABS.WAR, TECH.SCIENCE_ONE, nil, nil, nil, nil, "javelin_builder", "images/inventoryimages/javelin.xml", "javelin.tex")
local primitive_axe = AddRecipe("primitive_axe", {Ingredient("twigs", 1), Ingredient("flint", 1)}, RECIPETABS.TOOLS, TECH.NONE, nil, nil, nil, nil, "primitive_axe_builder", "images/inventoryimages/primitive_axe.xml", "primitive_axe.tex")
primitive_axe.sortkey = 0.1996
local primitive_pickaxe = AddRecipe("primitive_pickaxe", {Ingredient("twigs", 2), Ingredient("flint", 2)}, RECIPETABS.TOOLS, TECH.NONE, nil, nil, nil, nil, "primitive_pickaxe_builder", "images/inventoryimages/primitive_pickaxe.xml", "primitive_pickaxe.tex")
primitive_pickaxe.sortkey = 0.1997

STRINGS.CHARACTER_TITLES.drok = "The Caveman"
STRINGS.CHARACTER_NAMES.drok = "Drok"
STRINGS.CHARACTER_DESCRIPTIONS.drok = "*Is dumb\n*Grows hair that keeps him warm\n*Is strong but needs food"
STRINGS.CHARACTER_QUOTES.drok = "\"Oog!\""

STRINGS.CHARACTERS.DROK = require "speech_drok"

STRINGS.NAMES.DROK = "Drok"

STRINGS.CHARACTERS.GENERIC.DESCRIBE.DROK = 
{
	GENERIC = "It's Drok!",
	ATTACKER = "That Drok looks shifty...",
	MURDERER = "Murderer!",
	REVIVER = "Drok, friend of ghosts.",
	GHOST = "Drok could use a heart.",
}

STRINGS.RECIPE_DESC.WIGSTAN = "Make a new friend."
STRINGS.RECIPE_DESC.WIGSTANFULL = "Make a better hairy friend."
STRINGS.RECIPE_DESC.REDPAINT = "Some red paint."
STRINGS.RECIPE_DESC.PAINTEDROCK = "Show your dominance by painting on rocks."
STRINGS.RECIPE_DESC.BEEFALO_HIDE = "Keeps warm and protects."
STRINGS.RECIPE_DESC.JAVELIN = "Throw to hunt and kill."
STRINGS.RECIPE_DESC.PRIMITIVE_AXE = "A primitive tool to chop wood."
STRINGS.RECIPE_DESC.PRIMITIVE_PICKAXE = "A primitive tool to mine stone."

--table.insert(GLOBAL.CHARACTER_GENDERS.MALE, "drok")

AddMinimapAtlas("images/map_icons/drok.xml")
AddModCharacter("drok", "MALE")

STRINGS.NAMES.WIGSTANSTONE = "Roundish Stone"
STRINGS.CHARACTERS.GENERIC.DESCRIBE.WIGSTANSTONE = "It's a stone."
STRINGS.CHARACTERS.DROK.DESCRIBE.WIGSTANSTONE = "Maybe Drok make new friend?"

STRINGS.NAMES.WIGSTANFULL = "Wigstan"
STRINGS.CHARACTERS.GENERIC.DESCRIBE.WIGSTANFULL = "It looks a bit like a volleyball. A stone volleyball."

STRINGS.NAMES.WIGSTAN = "Wigstan"
STRINGS.CHARACTERS.GENERIC.DESCRIBE.WIGSTAN = "I have the feeling i saw this somewhere before..."

STRINGS.NAMES.REDPAINT = "Red Dye"
STRINGS.CHARACTERS.DROK.DESCRIBE.REDPAINT = "Drok use to paint!"
STRINGS.CHARACTERS.GENERIC.DESCRIBE.REDPAINT = "It looks primitive."

STRINGS.NAMES.PAINTEDROCK = "Rock Paintings"
STRINGS.CHARACTERS.DROK.DESCRIBE.PAINTEDROCK = "Drok show dominance!"
STRINGS.CHARACTERS.GENERIC.DESCRIBE.PAINTEDROCK = "Those paintings are from an ancient time..."

STRINGS.NAMES.JAVELIN = "Throwing Spear"
STRINGS.CHARACTERS.DROK.DESCRIBE.JAVELIN = "Drok good hunt!"
STRINGS.CHARACTERS.GENERIC.DESCRIBE.JAVELIN = "It's some sort of ancient throwing device."

STRINGS.NAMES.BEEFALO_HIDE = "Winter Hide"
STRINGS.CHARACTERS.DROK.DESCRIBE.BEEFALO_HIDE = "Keep Drok very warm!"
STRINGS.CHARACTERS.GENERIC.DESCRIBE.BEEFALO_HIDE = "It looks itchy and uncomfortable."

STRINGS.NAMES.PRIMITIVE_AXE = "Primitive Axe"
STRINGS.CHARACTERS.DROK.DESCRIBE.PRIMITIVE_AXE = "Drok proud of axe made! Chop wood for fire!"
STRINGS.CHARACTERS.GENERIC.DESCRIBE.PRIMITIVE_AXE = "It is poorly made and looks like it came from the stone age."

STRINGS.NAMES.PRIMITIVE_PICKAXE = "Primitive Pickaxe"
STRINGS.CHARACTERS.DROK.DESCRIBE.PRIMITIVE_PICKAXE = "Drok gather rock!"
STRINGS.CHARACTERS.GENERIC.DESCRIBE.PRIMITIVE_PICKAXE = "How is this even sturdy enough to mine stone?"

Edited by QuickShot010
Link to comment
Share on other sites

11 minutes ago, rezecib said:

It's working for me when I do it...

My modmain is the same as in the message i sent before, and this is my ingame screenshot:

Df2XgFE.jpg

As you can see the recipes are still here, is it because i didn't yet add the primitive_shovel prefab? That seems unlikely though. 

What should i do now? :?

 

EDIT: Just removed the GLOBAL.AllRecipes.shovel.builder_tag = "ordinary_dude" line but it is still not working.

Edited by QuickShot010
Link to comment
Share on other sites

3 minutes ago, QuickShot010 said:

My modmain is the same as in the message i sent before, and this is my ingame screenshot:

Df2XgFE.jpg

As you can see the recipes are still here, is it because i didn't yet add the primitive_shovel prefab? That seems unlikely though. 

What should i do now? :?

you could print some stuff to check that the tag is being added, or you could try the AddPlayerPostInit method. ik it might be a bit bad, but at least see if it works

Link to comment
Share on other sites

11 minutes ago, Aquaterion said:

you could print some stuff to check that the tag is being added, or you could try the AddPlayerPostInit method. ik it might be a bit bad, but at least see if it works

Yes, i'll try the AddPlayerPostInit method and keep you guys up to date. :D

Link to comment
Share on other sites

5 hours ago, rezecib said:

It's working for me when I do it...

I'm doing

AddComponentPostInit("builder", function(self)
	print("BUILDER TEST")
	print(self.inst.prefab or "nil prefab")
end)

and the log always shows "nil prefab" for:

1) Enabling mod, generating new world without caves

2) Enabling mod, reloading old world without caves

3) Enabling mod, generating new world with caves

4) Enabling mod, reloading old world with caves

Link to comment
Share on other sites

@DarkXero @QuickShot

Whoops, right. Components get added during the constructor, and the prefab field doesn't get populated until after that. Pushing it into an inst:DoTaskInTime should fix it: (I had been testing it with console commands in game rather than setting it up in a modmain)

GLOBAL.AllRecipes.axe.builder_tag = "ordinary_dude"
GLOBAL.AllRecipes.pickaxe.builder_tag = "ordinary_dude"
GLOBAL.AllRecipes.shovel.builder_tag = "ordinary_dude"

AddComponentPostInit("builder", function(self)
	self.inst:DoTaskInTime(0, function()
		if self.inst and self.inst.prefab ~= "my_mod_character" then
			self.inst:AddTag("ordinary_dude")
		end
	end)
end)

 

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