Jump to content

General use haunt behavior question


Recommended Posts

So I have been toiling around with an idea as a small QoL for people that can't help but put things in their backpack.

The scenario is simple: Leaving a life giving amulet in a backpack is far from unusual, the issue arises where if a player dies and the amulet is in the backpack it is useless to them. I want to make it so when a player haunts the backpack it can drop the amulet from the backpack. I am unaware if there is a way to define this behavior over all items with the container component, so any help would be greatly appreciated.

Link to comment
Share on other sites

For that you need to override the 'onhaunt' function from the hauntable component:

AddPrefabPostInit("backpack", function(inst)
	if not GLOBAL.TheWorld.ismastersim then
		return
	end

	if inst.components.hauntable then
		inst:RemoveComponent("hauntable") -- Remove it first to add it properly later
	end

	AddNewOnHaunt(inst) -- Set up new hauntable
end)

The AddNewOnHaunt:

local function AddNewOnHaunt(inst)
	inst:AddComponent("hauntable") -- Add the hauntable component

	inst.components.hauntable.onhaunt = DropRevivers -- Set up new 'onhaunt'
end

The DropRevivers:

local function DropRevivers(inst, doer)
	inst.components.container:DropEverythingWithTag("resurrector") -- Drop everything that has the 'resurrector' tag, so the Life Giving Amulet
end

 

Put all of this in modmain.lua and it should work.

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