Jump to content

[HELP] sanitygain near rabbits


Recommended Posts

Hello floks,

im new to modding and currently trying around with adjusting an existing character for my girlfriend. i wont upload it since i dont have the copyright for it. it is just for my personal use. 

Since the character is a rabbit, other rabbits are not afraid of him any more. I managed to make this work by adding: 

inst:RemoveTag("scarytoprey")

to my character prefab. 

After that i wanted him to gain sanity while standing next to rabbits. I used a code which i found in another thread of this forum:

local function sanityfn(inst)        local x,y,z = inst.Transform:GetWorldPosition()	        local delta = 0        local ents = TheSim:FindEntities(x,y,z, 4, {"rabbit"})        for k,v in pairs(ents) do             local bonus_sanity = TUNING.SANITYAURA_LOW            local distsq = math.max(inst:GetDistanceSqToInst(v),1)            delta = delta + bonus_sanity/distsq        end        return delta    end        inst.components.sanity.custom_rate_fn = sanityfn

While now i get sanity by standing near rabbits all rabbits immediately start to run in their rabbitholes when i cross the map^^ 

Can someone help me with that? Did i miss something?

 

Link to comment
Share on other sites

For gaining sanity around rabbits I think you can put this in your modmain.lua, maaaybe :)

Spoiler

if GLOBAL.TheNet:GetIsServer() then

	AddPrefabPostInit("rabbit", function(inst)
		inst:AddComponent("sanityaura")
		inst.components.sanityaura.aura = 0
	end)

	AddComponentPostInit("sanityaura", function(self)
		local old = self.GetAura 
		function self:GetAura(observer) 
			if observer.prefab == "YOURCHARACTERNAMEHERE" and self.inst.prefab == "rabbit" then 
				return .1
			end
			return old(self,observer) 
		end
	end)		

end

 

 

Link to comment
Share on other sites

you can put anuywhere in modmain.lua :)

 

Also, make sure where it says 

YOURCHARACTERNAMEHERE

to change to name of your charharacter's prefab file is name 

:D

Edited by SuperDavid
Link to comment
Share on other sites

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
 Share

×
  • Create New...