Jump to content

Question for Character perk


Recommended Posts

Is it possible to gain a sanity aura depending on someone ELSE'S sanity?

Example: there is a group of 3. Wendy, Wilson, and My character

  • Wendy is at the level of sanity where she can be attacked by shadows
  • Wilson is about middle of the road (he can see shadows, but not be attacked by them)
  • My character is at max sanity
  • My character walks to Wilson, nothing happens.
  • My character walks up to Wendy and BOTH Wendy AND Wilson start gaining sanity

Is this a possible thing to code? Or would this be a task too intense for the game?

Link to comment
Share on other sites

Place in the OnLoad or master_init function:

	local ic = inst.components
	if ic.sanityaura == nil then
		inst:AddComponent("sanityaura")
		ic.sanityaura.aura = TUNING.SANITYAURA_LARGE * ic.sanity:GetPercent()
	end
	inst:ListenForEvent("sanitydelta", function()
		if ic.sanityaura ~= nil then
			ic.sanityaura.aura = TUNING.SANITYAURA_LARGE * ic.sanity:GetPercent()
		end
	end)

EDIT: Okay, I didn't quite understand what you meant the first time, but after reading your post again, I seem to have made a mistake. The code above gives you a sanity aura depending on your own character's sanity, however you asked for a sanity aura that depends on someone else's sanity.

Edited by JohnWatson
Link to comment
Share on other sites

I haven't tested this yet, but try it anyway. OnLoad or master_init

	local restore_radius = 15 -- 'Check for players within this distance in metres'
	
	local ic = inst.components
	if ic.sanityaura == nil then
		inst:AddComponent("sanityaura")
	end
	if inst.checkForInsaneMates ~= nil then
		inst.checkForInsaneMates:Cancel()
		inst.checkForInsaneMates = nil
	end
	inst.checkForInsaneMates = inst:DoPeriodicTask(0.5, function()
		local x,y,z = inst.Transform:GetWorldPosition()
		local f = TheSim:FindEntities( x,y,z, restore_radius)
		local enableaura = false
		for k, v in ipairs(f) do
			local vc = v.components
			if vc ~= nil and vc.sanity ~= nil and (vc.sanity:GetPercent() <= 0.15) then
				enableaura = true
			end
		end
		ic.sanityaura.aura = TUNING.SANITYAURA_LARGE * ((enableaura==true and 1) or 0)
	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...