Jump to content

How do I fix temperature overlay for client? (Overheating/Freezing)


Recommended Posts

Hello, I'm working on a mod character with custom overheating and freezing temperature.
So I've been tweaking on the temperature component and the overlay widgets.

For example:
If my character has the overheating temp at 75.
The widget should start catching the heat ring in four stages, at  {70, 75, 80, 85}  instead of  {65, 70, 75, 80}
The damage arrow will appear at 75 and start damaging the player.

It work perfectly fine on hosting without cave.


However, the widget doesn't seems to work when it comes to server with cave. 
The ring start catching at 70 as a second stage instead, as well as the damaging arrow
Even though my character doesn't take any damage yet.

Is there a way to fix this? So the second stage and damage arrow only appear at the threshold it should be.

Spoiler

Here is how I modified the temperature component. So that I can have my custom freezing temperature instead of 0

AddComponentPostInit('temperature', function(self)
    -- if not GLOBAL.TheWorld.ismastersim then
    --     return
    -- end

    local temperature = self
    temperature.freezingtemp = 0

    temperature.SetTemperature = function(self, value)
        local last = self.current
        self.current = value

        if (self.current < self.freezingtemp) ~= (last < self.freezingtemp) then
            self.inst:PushEvent(self.current < self.freezingtemp and "startfreezing" or "stopfreezing")
        end

        if (self.current > self.overheattemp) ~= (last > self.overheattemp) then
            self.inst:PushEvent(self.current > self.overheattemp and "startoverheating" or "stopoverheating")
        end

        self.inst:PushEvent("temperaturedelta", { last = last, new = self.current })
    end

    temperature.IsFreezing = function(self)
        return self.current < self.freezingtemp
    end

    local old_OnUpdate = temperature.OnUpdate
    temperature.OnUpdate = function(self, dt, applyhealthdelta)
        old_OnUpdate(self, dt, applyhealthdelta)
        if applyhealthdelta ~= false and self.inst.components.health ~= nil then
            if self.current >= 0 and self.current < self.freezingtemp then
                self.inst.components.health:DoDelta(-self.hurtrate * dt, true, "cold")
            end
        end
    end
end)


As for the widget (heatover), I only modified the ownerTemp and the all_up_thresh. (The same goes to iceover for freezing)

local function ModifyHeatOver(widget)

    local TheWorld = GLOBAL.TheWorld
    local TheFrontEnd = GLOBAL.TheFrontEnd

    function widget.OnHeatChange(self)
        local temp = self.owner.components.temperature ~= nil
            and self.owner.components.temperature:GetCurrent()
            or (self.owner.player_classified ~= nil and
                self.owner.player_classified.currenttemperature or TUNING.STARTING_TEMP)

        local num_steps = 4

        local overheattemp = self.owner.components.temperature and self.owner.components.temperature.overheattemp or self.owner.overheattemp:value()

        -- local minimumThresh = ownerTemp ~= nil and ownerTemp.overheattemp - 5 or 65
        local all_up_thresh = {overheattemp - 5, overheattemp, overheattemp + 5, overheattemp + 10}

        local heat_sounds =
        {
            "dontstarve_DLC001/common/HUD_hot_level1",
            "dontstarve_DLC001/common/HUD_hot_level2",
            "dontstarve_DLC001/common/HUD_hot_level3",
            "dontstarve_DLC001/common/HUD_hot_level4",
        }
        local heat_sounds_names =
        {
            "HUD_hot_level1",
            "HUD_hot_level2",
            "HUD_hot_level3",
            "HUD_hot_level4",
        }
        --local all_down_thresh = {8, 3, -2, -7}

        local up_thresh = all_up_thresh[self.laststep+1]
        local down_thresh = all_up_thresh[self.laststep]

        local isup = false
        while all_up_thresh[self.laststep+1] ~= nil and
            temp > all_up_thresh[self.laststep+1] and
            self.laststep < num_steps
            -- and (temp >= 65 or TheWorld.state.issummer or GetLocalTemperature(self.owner) >= 65)
            do

            self.laststep = self.laststep + 1
            isup = true
        end

        if isup then
            -- Check if the sound is playing so it doesn't get spammed when temp dances back and forth across the threshold
            if not TheFrontEnd:GetSound():PlayingSound(heat_sounds_names[self.laststep]) then
                TheFrontEnd:GetSound():PlaySound(heat_sounds[self.laststep], heat_sounds_names[self.laststep])
            end
        else
            while all_up_thresh[self.laststep] ~= nil and
                temp < all_up_thresh[self.laststep] and
                self.laststep > 0 do

                self.laststep = self.laststep - 1
            end
        end

        if self.laststep == 0 then
            self.alpha_min_target = 1
        else
            local alpha_mins =
            {
                .4, .3, .1, 0
            }
            self.alpha_min_target = alpha_mins[self.laststep]
            local distortion_size =
            {
                0.01, 0.011, 0.012, 0.013
                --0.01, 0.01, 0.01, 0.01
            }
            self.effectSize_target = distortion_size[self.laststep]
            local distortion_frequency =
            {
                10, 13, 17, 20
            }
            self.effectFrequency_target = distortion_frequency[self.laststep]
            local distortion_speed =
            {
                -- keep this value constant for now as both lerping and stepping it produce ugly artifacts
                7, 7, 7, 7
            }
            self.effectSpeed = distortion_speed[self.laststep]
            --self.effectSpeed_target = distortion_speed[self.laststep]
            self:StartUpdating()
        end
    end
end

AddClassPostConstruct("widgets/heatover", ModifyHeatOver)

AddPlayerPostInit(function(inst)
    inst.overheattemp = GLOBAL.net_shortint(inst.GUID,"overheattemp")
    inst.freezingtemp = GLOBAL.net_shortint(inst.GUID,"freezingtemp")

    if not TheNet:GetIsClient() and inst.components.temperature then
        inst.overheattemp:set(inst.components.temperature.overheattemp)
        inst.freezingtemp:set(inst.components.temperature.freezingtemp)
    end
end)

 

 

Edited by Webberah
change topic name a bit
Link to comment
Share on other sites

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
 Share

×
  • Create New...