Jump to content

Recommended Posts

I want to make a custom character with the perk of gaining sanity when near shadow creatures (and maybe night light) rather than losing it. I want spiders and such to make you insane like normal though.

 

I started by copying Willows perk of gaining sanity by fire and removing the burning bits and replacing "fire" with "flower_evil" (for testing purposes). This is what the code looks like:

local function sanityfn(inst)	local x,y,z = inst.Transform:GetWorldPosition()		local delta = 0	local rad = 5	local ents = TheSim:FindEntities(x,y,z, rad, {"flower_evil"})		for k,v in pairs(ents) do 			local sz = TUNING.SANITYAURA_MED--			local rad = 1--			sz = sz * ( math.min(max_rad, rad) / max_rad )	I don't think those two lines are necessary.			local distsq = inst:GetDistanceSqToInst(v)			delta = delta + sz/math.max(1, distsq)		end	return deltaendlocal fn = function(inst)	--cut out some unrelated pieces.	inst.components.sanity:SetMax(TUNING.WILSON_SANITY * 0.8 )	inst.components.sanity.custom_rate_fn = sanityfnend

Unfortunately, something (maybe the line outside the function) makes the presence of evil flowers not raise my current sanity, but rather slightly drop my maximum sanity (the effect never goes away).

 

I don't quite understand the sanity code yet, not at all to be honest. I am thankful for any code suggestions, constructive questions or explanations.

probably you have to change evil flowers instead of player

 

local function MakeGood(inst)     if inst and inst.components then            if not inst.components.sanityaura then inst:AddComponent("sanityaura") end            inst.components.sanityaura.aura = GLOBAL.TUNING.SANITYAURA_MED     endend AddPrefabPostInit("flower_evil", MakeGood)--AddPrefabPostInit("someotherprefab", MakeGood)-- add more prefabs here

 

but tbh MED is too much :)

Edited by Rincevvind

That was a quick reply...

 

Sadly, now the game crashes. I've attached the log.txt, it says that AddPrefabPostInit is not declared. I've tried to put the line alone and in fn.

 

Am I supposed to declare it earlier in the file? I am not even sure what's going on anymore :razz:

well bad side of this method - code will work for all characters, so better to test it with
 

local function MakeGood(inst)     local p = GLOBAL.GetPlayer()     if inst and inst.components and p and p.prefab=="wilfre" then            if not inst.components.sanityaura then inst:AddComponent("sanityaura") end            inst.components.sanityaura.aura = GLOBAL.TUNING.SANITYAURA_MED     endend

but i am unsure about it

Edited by Rincevvind

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