Jump to content

Recommended Posts

Hello, 

I'm a complete novice to Don't Starve modding, but I've done some research before starting my first character mod. I've gotten the basics down, but I've been struggling to add two perks for my character.

1)The character is supposed to have a higher freezing temperature (<5), but I've been struggling to implement it. I was originally going to go with their internal temperature dropping quicker, but that seemed way more complex. (I've already added 'inst.components.temperature.inherentinsulation' which I think affects how effective insulating clothing is.)

2)I also wanted to make it so that the sanity penalty from being wet and/or wearing wet clothing doesn't apply to the character. Tools slipping and the quicker freezing penalty would still apply when wet.

Any help would be appreciated, thanks. 

Edited by Scrumch

inst.components.temperature.inherentinsulation increases the character's inherent insulation, meaning they have extra insulation in addition to the insulation gained from clothes. That'll work for your purpose. The freezing temperature is hard-coded to 0, whereas you CAN change the overheat temperature. A bit annoying, but there you go. With the way the code is written, it's hard to change the freezing temperature without creating incompatibility with other mods.

Moisture sanity-loss is handled by the sanity component, and is another thing that's difficult to change without creating incompatibility with other mods, since the whole calculation for it uses the same functions in the moisture component that the rest of the game code uses to read moisture, as well as a tuning variable which is set by the server. The only thing you can do, is to counteract it, which is easy. Put this at the bottom of your character's master_postinit() or fn()

local oldRecalc = inst.components.sanity.Recalc
function inst.components.sanity:Recalc(dt)
	oldRecalc(dt)
	self.DoDelta(-easing.inSine(self.inst.components.moisture:GetMoisture(), 0, TUNING.MOISTURE_SANITY_PENALTY_MAX, self.inst.components.moisture:GetMaxMoisture()) * dt, true)
end

 

21 hours ago, Ultroman said:

inst.components.temperature.inherentinsulation increases the character's inherent insulation, meaning they have extra insulation in addition to the insulation gained from clothes. That'll work for your purpose. The freezing temperature is hard-coded to 0, whereas you CAN change the overheat temperature. A bit annoying, but there you go. With the way the code is written, it's hard to change the freezing temperature without creating incompatibility with other mods.

Moisture sanity-loss is handled by the sanity component, and is another thing that's difficult to change without creating incompatibility with other mods, since the whole calculation for it uses the same functions in the moisture component that the rest of the game code uses to read moisture, as well as a tuning variable which is set by the server. The only thing you can do, is to counteract it, which is easy. Put this at the bottom of your character's master_postinit() or fn()


local oldRecalc = inst.components.sanity.Recalc
function inst.components.sanity:Recalc(dt)
	oldRecalc(dt)
	self.DoDelta(-easing.inSine(self.inst.components.moisture:GetMoisture(), 0, TUNING.MOISTURE_SANITY_PENALTY_MAX, self.inst.components.moisture:GetMaxMoisture()) * dt, true)
end

 

Ah thanks for the scripting, I just need some more help. This is a single player character so I'm using the 'local fn =function(inst) part', right? But when I paste the code at the end of that local, the mod won't start up. Am I missing something?

 

image.png

Oh, and here's the log:

Spoiler

LUA ERROR stack traceback:
C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/components/sanity.lua:196 in (upvalue) oldRecalc (Lua) <195-262>
   self = 0.033333335071802
   dt = nil
C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/../mods/Takes-the-Shot/scripts/prefabs/wakes.lua:72 in (method) Recalc (Lua) <71-74>
   self =
      onInsane = function - @C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/prefabs/player_common.lua:8
      current = 200
      dapperness_mult = 1
      dapperness = 0
      max = 200
      rate = 0
      onSane = function - @C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/prefabs/player_common.lua:4
      night_drain_mult = 1
      inst = 100030 - wakes (valid:true)
      fxtime = 0
      Recalc = function - @C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/../mods/Takes-the-Shot/scripts/prefabs/wakes.lua:71
      penalty = 0
      neg_aura_mult = 1
      sane = true
   dt = 0.033333335071802
C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/components/sanity.lua:187 in (method) OnUpdate (Lua) <170-188>
   self =
      onInsane = function - @C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/prefabs/player_common.lua:8
      current = 200
      dapperness_mult = 1
      dapperness = 0
      max = 200
      rate = 0
      onSane = function - @C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/prefabs/player_common.lua:4
      night_drain_mult = 1
      inst = 100030 - wakes (valid:true)
      fxtime = 0
      Recalc = function - @C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/../mods/Takes-the-Shot/scripts/prefabs/wakes.lua:71
      penalty = 0
      neg_aura_mult = 1
      sane = true
   dt = 0.033333335071802
   speed = 0
   distortion_value = 1
