Jump to content

Help: Cave and Surface Sanity


Automb

Recommended Posts

Hello! Doing a character mod and need some help with the perks. Right now as it stands, the characters perks should be:

  • Loses sanity above ground
  • Doesn't lose sanity in the caves and ruins so long as he has some light: ex, a torch, fire anything so he isn't in complete darkness
  • Comes with a lantern as a starter item

Looking at tutorials and threads in this forum, I haven't run across anything like the cave sanity or surface sanity thing so I'm reaching out to you guys for help again.

 

I'm not sure if the caves have their own sanity code or if it is just branched into the darkness code. Same for the surface, if the light is it's own thing or if it factors into the daytime. Looking into the 'cave.lua' I didn't see anything that referred to sanity.

And I just can't figure out how to set up the coding for having the lantern be a starter item.

 

Thank you!

Link to comment
Share on other sites

Check for whether the character is underground with if not GetWorld():HasTag("cave") then ... end (this also applies to ruins)

you can set a negative dapperness value in sanity to cause the character to get into a froth.

 

Set night_drain_mult from sanity to zero to eliminate the sanity loss even while in light, though this may affect total darkness too. In that case you should add so-called event listeners (similiar to how they're used in grue.lua) to update the multiplier.

 

You can make a table (the thing with swirly brackets) that lists starter items, and reference it in the function at the end of the character file. Other character mods surely can show you how to do that.

 

Look for similiar mods and study them, if you ever get swamped. To be fair, I can't find any mod that would help with the first two perks either.

Link to comment
Share on other sites

check in sanity.lua for the  Recalc() method.  This is what you will want to alter to have it check for your specific situation.  The best way to do that in my opinion is to have your modmain look somewhat like:

-- 'self' is the component, not the player instance. local function MySanityRecalc( self, dt )   //copy original recalc code here and adjust to fit your goalsendAddPlayerPostInit( function(inst)   if inst.prefab == "yourCharacter" then      inst.components.sanity.Recalc = MySanityRecalc   endend)

The original recalc has very clear sections for handling how much adjustment is based on light levels or other factors. The logic is pretty simple so read it over a few times and you should be able to get your goals to work

 

-edit-

 

Figure id add another point.  While reading the Recalc method you might notice at the bottom there is a check for a custom rate method.  You could set this to your custom function, but i still recommend just replacing the recalc method entirely with what you need to do.  The reason is that the adjusted function has its rate applied in ADDITION to what Recalc() computes, not INSTEAD of it. So since you want to utterly remove some rates you nee the full replacement.

Link to comment
Share on other sites

Adding to what seronis said, you can also do that right in your prefab file. This way, you can keep all your character's functional code in one file, and won't have to test its prefab when initializing.

local function SanityRecalc(self, dt)    -- ...end-- ...-- In your create fn, where inst is the player instanceinst.components.sanity.Recalc = SanityRecalc
Link to comment
Share on other sites

@seronis

I don't think I understand this right, what is the base recalc code? Also would 'the surface' be considered anything but the caves and ruins, if so. How would it work to exempt the underground to only affect the surface?

Link to comment
Share on other sites

I don't think I understand this right, what is the base recalc code? Also would 'the surface' be considered anything but the caves and ruins, if so. How would it work to exempt the underground to only affect the surface?

 

Study the sanity component or Lua in general. And yes, everything that is not marked as a cave is considered the surface (there are no in-game areas other than the surface though, only the cloud realm from U&A mod)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...