Jump to content

Recommended Posts

The Books prefab has this code:

 

inst:AddComponent("characterspecific")
inst.components.characterspecific:SetOwner("wickerbottom")
 
Is there anyway I could use this somehow? Any help would be much appreciated. :-)
Edited by FruityKinqz

@FruityKinqz, This method will not work. The character specific component has more to do with whether it lets you keep the item when you leave. The books tab is actually hard coded in crafttabs.lua to check for the "bookbuilder" tag, but adding your own tab that works like that is quite an ordeal.

 

As for adding some items to existing tabs, currently this is something that's a bit tricky to do, but basically what you do is just hide the recipe from characters who aren't supposed to make this. The way I did this for Wigfrid and Webber was the following:

if 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 = IsRecipeValidendlocal 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),}for k,v in pairs(recipes) do	v.tagneeded = trueend

Then in the character's prefabs you add a tag for each recipe that only they can craft:

	inst:AddTag("spidereggsack_builder")

@rezecib thank you :D so where do I put the first bit of code?

And just to clarify I just copy it over and replace "ThePlayer", "_builder" and recipes with my own. I don't really know much about modding only started like a week ago. :)

 

where do I put the first bit of code
In your modmain. And do not change "ThePlayer", it's a constant that refers to the local player object. The only stuff you should need to change is the recipes, and then the tag that you add to the prefab. For example, let's say your recipe is for the "shotgun" prefab, in your character's common_postinit you'd add inst:AddTag("shotgun_builder").

Okayy so I added It but it does not show up at all now :/ I think it because I removed the line:

 

crown_recipe.atlas = "images/inventoryimages/Crown.xml"

 

Doesn't work when I leave it in if I leave It like above it says attempt to index global  "crown_recipe" (a nil value)
and if i put it as:

Local crown_recipe.atlas = "images/inventoryimages/Crown.xml"

 

It says unexpected symbol near "."
 

@FruityKinqz, No, not that. But actually double-checking it, looks like I was wrong. The atlas argument is just for the ingredients. But show me how you're declaring your recipes and I can show you how to get it to change the atlas.

Just how you've said above (first post) I got rid of:

 

local crown_recipe = GLOBAL.Recipe("crown",{ Ingredient("flint", 1) },                     
        RECIPETABS.DRESS, TECH.NONE )
        crown_recipe.atlas = "images/inventoryimages/Crown.xml"
 
when I put the code in

@FruityKinqz, Well, I wanted your actual code, but hopefully I can explain how to do it.

 

In my example, recipes[1] is the spidereggsack recipe, recipes[2] is the wrathgrithrhat recipe, and recipes[3] is the wrathgrithr_spear recipe. So if yours was the first entry in your recipe table, you can do recipes[1].atlas = "images/inventoryimages/Crown.xml"

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
×
  • Create New...