Jump to content

Negative sanity aura near some prefabs ?


Recommended Posts

Hi,

I want the character i'm working on to lose sanity near moles (because they steal treasure). So as far as i understand i must search entities to search for moles, right ? How do i do this ?

 

Thanks for the help :)

Link to comment
Share on other sites

Use custom_rate_fn in your character's master_postinit:

inst.components.sanity.custom_rate_fn = sanityfn

Define a sanityfn in your character file that uses TheSim:FindEntities:

TheSim:FindEntities(x, y, z, radius, MUSTHAVETAGS, CANTHAVETAGS, MUSTHAVEONETAG)

MUSTHAVETAGS, CANTHAVETAGS and MUSTHAVEONETAG should be tables containing all tags to look for (and, not and or respectively).

So something like:

local function sanityfn(inst)
	local x, y, z = inst.Transform:GetWorldPosition()
	local ents = TheSim:FindEntities(x, y, z, TUNING.SANITY_EFFECT_RANGE, {"mole"})
	local delta = 0
	for k, v in pairs(ents) do
		local distsq = math.max(inst:GetDistanceSqToInst(v), 1)
		delta = delta - TUNING.SANITYAURA_SMALL / distsq
	end
	return delta
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...