Jump to content

Recommended Posts

I'm working on a character mod and need to detect when sanity changes occur due to specific item usage, particularly:

  1. Staffs (icestaff, firestaff, telestaff, etc.) - I want to detect when they're successfully used and cause sanity changes
  2. 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:

  1. Is there a reliable way to detect when staff spells are successfully cast and cause sanity changes?
  2. Can I detect when Thulecite Crown absorbs damage and reduces sanity, and get the amount?
  3. Are there any events or methods that provide the "reason" for sanity changes?

Any guidance would be greatly appreciated!

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.

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!

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 by Baguettes
crown

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!

  • Health 1
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.

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.

  • Sad 1
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.

  • Health 1

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
×
  • Create New...