Jump to content

[Help] Character mod coding: overheating and sanity regen


Recommended Posts

This is my first time making a character mod and I've never had much experience with coding.

I want to have a character who is close to immune to overheating and gains sanity slowly while the temperature is high but is weak to cold and freezes very quickly, would anyone be able to explain how I could achieve that or something close to it?

Also as I side note, how would i go about making the character lose sanity when they attack creatures?

Thanks in advance!

Link to comment
Share on other sites

I actually have very similar things in my own mod :D So here ya go, this is what you'll need: 

To make your character lose sanity each time it'll attack something, you need to head to your character's prefab file and add this somewhere below your character's stats.

    local function OnHit(inst,data)
        inst.components.sanity:DoDelta(-1)
    end
    inst:ListenForEvent("onhitother",OnHit)
    
You can of course change the "-1" to whatever other sanity damage you wish your character to take. 

To make your character almost immune to overheating, you can go in 2 different ways about it, it all depends what effect exactly you'll wish to have on your character.
If you want your character to still be able to overheat but simply do it very slowly, then add this line in your character's prefab file along with your character's stats

    inst.components.temperature.inherentsummerinsulation = 200
    
This will slow the time in which your character will start to overheat.
You can increase the number "200" if you want your character to overheat even slower.

However, if you want your character to be literally immune to overheating then you will need to change your character's max temperature range 
(Character start overheating when they reach the temperature of 70)
So again, in your character's prefab file, add this along with your character's stats.

    inst.components.temperature.maxtemp = ( 65 )
    
This will make your character be unable to overheat but still show the "sweating" animation
(if you don't want your character to show that animation then simply change the max temperature to 60 instead)

Now, To make your character gain sanity from temperature you'll need this.
This also goes into your character's prefab file, place it somewhere below your character's stats

    local function CheckTemperature(inst)
        if inst.components.temperature then            
            local t = inst.components.temperature
            if t:GetCurrent() > 64 and not inst:HasTag("heating") then
                inst:AddTag("heating")
                inst.components.sanity.dapperness = TUNING.SANITYAURA_TINY*2
            end
            if t:GetCurrent() < 64 and inst:HasTag("heating") then
                inst:RemoveTag("heating")
                inst.components.sanity.dapperness = 0
            end            
        end
    end
    inst:DoPeriodicTask( 0.0, function(inst)  --This will keep on checking your character's current temperature.
        CheckTemperature(inst)
    end)

You can change the number "*2" next to "TUNING.SANITYAURA_TINY" if you want to increase or lower the amount of sanity your character will be gaining.

And if you want your character to be fragile to cold then you can play with the max temperature range again. 
(character's start freezing when they reach temperature 0 )
(You can use the code I made for my own character. This is just copy paste from my own mod XD with few changes)
Same as everything else, this also goes to your character's prefab file, somewhere below your character's stats.

    inst:ListenForEvent("seasonChange", function(it, data)
        if data.season == SEASONS.WINTER then
            inst.components.temperature.maxtemp = ( 6 )
        end
        if data.season == SEASONS.SPRING then
            inst.components.temperature.maxtemp = ( 65 )
        end
        if data.season == SEASONS.AUTUMN then
            inst.components.temperature.maxtemp = ( 65 )
        end
        if data.season == SEASONS.SUMMER then
            inst.components.temperature.maxtemp = ( 65 )
        end        
    end, GetWorld())
    
This will change your character's max temperature range depending on the season.
(But this also means that your character will be unable to get too warm during winter

I hope this helps ^-^
And good luck with your 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...