C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/update.lua:157 in () ? (Lua) <90-191>
   dt = 0.033333335071802
   tick = 394
   k = 100030
   ent = 100030 - wakes (valid:true)
   prefab = wakes
   cmp = table: 24230000
   name = sanity

[00:00:52]: Last called Lua: luaUpdate
[00:00:52]: scripts/mainfunctions.lua(946,1) LUA ERROR stack traceback:
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/mainfunctions.lua(946,1)    
[00:00:52]: scripts/mainfunctions.lua(947,1) ...ommon/dont_starve/data/scripts/components/sanity.lua:196: attempt to index local 'self' (a number value)
LUA ERROR stack traceback:
    C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/components/sanity.lua:196 in (upvalue) oldRecalc (Lua) <195-262>
    C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/../mods/Takes-the-Shot/scripts/prefabs/wakes.lua:72 in (method) Recalc (Lua) <71-74>
    C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/components/sanity.lua:187 in (method) OnUpdate (Lua) <170-188>
    C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/update.lua:157 in () ? (Lua) <90-191>
    
[00:00:52]: scripts/frontend.lua(773,1) SCRIPT ERROR! Showing error screen    
[00:00:53]: CURL ERROR: couldn't connect to host at analytics-staging.office.kleientertainment.com:443
[00:00:53]: QueryServerComplete no callback
[00:00:53]: HttpClientWriteCallback (0x04C0F3E1, 1, 78, 0x0730FC90)
[00:00:53]: HttpClientWriteCallback READ 78 (78 total)
[00:00:53]: QueryServerComplete no callback
[00:00:58]: Force aborting...
 

 

Edited by Scrumch
local oldRecalc = inst.components.sanity.Recalc
function inst.components.sanity:Recalc(dt)
	oldRecalc(self, dt)
	self.DoDelta(-easing.inSine(self.inst.components.moisture:GetMoisture(), 0, TUNING.MOISTURE_SANITY_PENALTY_MAX, self.inst.components.moisture:GetMaxMoisture()) * dt, true)
end

I forgot to give oldRecalc "self" as a parameter :(

Also, this looks wrong:

5cbd9166b5b45_2019-04-2212_00_34-RainandFreezingPerksHelp-DontStarveModsandtools-KleiEntertainmen.png.28db0aabd0867ef90f47d3703a162b3f.png

I've written that into the code and it's liked that a bit more. However the log gave out the error '...ata/../mods/Takes-the-Shot/scripts/prefabs/wakes.lua:85: attempt to call method 'GetMaxMoisture' (a nil value)' which I assume mean I haven't declared the GetMaxMoisture variable? Is that supposed to happen?

Oh, dammit. That's my fault. I keep forgetting to check whether people are doing DS or DST. I'm so sorry.

Exchange this:

self.DoDelta(-easing.inSine(self.inst.components.moisture:GetMoisture(), 0, TUNING.MOISTURE_SANITY_PENALTY_MAX, self.inst.components.moisture:GetMaxMoisture()) * dt, true)

with this:

self.DoDelta(-self.inst.components.moisture:GetMoistureDelta() * dt, true)

Code for negating moisture sanity loss for a character

For completeness, I will post the complete code for both DS and DST below. It isn't perfect, since this code only fixes the problem reactively instead of proactively, but it should be good enough for most cases. If the character gets to 0 sanity, then all the original sanity loss applied by oldRecalc will be clamped to 0, and if the moisture delta is negative then we will be countering that moisture delta, even though the original loss was clamped. This means that the character will always have one frame of moisture_delta value on their sanity meter, and thus never hit 0 completely. I don't think this yields any problems, though. Let me know if it does, so I can change the code. Otherwise, you can just put in a check saying not to reverse the moisture delta if the current sanity after oldRecalc(self, dt) is 0.

DS

local oldRecalc = inst.components.sanity.Recalc
function inst.components.sanity:Recalc(dt)
	oldRecalc(self, dt)
	self.DoDelta(-self.inst.components.moisture:GetMoistureDelta() * dt, true)
end

DST

local oldRecalc = inst.components.sanity.Recalc
function inst.components.sanity:Recalc(dt)
	oldRecalc(self, dt)
	self.DoDelta(-easing.inSine(self.inst.components.moisture:GetMoisture(), 0, TUNING.MOISTURE_SANITY_PENALTY_MAX, self.inst.components.moisture:GetMaxMoisture()) * dt, true)
end

 

Edited by Ultroman

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
×
  • Create New...