Jump to content

Recommended Posts

Hello, me again, working on someone else's mod this time.

I'm making a tool for a character mod. It's a needle that, when held in the hand slot, allows the character to craft special clothing. Crafting with the needle causes the needle's durability to go down.

I've gotten it working for the most part, but hit a snag with the durability depletion.

Looking at the green amulet's code, I found this in OnEquip:

Quote

 inst.onitembuild = function()
        inst.components.finiteuses:Use(1)
    end
    inst:ListenForEvent("consumeingredients", inst.onitembuild, owner)

...which works as a foundation. However, I don't know how to check for what item is being crafted so the game knows whether or not to reduce the needle's durability. Currently it depletes no matter what is being crafted, just like the green amulet.

Is there any straightfoward way to add a check for a tag or a prefab name to this function so that the needle depletes properly? Since this is someone else's mod I'm helping with, I want to give it a fair shot before restorting to making the needle function differently to what they want.

Thanks for reading.

Edited by Chesed

You can listen for the event "builditem" instead of "consumeingredients". 

inst.onitembuild = function(player,data)
	if data and data.recipe and data.recipe.name == "your_recipe_name" then
		inst.components.finiteuses:Use(1)
	end
end
inst:ListenForEvent("builditem", inst.onitembuild, owner)

This should work I think :)

  • Thanks 1

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