MothsPastry Posted May 26 Share Posted May 26 Hii I'm requesting some assistance on coding a debuff. Basically I just want a sanity drain to happen when lighting objects on fire and being around burning objects (things like fire pits, torches, ect are excluded because at that point the character would not be very fun to play as and my reasoning for these being excluded are because they're controlled fires technically) and sanity loss at overheating. I know it's a perfab thing, but this is my first attempt at coding a debuff and I'm probably biting off way more I can chew but I would appreciate any assistance on this thank you! Link to comment https://forums.kleientertainment.com/forums/topic/171698-help-with-coding-pyrophobia-and-sanity-loss-when-overheating/ Share on other sites More sharing options...
Meepenator Posted May 27 Share Posted May 27 local CAMPFIRE_TAGS = { "campfire", "wildfireprotected" } local FIRE_TAGS = { "fire" } local function sanityfn(inst)--, dt) local sanity_cap = TUNING.SANITYAURA_LARGE local sanity_per_ent = TUNING.SANITYAURA_TINY local delta = 0 local beta = 0 local x, y, z = inst.Transform:GetWorldPosition() local max_rad = 20 local ents = TheSim:FindEntities(x, y, z, max_rad, FIRE_TAGS) local fents = TheSim:FindEntities(x, y, z, max_rad, CAMPFIRE_TAGS) for i, v in ipairs(fents) do if v.components.burnable ~= nil and v.components.burnable:IsBurning() then local stack_size = v.components.stackable ~= nil and v.components.stackable.stacksize or 1 local rad = v.components.burnable:GetLargestLightRadius() or 1 local sz = stack_size * sanity_per_ent * math.min(max_rad, rad) / max_rad local distsq = inst:GetDistanceSqToInst(v) - 9 -- shift the value so that a distance of 3 is the minimum delta = delta + sz / math.max(1, distsq) if delta > sanity_cap then delta = sanity_cap break end end end for i, v in ipairs(ents) do if v.components.burnable ~= nil and v.components.burnable:IsBurning() then local stack_size = v.components.stackable ~= nil and v.components.stackable.stacksize or 1 local rad = v.components.burnable:GetLargestLightRadius() or 1 local sz = stack_size * sanity_per_ent * math.min(max_rad, rad) / max_rad local distsq = inst:GetDistanceSqToInst(v) - 9 -- shift the value so that a distance of 3 is the minimum beta = beta + sz / math.max(1, distsq) if beta > sanity_cap then beta = sanity_cap break end end end return -(beta - delta) end local function LocalTemperature(inst,data) if inst.components.temperature.current > 65 then inst.components.sanity.dapperness = -TUNING.DAPPERNESS_LARGE * 2 else inst.components.sanity.dapperness = TUNING.DAPPERNESS_LARGE * 0 end end --put these 2 parts in your master_postinit inst.components.sanity.custom_rate_fn = sanityfn inst:ListenForEvent("temperaturedelta", LocalTemperature) --feel free to tweak these in anyway you choose, campfires do not count towards the fire debuff Link to comment https://forums.kleientertainment.com/forums/topic/171698-help-with-coding-pyrophobia-and-sanity-loss-when-overheating/#findComment-1868437 Share on other sites More sharing options...
MothsPastry Posted June 8 Author Share Posted June 8 On 5/27/2026 at 4:58 AM, Meepenator said: local CAMPFIRE_TAGS = { "campfire", "wildfireprotected" } local FIRE_TAGS = { "fire" } local function sanityfn(inst)--, dt) local sanity_cap = TUNING.SANITYAURA_LARGE local sanity_per_ent = TUNING.SANITYAURA_TINY local delta = 0 local beta = 0 local x, y, z = inst.Transform:GetWorldPosition() local max_rad = 20 local ents = TheSim:FindEntities(x, y, z, max_rad, FIRE_TAGS) local fents = TheSim:FindEntities(x, y, z, max_rad, CAMPFIRE_TAGS) for i, v in ipairs(fents) do if v.components.burnable ~= nil and v.components.burnable:IsBurning() then local stack_size = v.components.stackable ~= nil and v.components.stackable.stacksize or 1 local rad = v.components.burnable:GetLargestLightRadius() or 1 local sz = stack_size * sanity_per_ent * math.min(max_rad, rad) / max_rad local distsq = inst:GetDistanceSqToInst(v) - 9 -- shift the value so that a distance of 3 is the minimum delta = delta + sz / math.max(1, distsq) if delta > sanity_cap then delta = sanity_cap break end end end for i, v in ipairs(ents) do if v.components.burnable ~= nil and v.components.burnable:IsBurning() then local stack_size = v.components.stackable ~= nil and v.components.stackable.stacksize or 1 local rad = v.components.burnable:GetLargestLightRadius() or 1 local sz = stack_size * sanity_per_ent * math.min(max_rad, rad) / max_rad local distsq = inst:GetDistanceSqToInst(v) - 9 -- shift the value so that a distance of 3 is the minimum beta = beta + sz / math.max(1, distsq) if beta > sanity_cap then beta = sanity_cap break end end end return -(beta - delta) end local function LocalTemperature(inst,data) if inst.components.temperature.current > 65 then inst.components.sanity.dapperness = -TUNING.DAPPERNESS_LARGE * 2 else inst.components.sanity.dapperness = TUNING.DAPPERNESS_LARGE * 0 end end --put these 2 parts in your master_postinit inst.components.sanity.custom_rate_fn = sanityfn inst:ListenForEvent("temperaturedelta", LocalTemperature) --feel free to tweak these in anyway you choose, campfires do not count towards the fire debuff Thank you so much!! Link to comment https://forums.kleientertainment.com/forums/topic/171698-help-with-coding-pyrophobia-and-sanity-loss-when-overheating/#findComment-1870844 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