Jump to content

Recommended Posts

Long story short, I want to clean up a characters in-game hud, because there are items he is incapable of using (he is disallowed from using them entirely, this isn't the solution to stop him from using them, just to prevent them from being craftable by him)

 

I was using an old recipe thing by Quickshot (steam workshop) that was used for Drok as the base for my code, and ended up with this:

local OldIsRecipeValid = GLOBAL.IsRecipeValidlocal function IsRecipeValid(recipe) return OldIsRecipeValid(recipe) and  ((GLOBAL.ThePlayer and GLOBAL.ThePlayer:HasTag(recipe.name.."_builder")) or not recipe.tagneeded and not (GLOBAL.ThePlayer:HasTag(recipe.name.."_breaker")))end

This code had worked in the past for allowing me to completely remove any traces of specific recipes for a specific character by adding

 inst:AddTag("torch_breaker")

as a quick example. 

 

However with the new recipe system in place (which actually makes adding custom recipes easier than ever for most people), I'm hitting my head on the wall here all stupid-like, unable to see how I can make it so characters can't craft the items in the base game.

Link to comment
https://forums.kleientertainment.com/forums/topic/55737-recipe-breaker/
Share on other sites

Thanks to some off-forums messaging with Ksizor, he was able to provide me with a pretty nifty solution to this all. This is the code he had provided me with, and with his approval I'm putting it here so others who may want to have a character that cannot craft specific base-game items be a bit easier for people to make.

AddPlayerPostInit( function ( player ) if not GLOBAL.TheWorld.ismastersim or player.prefab ~= "characters prefabe name here" then        return playerend player.components.builder.ignorelist = { } function player.components.builder:AddIgnoreRecipe( recname )        self.ignorelist[ recname ] = recnameend function player.components.builder:RemoveIgnoreRecipe( recname )        self.ignorelist[ recname ] = nilend player.components.builder._CanLearn = player.components.builder.CanLearnfunction player.components.builder:CanLearn( recname )        local ret = self:_CanLearn(recname)    return ret and self.ignorelist[ recname ] == nilend  player.components.builder:AddIgnoreRecipe("torch") return player end)

This specific example will make it so a character cannot craft a torch. This all goes into the modmain.lua. Once again, another thanks to Ksizor for putting up with all my stupid problems.

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