Jump to content

Weapon Turning into Other Item when Broken


Recommended Posts

The title's the gist of it, I'm making a weapon with an armor value, but I want it to turn into an armorless version when it breaks.

I plan on making so that it can be turned back into the normal version, but that's as simple as making a custom craft recipe and I already know how to do that.

Link to comment
Share on other sites

you can remove the armor component, or you can take use the ReplacePrefab function. You can also take advantage of the perishable component, since the perishable:Perish() function checks whether the item is being held in an inventory or container and puts the replacement at the same spot.

Link to comment
Share on other sites

On 11/3/2021 at 11:49 PM, Bad Willow said:

its in main functions. it's only in dst though and not in ds. ds has another function whose name escapes me

Found it, but I have no idea how to tell the game to Listen for the weapon breaking. I think I've seen it somewhere, but I don't remember where.

Actually, I just realized something, shouldn't I have the weapon Listen for it breaking and then tell the game to spawn the broken version? Do I even need ReplacePrefab at all?

Link to comment
Share on other sites

21 hours ago, Bad Willow said:

you should probably look inside the finite uses component, there's an on finish callback function available there, or you can listen for the event of tool break, which I think the finite uses component pushes.

So like this?

inst:AddComponent("finiteuses")
	inst.components.finiteuses:onfinished = fn

And then make a Function that has SpawnPrefab?

Edited by icantevenname
Link to comment
Share on other sites

yeah i've also noticed the problem with the hud when doing a hamlet mod for the thunderhat recently, my solution ended up being using the timer component instead of the fueled component for a lightning charge level. you can either suffer the swap or try to work around one  of the components, for example, instead of using the armor component properly, trying to reduce damage in another way, such as a buff. as for the event, in my experience, declaring a function in a component is a lot more reliable than listening for an event, since sometimes the event is not pushed - an example of this is the equippable component where the onunequipfn can be called without the unequipped event pushed. but your code looks good to me.

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