Jump to content

Recommended Posts

Hi! i'm making another mod character, and I was trying to setup one of their mechanics.

Basically, they have a hunger bar of 300, and the more full their hunger is the higher their insulation and damage resistance is.

The math basically being Current Hunger/300-.2 for Damage Resistance, and Current Hunger-60 for Insulation.

I got the damage resistance mechanic working great, 80% resistance at 300 hunger and 0% at 60 and below, but I'm not sure how to properly test if the insulation works the way I want it to. Its supposed to be 240 Insulation(equal to a Hibearnation Vest or Eyebrella) at 300 hunger, but 0 at 60.

Is there a way to check what my current insulation stat is? Or do I need to just be in Winter and see if I freeze faster or slower with it?

Followup question. I know that apparently, Winter Insulation and Summer Insulation are both different, and turn off during each other's seasons. So would this code be correct to have the insulation work the same for both seasons? I want the insulation mechanic to help with resisting both Heat and Cold, as its based on the Thick Fat ability from Pokemon.

-- Maybe this does it.
       inst:ListenForEvent("hungerdelta", function(inst, data)
	-- I think this is resist.
	inst.components.health:SetAbsorptionAmount(inst.components.hunger.current/300-0.2)

	-- I think this is insulation.
	inst.components.temperature.inherentinsulation = (inst.components.hunger.current-60)
    inst.components.temperature.inherentsummerinsulation = (inst.components.hunger.current-60)
	end)

I have that in the master_postinit section, but I also have this next bit of code earlier in the lua file.

local function onhungerchange(inst, data, forcesilent)

	-- I think this is resist.
	inst.components.health:SetAbsorptionAmount(inst.components.hunger.current/300-0.2)

	-- I think this is insulation.
	inst.components.temperature.inherentinsulation = (inst.components.hunger.current-60)
    inst.components.temperature.inherentsummerinsulation = (inst.components.hunger.current-60)

end

And I'm not sure if I need both or if I should remove one. My main worry though is like, making sure that the insulation works for both summer and winter, and changes properly with hunger.

Edited by PocketPossum

What you do for temperature doesn't work because it seems that inherent insulation doesn't affect the rate for some reason.

 

For the first problem, you can use 

player_inst.components.temperature:GetCurrent()

For view the temperature you can use this mod: Combined Status (modified) server version

Now, I recommend that you control the temperature by using a beard for your character, that is, not literally giving him a beard, but using the beard component to regulate the temperature as you want since it is the most organic way to manage it without modifying things in the game.

The code handles the temperature like this:

if self.inst.components.beard ~= nil then
  --Beards help winterInsulation but hurt summerInsulation
  winterInsulation = winterInsulation + self.inst.components.beard:GetInsulation()
  summerInsulation = summerInsulation - self.inst.components.beard:GetInsulation()
end

and this is how insolation is calculated:

self.rate = math.min(self.delta, TUNING.SEG_TIME / (TUNING.SEG_TIME + summerInsulation))
self.rate = math.max(self.delta, -TUNING.SEG_TIME / (TUNING.SEG_TIME + winterInsulation))

Use this function to graph the change relative to X (Summer or winter insulation value), as it's not a very intuitive function. Remember that this only calculates the change per second.

image.png.c4f36bd35fa25f8df6821adce771de32.png

2 hours ago, FerniFrenito said:

What you do for temperature doesn't work because it seems that inherent insulation doesn't affect the rate for some reason.

 

For the first problem, you can use 

player_inst.components.temperature:GetCurrent()

For view the temperature you can use this mod: Combined Status (modified) server version

Now, I recommend that you control the temperature by using a beard for your character, that is, not literally giving him a beard, but using the beard component to regulate the temperature as you want since it is the most organic way to manage it without modifying things in the game.

The code handles the temperature like this:

if self.inst.components.beard ~= nil then
  --Beards help winterInsulation but hurt summerInsulation
  winterInsulation = winterInsulation + self.inst.components.beard:GetInsulation()
  summerInsulation = summerInsulation - self.inst.components.beard:GetInsulation()
end

and this is how insolation is calculated:

self.rate = math.min(self.delta, TUNING.SEG_TIME / (TUNING.SEG_TIME + summerInsulation))
self.rate = math.max(self.delta, -TUNING.SEG_TIME / (TUNING.SEG_TIME + winterInsulation))

Use this function to graph the change relative to X (Summer or winter insulation value), as it's not a very intuitive function. Remember that this only calculates the change per second.

image.png.c4f36bd35fa25f8df6821adce771de32.png

I'm a lil confused honestly? I'm not sure how to make use of this for what I'm trying to do. Like, I'm not sure what to do to actually add the beard, or how to modify it to get the insulation I want from this?

Also, I wound up testing to see if my coding for insulation worked to slow or speed up temperature change, and it seems like it works? At full hunger it takes a long time to get cold or overheat, but at low hunger the temperature changes pretty fast. So I'm a lil confused what you meant by the inherent insulation not affecting the rate.

 

That said! Thank you for the mod recommendation and how to track my temperature. It did help with testing.

Edited by PocketPossum
31 minutes ago, PocketPossum said:

I'm a lil confused honestly? I'm not sure how to make use of this for what I'm trying to do. Like, I'm not sure what to do to actually add the beard, or how to modify it to get the insulation I want from this?

Also, I wound up testing to see if my coding for insulation worked to slow or speed up temperature change, and it seems like it works? At full hunger it takes a long time to get cold or overheat, but at low hunger the temperature changes pretty fast. So I'm a lil confused what you meant by the inherent insulation not affecting the rate.

forget it, it works just as you are doing, only since the code takes the minimum between the formula and self.delta, the inherent isolation in some cases does not affect the rate because the value of self.delta is taken instead of the one calculated with the inherent isolation

Answering your other question from the original post, yes, you can use the same logic for both temperatures, since apparently if a specific value causes the temperature to rise in winter, it will cause it to fall in summer, or at least that's what it seems. You just have to change self.inherentinsulation to self.inherentsummerinsulation

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