KirbyJParasol Posted July 11, 2017 Share Posted July 11, 2017 I'm trying to make a pair of characters, one that is better in heat and worse in cold, while the other is better in cold and worse in heat. I noticed that the temperature.lua component in the base DST game has this line for beards: 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 This is exactly the kind of argument I'm looking for; I want the characters to have inherent insulation that benefits during one season, but harms in the other. How do I program such a thing into my characters? Link to comment Share on other sites More sharing options...
alainmcd Posted July 11, 2017 Share Posted July 11, 2017 inst.components.temperature.inherentinsulation and inst.components.temperature.inherentsummerinsulation seem to be what you're looking for. Link to comment Share on other sites More sharing options...
KirbyJParasol Posted July 11, 2017 Author Share Posted July 11, 2017 Thanks, but how do I get those to take negative values? When I tried putting a minus sign in front of the value, it just didn't recognize the value at all. Link to comment Share on other sites More sharing options...
alainmcd Posted July 11, 2017 Share Posted July 11, 2017 Insulation is never a direct penalty (because of return math.max(0, winterInsulation), math.max(0, summerInsulation) ), so the penalty for negative values for inherentinsulation or inherentwinterinsulation is that they make proper insulation less effective. If you want a negative to be applied regardless, you can try adding something like this in your master_postinit's (untested): local OldGetInsulation = inst.components.temperature.GetInsulation inst.components.temperature.GetInsulation = function(self) local a, b = OldGetInsulation(self) return a + TUNING.INSULATION_MED, b - TUNING.INSULATION_MED end and local OldGetInsulation = inst.components.temperature.GetInsulation inst.components.temperature.GetInsulation = function(self) local a, b = OldGetInsulation(self) return a - TUNING.INSULATION_MED, b + TUNING.INSULATION_MED end Link to comment Share on other sites More sharing options...
KirbyJParasol Posted July 11, 2017 Author Share Posted July 11, 2017 I'll give it the ol' college try and get back to you Link to comment Share on other sites More sharing options...
KirbyJParasol Posted July 11, 2017 Author Share Posted July 11, 2017 So, both those lines of code have the incredibly odd effect of RAISING my temperature during winter. Instead of messing with insulation levels, is there a way to adjust the temperature at which a character freezes? I know you can set the overheating temperature with (inst.components.temperature.overheattemp = x), but I've found no such easy fix for freezing, since it seems to just be below zero in the core temperature component file. Link to comment Share on other sites More sharing options...
alainmcd Posted July 11, 2017 Share Posted July 11, 2017 23 minutes ago, KirbyJParasol said: So, both those lines of code have the incredibly odd effect of RAISING my temperature during winter. Eh... the relevant code from the OnUpdate function in the Temperature component: if ambient_temperature >= TUNING.STARTING_TEMP then -- it's warm out if self.delta > 0 then -- If the player is heating up, defend using insulation. local winterInsulation, summerInsulation = self:GetInsulation() self.rate = math.min(self.delta, TUNING.SEG_TIME / (TUNING.SEG_TIME + summerInsulation)) else -- If they are cooling, do it at full speed, and faster if they're overheated self.rate = math.max(self.delta, self.current >= self.overheattemp and -TUNING.THAW_DEGREES_PER_SEC or -TUNING.WARM_DEGREES_PER_SEC) end -- it's cold out elseif self.delta < 0 then -- If the player is cooling, defend using insulation. local winterInsulation, summerInsulation = self:GetInsulation() self.rate = math.max(self.delta, -TUNING.SEG_TIME / (TUNING.SEG_TIME + winterInsulation)) else -- If they are heating up, do it at full speed, and faster if they're freezing self.rate = math.min(self.delta, self.current <= 0 and TUNING.THAW_DEGREES_PER_SEC or TUNING.WARM_DEGREES_PER_SEC) end It assumes winterInsulation and summerInsulation are non-negative. Since my proposed TUNING.INSULATION_MED is greater than TUNING.SEG_TIME, it messes up everything. Try this return a + TUNING.MY_POSITIVE_INSULATOR, b - TUNING.MY_NEGATIVE_INSULATOR and this return a - TUNING.MY_NEGATIVE_INSULATOR, b + TUNING.MY_POSITIVE_INSULATOR instead, where TUNING.MY_NEGATIVE_INSULATOR is strictly less than TUNING.SEG_TIME (30) and TUNING.MY_POSITIVE_INSULATOR is any positive value; define them somewhere in your code. Tune them as you see fit. You might want to keep TUNING.MY_NEGATIVE_INSULATOR small, keep using inherentinsulation and inherentsummerinsulation (positive and negative accordingly), and change TUNING.MY_POSITIVE_INSULATOR or remove it altogether. You should be able tune the values directly from the console. ThePlayer.components.temperature.inherentinsulation = -20 ThePlayer.components.temperature.inherentsummerinsulation = 100 TUNING.MY_POSITIVE_INSULATOR = 500 TUNING.MY_NEGATIVE_INSULATOR = 3 --silly test values -- 33 minutes ago, KirbyJParasol said: Instead of messing with insulation levels, is there a way to adjust the temperature at which a character freezes? I know you can set the overheating temperature with (inst.components.temperature.overheattemp = x), but I've found no such easy fix for freezing, since it seems to just be below zero in the core temperature component file. Silly idea: copy the whole temperature.lua to a new component file, say alttemp.lua, change a few zeroes to self.freezetemp, then add something like inst:RemoveComponent("temperature") inst:AddComponent("alttemp") inst.components.alttemp.freezetemp = -10 inst.components.temperature = inst.components.alttemp to your master_postinit and hope that it works. Link to comment Share on other sites More sharing options...
KirbyJParasol Posted July 13, 2017 Author Share Posted July 13, 2017 I apologize, I'm still pretty novice so I'm having trouble understanding that entire post. What should the code look like now...? Link to comment Share on other sites More sharing options...
alainmcd Posted July 13, 2017 Share Posted July 13, 2017 Tl;dr is that I screwed up before when suggesting b - TUNING.INSULATION_MED. The OnUpdate function governs how to update the player's temperature and it expects the GetInsulation function to return zero or positive values for winterInsulation and summerInsulation. Since TUNING.INSULATION_MED (120) is greater than TUNING.SEG_TIME (30), the line Quote self.rate = math.max(self.delta, -TUNING.SEG_TIME / (TUNING.SEG_TIME + winterInsulation)) from the OnUpdate function can result in a positive number instead of the negative expected, which ends up increasing your temperature when it's cold. So my suggestion is to use something like inst.components.temperature.inherentinsulation = 100 inst.components.temperature.inherentsummerinsulation = -20 local OldGetInsulation = inst.components.temperature.GetInsulation inst.components.temperature.GetInsulation = function(self) local a, b = OldGetInsulation(self) return a + TUNING.MY_POSITIVE_INSULATOR, b - TUNING.MY_NEGATIVE_INSULATOR end in your master_postinit for one of your characters, define TUNING.MY_POSITIVE_INSULATOR and TUNING.MY_NEGATIVE_INSULATOR anywhere in your code: TUNING.MY_POSITIVE_INSULATOR = 50 TUNING.MY_NEGATIVE_INSULATOR = 10 Spoiler If you're defining it in your modmain.lua, you need to add a GLOBAL: GLOBAL.TUNING.MY_POSITIVE_INSULATOR = 50 GLOBAL.TUNING.MY_NEGATIVE_INSULATOR = 10 Jump into the game and test it. Use the console commands I mentioned before to change the values on the fly and find what values fit you best. Remember that MY_NEGATIVE_INSULATOR should always be less than 30.Then do the same for the other character. Spoiler inst.components.temperature.inherentinsulation = -20 inst.components.temperature.inherentsummerinsulation = 100 local OldGetInsulation = inst.components.temperature.GetInsulation inst.components.temperature.GetInsulation = function(self) local a, b = OldGetInsulation(self) return a - TUNING.MY_NEGATIVE_INSULATOR, b + TUNING.MY_POSITIVE_INSULATOR end No need to define MY_POSITIVE_INSULATOR and MY_NEGATIVE_INSULATOR again. Use other constants if you want to use different values for your characters. -- Quote whatever parts of text or code you don't understand and I'll try to be clearer. Don't be afraid to ask, but do let me know what you think it could mean (if anything), so I can more or less know where you're at. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now