QuickShot010 Posted February 2, 2015 Share Posted February 2, 2015 How excactly do i increase the sanity range of something without increase the sanity aura?I just want my ground prefab to have a higher range, but not a faster sanity recovery. Any suggestions? Link to comment https://forums.kleientertainment.com/forums/topic/50235-increase-sanity-range/ Share on other sites More sharing options...
Blueberrys Posted February 3, 2015 Share Posted February 3, 2015 (edited) @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/2This 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 February 3, 2015 by Blueberrys Link to comment https://forums.kleientertainment.com/forums/topic/50235-increase-sanity-range/#findComment-609148 Share on other sites More sharing options...
QuickShot010 Posted February 4, 2015 Author Share Posted February 4, 2015 @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/2This 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? Link to comment https://forums.kleientertainment.com/forums/topic/50235-increase-sanity-range/#findComment-609745 Share on other sites More sharing options...
Blueberrys Posted February 4, 2015 Share Posted February 4, 2015 (edited) @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_rateI made use of the custom_rate_fn that sanity provides instead of replacing the Recalc function. Edit: Forgot to return value, fixed code. Edited February 4, 2015 by Blueberrys Link to comment https://forums.kleientertainment.com/forums/topic/50235-increase-sanity-range/#findComment-609828 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now