Jump to content

Recommended Posts

Hello! I'm one step away from finishing a character mod for Don't Starve, though I'm having problems with a perk I've been trying to add in.

See, I was planning on making it so that there was an unseen timer that, when at 2/3 would give you a minor sanity drain, when 1/3 it would give you a medium sanity drain, and when empty it would give you a major sanity drain. It would take three days for the full effect to take place, and could only be restored to maximum by medication, a custom item I was planning on implementing.

Unfortunately, my attempts on using Woodie's "Beaverness" meter weren't very good, so I've come to this community to see if anybody could help.

Thank you very much!

One way to do it is to add a new component to your project, e.g. sanitytimer.lua. This would be used to store the timer, update the timer and return the timer value when requested. Example:

 

local sanitytimer = Class(function(self, inst)
    self.inst = inst
    self.stimer = 1440 --Timer value. 1440 seconds = 24 minutes = 3 game days?
end)


function sanitytimer:GetSTimer() --Function to return the current timer count
	return self.stimer
end

function sanitytimer:SetTimer(amount) --Function to update timer
	self.stimer = amount
end

return sanitytimer

Then in your characters prefab you would need to add the component and have a periodic task which updates timer and checks the value

 

    local function CheckSTimer(inst)

        local sanitycounter = inst.components.sanitytimer:GetSTimer()
        
        if sanitycounter == 960 then
            --start minor sanity drain
        end
        
        if sanitycounter == 480 then
            --start med sanity drain
        end

        if sanitycounter == 1 then --use 1 instead of 0 so code isnt re-ran every second once timer is at 0
            --start major sanity drain
        end
    
        if sanitycounter > 0 then 
            inst.components.sanitytimer:SetTimer(sanitycounter-1)
        end
    end

    inst:AddComponent("sanitytimer")
    inst:DoPeriodicTask(1, CheckSTimer)

 

You'd also need to add onsave and onload code to store the timer count (stimer). Once medication is consumed you would reset the sanity drain and then reset the timer:

inst.components.sanitytimer:SetTimer(1440)

Probably much more efficient ways to do this but maybe it's helpful to get you started.

 

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