Sign in to follow this  
MrDoge124

I need help with sanity based light.

Recommended Posts

MrDoge124    3

Hello I would like some help.

I would like my character to have a light that goes down with his sanity.

I have got the light working but I don't know how to make it go down with his sanity.

Share this post


Link to post
Share on other sites
HabdomeRaider    150

You'll want to take a look at rabbit.lua to see how the rabbits respond to your sanity to turn into beardlings. Specifically the WatchSanity function that gets called by OnPickup. You'll probably want to call WatchSanity in an OnEquip function and StopWatchingSanity in OnUnequip.

Share this post


Link to post
Share on other sites
--- -.-    3602

I think you would put something like this in YOURCHARACTER.lua inside the master_postinit ;)~

inst:ListenForEvent("sanitydelta", function(inst, data)
   if inst.components.sanity.current >= 150 then
      -- Set max light level
   elseif inst.components.sanity.current >= 100 then
      -- Lower light level
   elseif inst.components.sanity.current >= 50 then
      -- Lower light level
   elseif inst.components.sanity.current <= 50 then
      -- Set min light level
   end
end)

 

Share this post


Link to post
Share on other sites
On 2/5/2017 at 10:31 PM, SuperDavid said:

I think you would put something like this in YOURCHARACTER.lua inside the master_postinit ;)~


inst:ListenForEvent("sanitydelta", function(inst, data)
   if inst.components.sanity.current >= 150 then
      -- Set max light level
   elseif inst.components.sanity.current >= 100 then
      -- Lower light level
   elseif inst.components.sanity.current >= 50 then
      -- Lower light level
   elseif inst.components.sanity.current <= 50 then
      -- Set min light level
   end
end)

 

This ought to work, you can alternatively call an outside function which is basically the same method.

 

local function sanitylight(inst)
	if inst.components.sanity.current >= 150 then
		inst.Light:SetIntensity(0.5)
		inst.Light:SetRadius(0.9)
		inst.Light:SetFalloff(0.5)
	elseif inst.components.sanity.current >= 100 then
      -- Lower light level
		inst.Light:SetIntensity(0.5)
		inst.Light:SetRadius(0.9)
		inst.Light:SetFalloff(0.5)
	elseif inst.components.sanity.current >= 50 then
      -- Lower light level
		inst.Light:SetIntensity(0.5)
		inst.Light:SetRadius(0.9)
		inst.Light:SetFalloff(0.5)
	elseif inst.components.sanity.current <= 50 then
      -- Set min light level
		inst.Light:SetIntensity(0.5)
		inst.Light:SetRadius(0.9)
		inst.Light:SetFalloff(0.5)
	end
end
                                              
--Put this part in Master Post Init
inst:ListenForEvent("sanitydelta", sanitylight)

Then just change the light settings to whatever you want for each stage like SuperDavid mentioned.

Share this post


Link to post
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
Sign in to follow this