Jump to content

Gain sanity at night/ lose sanity at day


Recommended Posts

I'm trying to work out a character that would gain sanity during nighttime and lose sanity during the day. So far I've compiled a few changes in the sanity component into another component. Here's the snippet with the changes I've made

 

[codesyntax] local light_delta = 0
local lightval = self.inst.LightWatcher:GetLightValue()

local day = TheWorld.state.isday and not TheWorld:HasTag("cave")

if night then
light_delta = TUNING.SANITY_DAY_GAIN
elseif dusk
local highval = TUNING.SANITY_HIGH_LIGHT
local lowval = TUNING.SANITY_LOW_LIGHT

if lightval < highval then
light_delta = TUNING.SANITY_NIGHT_LIGHT
elseif lightval > lowval then
light_delta = TUNING.SANITY_NIGHT_DARK
else
if day light_delta = TUNING.SANITY_NIGHT_MID
end

else day light_delta = light_delta*self.night_drain_mult
end
end[/codesyntax]

 

I tried adding it to my character's modmain to replace the normal sanity but making this true and the original sanity component false didn't work. I'd appreciate the help.

Link to comment
Share on other sites

I tried adding it to my character's modmain to replace the normal sanity but making this true and the original sanity component false didn't work. I'd appreciate the help.
Huh?? Not sure what you were trying to do, but it does not sound like the right thing ("making this true"?).

 

But I wouldn't replace the sanity component, as it's a replicable component (and tied to player_classified) and we can't mod those yet. There are a couple of approaches you could take... you could override Sanity:Recalc(dt) like this:

inst.components.sanity.Recalc = function(self, inst)    --your version of the recalc function hereend 

Alternatively, you could use sanity.dapperness, and tie it to the phase change event like so:

inst:WatchWorldState("isday", function(inst, val)    local mult = val and 1 or -2    inst.components.sanity.dapperness = mult*TUNING.SANITY_NIGHT_LIGHTend)

I think that should make it gain sanity equivalent to the dusk/night sanity drain during the dusk/night, but lose the same amount during the day. The multiplier for not-day is -2 so that it both cancels out the normal night drain (-1) and gives that amount on top of it.

 

The way you have yours written right now, if you were using the overriding Recalc approach, would negate sanity loss from being completely in the dark. Not sure if that's what you intended.

Link to comment
Share on other sites

Huh?? Not sure what you were trying to do, but it does not sound like the right thing ("making this true"?).

 

But I wouldn't replace the sanity component, as it's a replicable component (and tied to player_classified) and we can't mod those yet. There are a couple of approaches you could take... you could override Sanity:Recalc(dt) like this:

inst.components.sanity.Recalc = function(self, inst)    --your version of the recalc function hereend 

Alternatively, you could use sanity.dapperness, and tie it to the phase change event like so:

inst:WatchWorldState("isday", function(inst, val)    local mult = val and 1 or -2    inst.components.sanity.dapperness = mult*TUNING.SANITY_NIGHT_LIGHTend)

I think that should make it gain sanity equivalent to the dusk/night sanity drain during the dusk/night, but lose the same amount during the day. The multiplier for not-day is -2 so that it both cancels out the normal night drain (-1) and gives that amount on top of it.

 

The way you have yours written right now, if you were using the overriding Recalc approach, would negate sanity loss from being completely in the dark. Not sure if that's what you intended.

 

 

Thank you for the help. With true/false I was trying to get the game to recognize my custom sanity file instead of the original one but if it can't be overwritten then that won't work. I'll try out your suggestions and post results here.

 

Side note: Yes, I was trying to negate sanity loss in the dark and have daytime drain his sanity instead.

 

Link to comment
Share on other sites

@Gian383 Might not be exactly what your looking for but I managed to get my character to do what your looking for with a function. Kinda based on Willow's.

local function sanityfn(inst)local delta = 0if TheWorld.state.isday thendelta = -0.25elseif TheWorld.state.isdusk thendelta = 0.5elseif TheWorld.state.isnight thendelta = 0.95endreturn deltaend

with a

inst.components.sanity.custom_rate_fn = sanityfn

in the master post.init

 

Link to comment
Share on other sites

Not sure what you were trying to do, but you only need these two lines for sanity swap:

inst.components.sanity.night_drain_mult = -14 --Sanity gained at night.inst.components.sanity.dapperness = TUNING.DAPPERNESS_SMALL * (-8) --Sanity lost during the day.

Those number are major gain/drain numbers I use in my mod, you'll probably want to lower them a bit. Make sure both numbers stay negative, otherwise you'll gain during the day, and lose at night.

Link to comment
Share on other sites

Here :

local function updatestats(inst)   if TheWorld.state.phase == "day" then      inst.components.sanity.dapperness = (TUNING.DAPPERNESS_SMALL * -5)     elseif TheWorld.state.phase == "dusk" then      inst.components.sanity.dapperness = (TUNING.DAPPERNESS_SMALL * 3)   elseif TheWorld.state.phase == "night" then      inst.components.sanity.dapperness = (TUNING.DAPPERNESS_SMALL * 8)   endend
Link to comment
Share on other sites

Don't forget to call it on your fontion, like this :

inst:WatchWorldState( "startday", function(inst) updatestats(inst) end )inst:WatchWorldState( "startdusk", function(inst) updatestats(inst) end )inst:WatchWorldState( "startnight", function(inst) updatestats(inst) end ) updatestats(inst)return inst

Place this at the end of the fonction where "inst.soundsname" is called =)
Cya !

Link to comment
Share on other sites

@Gian383 Might not be exactly what your looking for but I managed to get my character to do what your looking for with a function. Kinda based on Willow's.

local function sanityfn(inst)local delta = 0if TheWorld.state.isday thendelta = -0.25elseif TheWorld.state.isdusk thendelta = 0.5elseif TheWorld.state.isnight thendelta = 0.95endreturn deltaend

with a

inst.components.sanity.custom_rate_fn = sanityfn

in the master post.init

 

thank you very much, this is exactly what I was looking for!

Also thanks to everyone who provided answers for me, I appreciate it very much so. I can confirm that all of the code you've provided works, though the one I'm quoting above does exactly what I intended to make out of it.

 

Once more, thanks.

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