Jump to content

How to make my item can only be taken by my character

Recommended Posts

Oh, a problem I know the solution to! I'm assuming it's about a custom item.

If you want to create a recipe that's only available to a specific character to craft, create a coding like this and add it to your modmain.lua's bottom:


AddRecipe("name_of_the_item",{ Ingredient("first_ingredient_name", quantity), Ingredient("second_ingredient_name", quantity)}, tab_name, tech_level,nil,nil,nil,1,"required_tag_for_craft", "images/inventoryimages/name_of_the_item.xml", "name_of_the_item.tex")

The red part is where you can add what tag is required to make the recipe appear for the survivors.

If you want to make the custom item tag restricted, add this to your item's prefab file. You should add it inside the local function fn(Sim) part under the inst.entity:SetPristine() part.


inst.components.equippable.restrictedtag = "required_tag_for_craft"
inst.components.equippable:SetOnEquip( OnEquip )
inst.components.equippable:SetOnUnequip( OnUnequip )

If it's not a custom item, come back for a refund.

Edited by C_Thun
Link to comment
Share on other sites

C_Thun pretty much beat me to what I was thinking, but I can also go over how to make it only useable by your character. Assuming this is an equippable item (otherwise I'm not sure why it would be restricted)

You can have the game check who is equipping the item, and if it's not the character you want, drop the item. You can add this function into your item's file, or add the contents of the function to an already existing OnEquip function. Just replace "kaji" with your character's name

local function OnEquip(inst, owner)
	if owner.prefab ~= "kaji" and owner.components.inventory ~= nil then

Haven't tested this at all but it's similar to a character function I've used before, so I think it should work

Link to comment
Share on other sites

I've created a guidebook and tutorial collection about character modding.  It features some extras as well - including custom items. Most of the extra chapters are just collected links to previous awesome tutorials.

Check out the chapters you're interested in:


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

  • Create New...