Jump to content

How do I remove recipes that include a certain tag and component for a certain character?


Recommended Posts

So I'm working on making code for a character a friend of mine is making where the character is not able to equip any torso clothes or even craft them, but he's able to craft backpacks and armors and can also use them.

The equipping part is done, but the problem I'm having is with the code for removing recipes, as I'm trying to remove the recipes that do not include the backpack tag, do not count as armor but also are body slot items. However it keeps giving me an error in the line with removing the recipes and says that components is a "nil value".

The removal of recipes code:

	-- Removing every clothing recipes that exists for this character
	inst.components.builder.ignorelist = { }
	
	function inst.components.builder:AddIgnoreRecipe( recname )
		self.ignorelist[ recname ] = recname
	end

	function inst.components.builder:RemoveIgnoreRecipe( recname )
		self.ignorelist[ recname ] = nil
	end

	local old_CanLearn = inst.components.builder.CanLearn
	function inst.components.builder:CanLearn( recname )
		local ret = old_CanLearn(recname)
		return ret and self.ignorelist[ recname ] == nil
	end

	for k, v in pairs(AllRecipes) do
		if IsChestClothing(v.product) then inst.components.builder:AddIgnoreRecipe(v.name) end
	end

The code that crashed the game:

	local function IsChestClothing(item)
		if item.components.equippable and item.components.equippable.equipslot == EQUIPSLOTS.BODY and not item:HasTag("backpack") and not item.components.armor then
			return true
		else
			return false
		end
	end

Thanks in advance!

Link to comment
Share on other sites

'v.product' is of string type, and you're trying to index it as if it's a table.

I don't see a way to safely obtain this item information you're trying to request here.

It would be easier to make a blacklist of the torso items you don't want and check against the table.

local blacklist = {
    amulet = true,
    blueamulet = true,
    purpleamulet = true,
    orangeamulet = true,
    greenamulet = true,
    yellowamulet = true,
    beargervest = true,
    hawaiianshirt = true,
    onemanband = true,
    raincoat = true,
    reflectivevest = true,
    sweatervest = true,
    trunkvest_summer = true,
    trunkvest_winter = true,
}
if blacklist[v.product] then inst.components.builder:AddIgnoreRecipe(v.name) end

 

Link to comment
Share on other sites

On 2/18/2019 at 5:33 AM, CarlZalph said:

'v.product' is of string type, and you're trying to index it as if it's a table.

I don't see a way to safely obtain this item information you're trying to request here.

It would be easier to make a blacklist of the torso items you don't want and check against the table.


local blacklist = {
    amulet = true,
    blueamulet = true,
    purpleamulet = true,
    orangeamulet = true,
    greenamulet = true,
    yellowamulet = true,
    beargervest = true,
    hawaiianshirt = true,
    onemanband = true,
    raincoat = true,
    reflectivevest = true,
    sweatervest = true,
    trunkvest_summer = true,
    trunkvest_winter = true,
}

if blacklist[v.product] then inst.components.builder:AddIgnoreRecipe(v.name) end

 

I see,

So basically, there's no way to get item information from recipes (including modded recipes), right?

Thanks for the code, btw.

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