Jump to content

Is it possible to hide a certain crafting recipe for a character?


Recommended Posts

Hello! So I was wonder is it possible to hide a certain crafting recipe for a specific character because I don't want them to be able to craft a certain item.

Thanks for any help and reading, have a good day/night :D!

Link to comment
Share on other sites

The builder_replica component (the client version of the builder component) has a RemoveRecipe function. See if you can make that work. If not, you can extend/chain the three functions CanBuild, CanLearn and KnowsRecipe in BOTH the builder and the builder_replica components, and simply return false, without calling the original functions, if the recname parameter is the recipe you want to disable. That's only 4 lines of code times 6. But I'd bet RemoveRecipe on the replica works.

Edited by Ultroman
Link to comment
Share on other sites

If above does not work (I guess it wont work if you are host of the world?):
All recipes can have a "builder_tag".
builder_tag means only characters with this tag can build it. So you could make an AddPlayerPostInit and give every player, except if they play your character, a new builder_tag and add this builder_tag to the recipe. This of course only works if the recipe does not have already a builder tag, like the ones exclusive to special  characters.

To change a builder tag for an existing recipe, you can use this code (everyhting into modmain):

for k,v in pairs(GLOBAL.AllRecipes) do -- loop over all existing recipes
    if v.name=="axe" then -- find the one we are looking for
        if v.builder_tag==nil then -- make sure it does not already have a builder tag. in this case this code wont be a good idea        
            v.builder_tag = "canbuildaxe" -- change the builder_tag without overwriting anything else
        else
            print("axe already has a builder_tag, overwriting it is no good idea")
        end
    end
end

edit: removed CanLearn code, because I'm not sure if this is the intended result

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