Jump to content

[NEED HELP] Character gains sanity when around others


Recommended Posts

Hey! I'm trying to give a character an "extrovert" perk. Giving them sanity gain when around other players. I can't get it to work however. I'm pretty new to modding so I might be doing something wrong. I added the code at the bottom (before the last end) in the character.lua file. I used this code. This is for DST btw.


 local function sanityfn(inst)
 	local x,y,z = inst.Transform:GetWorldPosition()
 	local delta = 0
 	local rad = 10
 	local rad_sq = rad*rad
 	for k,v in pairs(AllPlayers) do
 	if v ~= inst then
 	local distsq = inst:GetDistanceSqToInst(v)
 	if distsq < rad_sq then
 	local sz = TUNING.SANITYAURA_MED * rad
 	delta = delta + sz/math.max(1, distsq)
 	end
 	end
 	end

 	return delta
 	end
 inst.components.sanity.custom_rate_fn = sanityfn

 

Link to comment
Share on other sites

I don't know how this sanityfn you used would work. 

Do this in main fn of character: 

inst:DoPeriodicTask(3, function() 

local ents = ..... 

---use some function that find creatures, dig combat component DoAreaAttack function for that

local playersnum = #ents 

local sanity = player*0.1

inst.components.sanity:DoDelta(sanity) 

end) 

Link to comment
Share on other sites

I would need to see your entire character Lua file to see where it goes wrong. Your sanityfn looks fine (at a glance). You can get a long way just printing the state of things with print-statements, so you can see, e.g., what your delta ends up being, how many players it registers, what your delta calculation results in. All that good stuff.

See the newcomer post, particularly the "Debugging" section, for more info.

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