Edm1rVMkz10 Posted November 16, 2025 Share Posted November 16, 2025 I'm working on a character mod and need to detect when sanity changes occur due to specific item usage, particularly: Staffs (icestaff, firestaff, telestaff, etc.) - I want to detect when they're successfully used and cause sanity changes Thulecite Crown - When it absorbs damage and causes sanity reduction What I've tried: sanitydelta event: Only provides oldpercent, newpercent, overtime, sanitymode - no reason for the change newstate event: Triggers immediately on use, but doesn't account for failed casts (like teleporting a bird that flies away) Combining state + sanity changes: Still unreliable for detecting successful casts The core problem: I need to distinguish between: Attempted item use vs successful item use that actually affects sanity General sanity changes vs those specifically caused by these items Specific questions: Is there a reliable way to detect when staff spells are successfully cast and cause sanity changes? Can I detect when Thulecite Crown absorbs damage and reduces sanity, and get the amount? Are there any events or methods that provide the "reason" for sanity changes? Any guidance would be greatly appreciated! Link to comment https://forums.kleientertainment.com/forums/topic/168775-question-about-detecting-sanity-changes-from-specific-item-usage/ Share on other sites More sharing options...
FerniFrenito Posted November 18, 2025 Share Posted November 18, 2025 In my experience working with the sanity component, I don't think so. For some reason (illogical, in my opinion), the sanity component has a list of modifiers that function like the health modifier, but it's not used... instead, it uses "dodelta" (omg, how I hate dodelta functions!). Perhaps you could set up a push event or something similar on each object you mentioned in the code section for its sanity penalty, since dodelta doesn't get the caller as a parameter. Link to comment https://forums.kleientertainment.com/forums/topic/168775-question-about-detecting-sanity-changes-from-specific-item-usage/#findComment-1843209 Share on other sites More sharing options...
Edm1rVMkz10 Posted November 18, 2025 Author Share Posted November 18, 2025 5 hours ago, FerniFrenito said: In my experience working with the sanity component, I don't think so. For some reason (illogical, in my opinion), the sanity component has a list of modifiers that function like the health modifier, but it's not used... instead, it uses "dodelta" (omg, how I hate dodelta functions!). Perhaps you could set up a push event or something similar on each object you mentioned in the code section for its sanity penalty, since dodelta doesn't get the caller as a parameter. Thanks for the insight! Totally agree about the sanity component frustrations. I'll try the push events approach you mentioned. Appreciate the help! Link to comment https://forums.kleientertainment.com/forums/topic/168775-question-about-detecting-sanity-changes-from-specific-item-usage/#findComment-1843219 Share on other sites More sharing options...
Baguettes Posted November 18, 2025 Share Posted November 18, 2025 (edited) Staves (in staff.lua) all use the staffsanity component, IIRC. That component doesn't really do much else apart from giving Wanda her magic insanity resistance when she's old. I wonder, since that function only ever gets called on staff usage being complete, could we simply hook into it? It was DoCastingDelta something, and its sole purpose is only to reduce your sanity (with a custom multiplier, if it exists) through the usual sanity component. EDIT: Yeah, what Frenito said; sanity's DoDelta doesn't even specify the source of where it came from. Frustrating, right? This just means I haven't found a good way to go about detecting crown forcefield hits. Edited November 18, 2025 by Baguettes crown Link to comment https://forums.kleientertainment.com/forums/topic/168775-question-about-detecting-sanity-changes-from-specific-item-usage/#findComment-1843221 Share on other sites More sharing options...
Edm1rVMkz10 Posted November 18, 2025 Author Share Posted November 18, 2025 Thanks for the staffsanity component tip! I was able to find a working solution for detecting staff usage based on that lead. Appreciate the help! For the crown though, I'm still struggling to find a way to detect when it absorbs damage and causes sanity drain. The forcefield effect doesn't seem to trigger any obvious events. Has anyone found a reliable way to hook into crown damage absorption? Also just wanted to say this community has been amazing - really appreciate how helpful and friendly everyone is! 1 Link to comment https://forums.kleientertainment.com/forums/topic/168775-question-about-detecting-sanity-changes-from-specific-item-usage/#findComment-1843227 Share on other sites More sharing options...
Baguettes Posted November 19, 2025 Share Posted November 19, 2025 15 hours ago, Edm1rVMkz10 said: For the crown though... Hmm... add a postinit, an event listener for the crown, namely armordamaged to it? Since the crown uses 100% protection during forcefield duration and armordamaged is always called (and also how Klei deducts sanity per forcefield hit from you) because you as the player don't take the hit, but the crown fully gets it. Lemme see... something like: AddPrefabPostInit("ruinshat", function(inst) -- mastersim check only if all clients require mod, you know the deal. if not GLOBAL.TheWorld.ismastersim then --Bet you know what global is, too, right? return end inst:ListenForEvent("armordamaged", function(hat) if hat.components.armor and hat.components.armor:GetAbsorption() == 1 then -- thing. combine inventoryitem:GetGrandOwner() with nil owner checks if you want it -- to do stuff with the wearer... sanity, was it? end end) end) Hella hacky, but what else to be done? I wonder if anyone has a better idea than this. Link to comment https://forums.kleientertainment.com/forums/topic/168775-question-about-detecting-sanity-changes-from-specific-item-usage/#findComment-1843264 Share on other sites More sharing options...
FerniFrenito Posted November 19, 2025 Share Posted November 19, 2025 8 hours ago, Baguettes said: Hella hacky, but what else to be done? I wonder if anyone has a better idea than this. The game's current code could greatly benefit from a refactoring, although it's unlikely to happen because it's very long. 1 Link to comment https://forums.kleientertainment.com/forums/topic/168775-question-about-detecting-sanity-changes-from-specific-item-usage/#findComment-1843342 Share on other sites More sharing options...
Edm1rVMkz10 Posted November 20, 2025 Author Share Posted November 20, 2025 23 hours ago, Baguettes said: Hmm... add a postinit, an event listener for the crown, namely armordamaged to it? Since the crown uses 100% protection during forcefield duration and armordamaged is always called (and also how Klei deducts sanity per forcefield hit from you) because you as the player don't take the hit, but the crown fully gets it. Lemme see... something like: AddPrefabPostInit("ruinshat", function(inst) -- mastersim check only if all clients require mod, you know the deal. if not GLOBAL.TheWorld.ismastersim then --Bet you know what global is, too, right? return end inst:ListenForEvent("armordamaged", function(hat) if hat.components.armor and hat.components.armor:GetAbsorption() == 1 then -- thing. combine inventoryitem:GetGrandOwner() with nil owner checks if you want it -- to do stuff with the wearer... sanity, was it? end end) end) Hella hacky, but what else to be done? I wonder if anyone has a better idea than this. That worked perfectly! Thank you so much! Really appreciate you taking the time to share this solution. 1 Link to comment https://forums.kleientertainment.com/forums/topic/168775-question-about-detecting-sanity-changes-from-specific-item-usage/#findComment-1843401 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