# Help / Lose sanity near fires

## Recommended Posts

Hello, I've already seen someone ask a similar question already, but I had problems figuring it out. I'm making my first mod and I wanted to make my character pyrophobic, so have a fear of nearby fires. I looked through Willow's prefab file because I originally assumed I could just copy Willow's sanity gain near fires and somehow invert it, but I wasn't exactly able to figure it out and it kept crashing.

If anybody could help me a little with this or send me a good tutorial, I'd be very thankful.

##### Share on other sites

You didn't even pasted your error...

I don't know how it's done, but I just added a minus before TUNING.SANITYAURA_TINY and it worked for me...

Local function:

Spoiler
```
local function sanityfn(inst)
local x,y,z = inst.Transform:GetWorldPosition()
local delta = 0
local ents = TheSim:FindEntities(x,y,z, max_rad, {"fire"})
for k,v in pairs(ents) do
if v.components.burnable and v.components.burnable.burning then
local sz = -TUNING.SANITYAURA_TINY
local distsq = inst:GetDistanceSqToInst(v)
delta = delta + sz/math.max(1, distsq)
end
end

if SaveGameIndex:IsModeShipwrecked() or SaveGameIndex:IsModePorkland() then
if GetWorld().IsVolcano() then
local map = GetWorld().Map
if map and map:IsTileGridValid() then
local tx, ty = map:GetTileXYAtPoint(x, y, z)
local dist = map:GetClosestTileDist(tx, ty, GROUND.VOLCANO_LAVA, 4)
if dist <= 4 then
delta = math.max(delta, -TUNING.SANITYAURA_TINY * (1 - (dist / 4)))
end
end
end
end

return delta
end```

In prefab function:

`inst.components.sanity.custom_rate_fn = sanityfn`

PS: Local function has to be before prefab function...

##### Share on other sites

Yes, thank you very much  I tried it right away and it worked.