# Anyway to make a character lose sanity by being near insane characters?

## Recommended Posts

Hiya there, I was looking for some help with a character I'm creating.

He's gonna be sort of a therapist character, increasing sanity of nearby people. But, I also want it to be that insanity sort of rubs off on him. Like, making it so that if he's near someone who's below, let's say, 50% sanity, then he will start to lose sanity.

How would I go about doing this?

##### Share on other sites

I would suggest you take a look at this function:

`TheSim:FindEntities(x, y, z, radius, musttags, canttags, mustoneoftags)`

Since every player has the tag "player" you could use this to find players around your character.

##### Share on other sites

Thank you, is there anyway to check if the players around him are insane?

##### Share on other sites

13 hours ago, WubbleWubble said:

Hiya there, I was looking for some help with a character I'm creating.

He's gonna be sort of a therapist character, increasing sanity of nearby people. But, I also want it to be that insanity sort of rubs off on him. Like, making it so that if he's near someone who's below, let's say, 50% sanity, then he will start to lose sanity.

How would I go about doing this?

5 hours ago, WubbleWubble said:

Thank you, is there anyway to check if the players around him are insane?

```inst:DoPeriodicTask(
1.0,
function(inst)
local x, y, z = inst.Transform:GetWorldPosition()
local ents = TheSim:FindEntities(x, y, z, 4.0, {"player"}, {"playerghost"})
local selfsanity = 1
for _,v in pairs(ents)
do
if v~=inst
then
v.components.sanity:DoDelta(1)
if v.components.sanity:IsCrazy()
then
selfsanity = selfsanity - 1
end
end
end
inst.components.sanity:DoDelta(selfsanity)
end
)
```

I commented out the 50% sanity thing and have the sane portion.

This would be in the master_postinit callback.

4.0 = radius of effect, and is 1 turf square in size for relative dimension comparing.

Edited by CarlZalph
'he' usage unclear, changed specification to mean 'other person'
##### Share on other sites

Thank you! It worked like a charm!

##### Share on other sites

1 hour ago, WubbleWubble said:

Thank you! It worked like a charm!

I changed some stuff around, code you're using is going to make the 'patient' lose sanity instead of the 'doctor'.

##### Share on other sites

Thank you!

On another note, do you think any of you could help me make the sanity aura silent? It makes the depleting noise every time