Jump to content

Sanity increase when fishing


Recommended Posts

I do not know how the script would look like for this, but I can recommend to look for mod in workshop with similiar perk and check it's script and/or check scripts of DS items, mechanics etc. in C:\Program Files (x86)\Steam\steamapps\common\dont_starve\data\scripts .

Link to comment
Share on other sites

You can add an external sanity modifier whenever your character starts to fish, and then remove it again when the fishing is stopped. Sadly, there is no event called when fishing starts. It's started by an action, but there is an event for when it stops fishing, called "fishingcancel" which is called on your player character.

You have a few options:

  1. Override the FISH action and make it call an event, e.g., "fishingstart" on act.doer, whenever the action is performed. (probably unnecessarily intrusive)
  2. Accept that the sanity boost only starts when a fish starts nibbling (because there's an event for that, "fishingnibble") and stops when "fishingcancel" is called. (possibly not an acceptable compromise, since the time between nibbling and catching the fish is very short compared to the time you have to wait for the fish to start nibbling)
  3. Use a periodic task to check whether the character is currently fishing, to make it start almost as soon as the fishing action is performed, and use the "fishingcancel" event to stop it again.

Neither of those are hard to do. The third one may be a bit tricky, but it's the most flexible one, and even though we want to use as few periodic tasks as possible, this one is very simple and won't eat up a lot of CPU because of its simple functionality. This code starts a never-ending periodic task (the outer one) which just checks whether the fishing regen task is currently running and whether the state-tag says that the character is fishing, and if the regen is already running or the character is not fishing, we do not want to do anything, but otherwise we want to start the regen. The regen task is simple in itself, and we simply cancel the task whenever the "fishingcancel" event is called (our ListenForEvent), since the event is called whenever the fishing ends (whether successful or not). You can adjust the intervals between the regens by changing the first parameter of the innermost DoPeriodicTask function inside the inst.fishingRegenTask function (see the comments).

inst:ListenForEvent("cancelfishing", function(inst)
	if inst.fishingRegenTask then
		inst.fishingRegenTask:Cancel()
	end
end)

-- 1.0 is the amount of seconds between running the function, so this check runs every 1.0 seconds
inst:DoPeriodicTask(1.0, function(inst)
	if not inst.fishingRegenTask and inst.sg:HasStateTag("fishing") then
		-- 1.0 is the amount of seconds between running the function, so this regen runs every 1.0 seconds
		inst.fishingRegenTask = inst:DoPeriodicTask(1.0, function(inst)
			-- 1 means it adds 1 sanity
			-- the 'true' makes it NOT make a sound and visual pulse on the sanity badge
			inst.components.sanity.DoDelta(1, true)
		end)
	end
end)

 

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