Jump to content

Recommended Posts

@QuickShot010

 

"..\scripts\components\sanity.lua" (Line 229-230)

local distsq = self.inst:GetDistanceSqToInst(v)local aura_val = v.components.sanityaura:GetAura(self.inst)/math.max(1, distsq) 

You can divide the distsq by a number to essentially stretch out the distance at which the aura will have an effect.

Example, divide distsq by two means that you're gonna consider a distance of 20 as if it was only 10. (and dist of 40 as if it's 20, and so on)

distsq = distsq/2

This is in the Recalc function. You can replace that through component post init.

local function sanity_postinit(inst)    self.old_Recalc = self.Recalc    self.Recalc = function(dt)        -- ...    endendAddComponentPostInit("sanity", sanity_postinit)

 

Edit: Actually, since it's only for your prefab, it might be better to do it through player_inst.components.sanity.Recalc instead.

 

Edited by Blueberrys

@QuickShot010

 

"..\scripts\components\sanity.lua" (Line 229-230)

local distsq = self.inst:GetDistanceSqToInst(v)local aura_val = v.components.sanityaura:GetAura(self.inst)/math.max(1, distsq) 

You can divide the distsq by a number to essentially stretch out the distance at which the aura will have an effect.

Example, divide distsq by two means that you're gonna consider a distance of 20 as if it was only 10. (and dist of 40 as if it's 20, and so on)

distsq = distsq/2

This is in the Recalc function. You can replace that through component post init.

local function sanity_postinit(inst)    self.old_Recalc = self.Recalc    self.Recalc = function(dt)        -- ...    endendAddComponentPostInit("sanity", sanity_postinit)

 

Edit: Actually, since it's only for your prefab, it might be better to do it through player_inst.components.sanity.Recalc instead.

 

Hmm. So what do you suggest i add to the prefab.lua?

@QuickShot010

 

Try this,

local function custom_sanity_rate(inst)	local sanity = inst.components.sanity	-- Copied from sanity.lua, modified to fit here	local aura_delta = 0	local x,y,z = inst.Transform:GetWorldPosition()	local ents = TheSim:FindEntities(x,y,z, TUNING.SANITY_EFFECT_RANGE, nil, {"FX", "NOCLICK", "DECOR","INLIMBO"} )	for k,v in pairs(ents) do		if v.components.sanityaura and v ~= inst then			local distsq = inst:GetDistanceSqToInst(v)			local aura_val = v.components.sanityaura:GetAura(inst)/math.max(1, distsq)			if aura_val < 0 then				aura_val = aura_val * sanity.neg_aura_mult			end			aura_delta = aura_delta + aura_val		end	end	return aura_deltaend-- ...-- Inst refers to the player instance here-- This line needs to be in the create fninst.components.sanity.custom_rate_fn = custom_sanity_rate

I made use of the custom_rate_fn that sanity provides instead of replacing the Recalc function.

 

Edit: Forgot to return value, fixed code.

Edited by Blueberrys

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