Jump to content

[SOLVED! :D] What's the event for a character wearing a hat called?


Recommended Posts

I'm trying to make it so that my character gains more sanity from wearing garlands specifically. I had found code for sanity bonus from picking things (in my case, flowers), and I'm hoping I can apply it to increasing the sanity gain from wearing a garland. Does anyone know what the hat worn event is called?

EDIT: Would the code for altering the sainty gained from wearing a garland look like this?

inst:ListenForEvent(
			"puteventhere"
			function(inst, data)
				if(data and data.object and data.object.prefab=="flowerhat")
				then
					if(inst and inst.components and inst.components.sanity)
					then
						inst.components.sanity:DoDelta(put sanity change here)
					end
				end
			end
		)

 

Edited by poppychips
added code
Link to comment
Share on other sites

@poppychips There isn't an event specifically for hats, but there is an "equip" event that gets pushed to the player:

        self.inst:PushEvent("equip", { item = item, eslot = eslot })

The code you posted would not change the sanity gain, it would just give an instantaneous bump in sanity (that's what DoDelta does).

To change the sanity gain, you would have to modify the garland's equippable.dapperness value.

You should also listen for the unequip event to reset it to its original value afterwards.

Link to comment
Share on other sites

30 minutes ago, rezecib said:

@poppychips There isn't an event specifically for hats, but there is an "equip" event that gets pushed to the player:


        self.inst:PushEvent("equip", { item = item, eslot = eslot })

The code you posted would not change the sanity gain, it would just give an instantaneous bump in sanity (that's what DoDelta does).

To change the sanity gain, you would have to modify the garland's equippable.dapperness value.

You should also listen for the unequip event to reset it to its original value afterwards.

Ok, thanks! How would I change the dapperness value? (I'm guessing I'd just set it back to default when it's unequipped)

Link to comment
Share on other sites

@rezecib I did some googling around and this code is what I came up with. Would this work for what I'm trying to do? (also, do I have the right name for the hat slot? is it head or hat?)

self.inst:PushEvent("equip", { item = flowerhat, eslot = head })(
			inst.components.sanity.dapperness_mult = 1.2
			)
			
self.inst:PushEvent("unequip", { item = flowerhat, eslot = head })(
			inst.components.sanity.dapperness_mult = .83
			)

 

Edited by poppychips
(this would go in local master_postinit, right?)
Link to comment
Share on other sites

dapperness_mult applies to the dapperness of all equipped items. So if they were wearing a Hibearnation vest and a flower hat, then changing dapperness_mult would apply the multiplier to both.

Pushing the event will not do what you want. That code is also not syntactically correct, it will crash when the file is loaded.

What you want is to put something like this in your character's master_postinit:

local cached_dapperness = 0
inst:ListenForEvent("equip", function(inst, data)
	if data.item and data.item.prefab == "flowerhat" then
		cached_dapperness = data.item.components.equippable.dapperness
		data.item.components.equippable.dapperness = cached_dapperness * 1.2
	end
end)
inst:ListenForEvent("unequip", function(inst, data)
	if data.item and data.item.prefab == "flowerhat" then
		data.item.components.equippable.dapperness = cached_dapperness
	end
end)

 

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