This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.


Help needed with custom perk coding!

Recommended Posts

This seems like the place to go to ask for this kind of help. Im trying to make a custom character and I've gotten to the part where I want to add some perks but I haven't been able to find any sort of guide or even like a list of basic perks. The perk I want the character to have is that they're basically invulnerable to attack while wearing a certain item (garland) or if you can't make them invulnerable than to just have extremely high health

I know how to change the basic stats but i don't want the character to just have really high health all the time, just when wearing a certain item if its possible, And i know i could just make a custom item but i'd rather not do that if i don't have to because thats a lot more in-depth.

I'd also like them to have the perk of regenerating sanity during dusk

If anyone is able and willing to help me its greatly appreciated! And if anyone knows of like a list of perk codes that other people have used or like a basic guide that would be great because i've been looking forever and I can't find anything like that.

Share this post

Link to post
Share on other sites
BraveChicken    25

I'm not sure if by saying "invulnerable to attacks" you meant that you want all of the creatures to simply ignore the character instead of attacking him, or if you just want the character to endure more while wearing the garland. 
However, I don't know if there is an easy way of making all of the mobs simply ignore the player (without causing any "tracking" issues in the game)
but if it's just endurance of the character that you want, then you can try this:
(place it in your modmain.lua)
   GetPlayer = GLOBAL.GetPlayer
    AddPrefabPostInit("flowerhat", function(inst)
        if GetPlayer().prefab == "YourCharacterHere" then
            local function onunequip(inst, owner)
       = 0

            local function onperish(inst, owner)
                if owner then
           = 0

            local function onequip(inst, owner)
                owner.AnimState:OverrideSymbol("swap_hat", "hat_flower", "swap_hat")
       = 0.90
            inst.components.equippable:SetOnUnequip( onunequip )
            inst.components.equippable:SetOnEquip( onequip )
This will increase your character's defense while wearing the garland, so it will lose far less HP when attacked (So you wouldn't need to give your character an immense amount of HP).
You can of course change your character's defense to higher or lower by increasing/decreasing the number "0.90". The number represents the percentage that will be absorbed from the inflicted damage. (Example: 0.90 = 90% less damage, 100 = 100% less damage, 0.25 = 25% less damage... and so on)

and to make your character gain sanity during dusk, you can try this:
(This one goes into your character's prefab file, place it somewhere below your character's stats)
    local function CheckTime(inst)
        if GetClock() and GetWorld() then
            if GetClock():IsDay() and inst:HasTag("dusk") and not GetWorld():IsCave() or 
               GetClock():IsNight() and inst:HasTag("dusk") and not GetWorld():IsCave() or
               GetWorld():IsCave() and inst:HasTag("dusk") then
                inst.components.sanity.dapperness = 0
            if GetClock():IsDusk() and inst:HasTag("notdusk") and not GetWorld():IsCave() then
                inst.components.sanity.dapperness = 0.5
    inst:DoPeriodicTask( 0.0, function(inst) 
If you want to increase/decrease the amount of sanity that your character will be gaining during dusk then you change the number "0.5" to higher or lower.

I hope this helps.
And good luck with your mod! :D 

Woops! Silly me! I made a small mistake in the script for the garland! :shock:
It's fixed now! Sorry about that XD

Share this post

Link to post
Share on other sites