Jump to content

Recommended Posts

Hello!

I am currently in the process of making a custom character for DST. I have all the basics down (customized stats, changed names in the files, etc.), I am still working on the art. However, I would like to implement a quirk that makes the character slowly lose sanity when around fire (exclusively in the daytime, if possible. If it's only possible for it to function all around the clock, that's fine as well). I tried manipulating Willow's .lua file, but I haven't been able to process the idea of changing and transferring it to the custom character's file. If anyone could help me out with this, I would be so grateful!

I have scoured the forums for other people looking to do this prior to posting this. I will admit that I am new to coding, and no advice that was given to others was accurate or applicable to the current day (The threads I have found are super outdated).

This is the wrong forum. You are asking about the multiplayer version, not the singleplayer. However, the relevant processes are the same for both versions, so this forum is still perfectly valid for this question.

 

I can't look into it now, but I'll come back and edit this post once I have.

(Yeah, it's perfectly possible to have this be daytime only. The coding interface for Don't Starve modding is very accommodating.)

2 hours ago, Arkathorn said:

This is the wrong forum. You are asking about the multiplayer version, not the singleplayer. However, the relevant processes are the same for both versions, so this forum is still perfectly valid for this question.

 

I can't look into it now, but I'll come back and edit this post once I have.

(Yeah, it's perfectly possible to have this be daytime only. The coding interface for Don't Starve modding is very accommodating.)

Oops! I thought this was the multiplayer forum. You do make a good point that it is the same process, so I don't think I'll have to have it moved, hopefully? 

I appreciate the response and information.  Thank you for taking the time to reply! :D

Nvm, I'll just post it here.

 

local function makefn(amt)
	return function(inst)
		inst:AddComponent("sanityaura")
		inst.components.sanityaura.aurafn = function(inst, observer)
			if observer.prefab == "yourcharacterprefab" and GetClock().phase == "day" then
				if inst.components.fueled then
					return inst.components.fueled:GetPercent() * amt
				else
					return amt
				end
			end
		end
	end
end

AddPrefabPostInit("campfire",makefn(TUNING.SANITY_SMALL))
AddPrefabPostInit("firepit",makefn(TUNING.SANITY_MED))

This goes in 'modmain.lua'. Add more 'AddPrefabPostInit' lines for more prefabs. See 'tuning.lua' for the other sanity amounts.

This should work in DS, but I'm pretty sure DST puts the Clock somewhere else (inside the SeasonManager?). Just remove this code to leave the daytime restriction out, and make it DST compatible: (Leave the 'then' in.)

and GetClock().phase == "day"

Or you could ask someone how to get the current phase in DST.

DST uses neither GetClock() or GetSeasonManager().

I'm going to suggest a tweaked DST Willow approach (to include more than campfire and firepit), with the fuel multiplier thing.

local function sanityfn(inst)
	-- Not day, give 0 back
	if TheWorld.state.phase ~= "day" then
		return 0
	end
	-- During day, Willow approach
	local delta = 0
	local x, y, z = inst.Transform:GetWorldPosition() 
	local max_rad = 10
	local ents = TheSim:FindEntities(x, y, z, max_rad, {"fire"})
	for i, v in ipairs(ents) do
		local fuel_mult = inst.components.fueled and inst.components.fueled:GetPercent() or 1
		if v.components.burnable and v.components.burnable:IsBurning() then
			local rad = v.components.burnable:GetLargestLightRadius() or 1
			local sz = TUNING.SANITYAURA_TINY * math.min(max_rad, rad) / max_rad
			local distsq = inst:GetDistanceSqToInst(v) - 9
			delta = delta + sz / math.max(1, distsq)
			delta = delta * fuel_mult
		end
	end
	-- Willow would be positive, so we invert it
	return -delta
end

-- inside master
local function master_postinit(inst)
	inst.components.sanity.custom_rate_fn = sanityfn
end

 

@DarkXero @Arkathorn

Thank you both for the coding and the help so far!

I followed @Arkathorn's directions to put @DarkXero's code in the modmain.lua file. I'm not sure if there's a specific place to put it, so I put it between "Assets" and "local require".

I went into the game with the character to test it out by building myself a campfire, and nothing seemed to happen. Thankfully, the game didn't crash like I've seen happen with others. I feel like I'm overlooking or missing something very obvious.

Put the 'sanityfn' function in 'yourcharacter.lua', outside of 'fn'. Inside of 'fn' (but before the "return" line), put the line from 'master_postinit':

inst.components.sanity.custom_rate_fn = sanityfn

 

Edited by Arkathorn

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