Jump to content

Sanity Gains/Losses Help


Recommended Posts

i wanna make my character gain more sanity, gain no sanity, and gain no sanity degeneration from specific equipped items

more specifically, these:

  • garland: 0x sanity gain (aka no sanity gain)
  • tophat: 1.25x sanity gain
  • night armor: 0x sanity loss
  • night sword: 0x sanity loss

not only equipped items, but i wanna get rid of sanity gain from picking flowers

could someone tell me how to add those multipliers to the said equippable items, and how to get rid of the flowers' picking sanity gain?

it would be greatly appreciated!

Edited by TotalTrashDream
Link to comment
Share on other sites

To play with the sanity loss/gain on items/equipment you will need to work on the "modmain.lua", and add there few "AddPrefabPostInit".
To make the garland have no sanity aura you will need to add:    
    
    AddPrefabPostInit("flowerhat", function(inst)
        if GetPlayer().prefab == "YourCharacterHere" then
            inst.components.dapperness.dapperness = 0
        end
    end)
    
For the tophat:
    
    AddPrefabPostInit("tophat", function(inst)
        if GetPlayer().prefab == "YourCharacterHere" then
            inst:AddComponent("sanityaura")
            inst.components.sanityaura.aura = TUNING.SANITYAURA_SMALL
        end
    end)
    
The amount of sanity loss/gain is determined by the "TUNING.SANITYAURA_SMALL". By changing that, you are changing the amount of sanity the item gives or takes. (You can check in the tuning.lua for those values)
    Those values are:
        SANITY_SUPERTINY = 1,
        SANITY_TINY = 5,
        SANITY_SMALL = 10,
        SANITY_MED = 15,
        SANITY_MEDLARGE = 20,
        SANITY_LARGE = 33,
        SANITY_HUGE = 50,
        
    And if you want them to take sanity instead of give, you can simply add a "-" in front of it. (example: -TUNING.SANITYAURA_SMALL)
    
For the Night armor and sword you will use same coding as for the garland, simply changing the "flowerhat" (which is the garlands code name) for "armor_sanity" and "nightsword" (The armor's and sword's code names).
(If you don't know what are the code names of the items you want to manipulate, you can head to the Don't starve wiki and look for the item you want. Then simply check it's "DebugSpawn", as they are also their code names.)
    
    AddPrefabPostInit("armor_sanity", function(inst)
        if GetPlayer().prefab == "YourCharacterHere" then
            inst.components.dapperness.dapperness = 0
        end
    end)
    AddPrefabPostInit("nightsword", function(inst)
        if GetPlayer().prefab == "YourCharacterHere" then
            inst.components.dapperness.dapperness = 0
        end
    end)
    
You will use similar method to remove the sanity gain from picking flowers, but you simply won't tell the function what to do upon picking the flower, so the game will simply do nothing (no sanity gain nor loss). You can do the same thing with the dark flowers if you want.
    
    AddPrefabPostInit("flower", function(inst)
        if GetPlayer().prefab == "YourCharacterHere" then
            inst.components.pickable.onpickedfn = function(inst, picker)
                if picker and picker.components.sanity then
                    
                end    
                inst:Remove()
            end
        end
    end)
    
(Remember to replace the "YourCharacterHere" with your character's code name there and everything hopefully should work well.)
I hope this will help you. :D I wish I had someone to teach me that when I needed it for my mods XD
You can also check the "Dementor" mod by Auxeras for similar codings. I believe you could find it interesting or useful :D

Edited by BraveChicken
Link to comment
Share on other sites

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
 Share

×
  • Create New...