BraveChicken

[Tutorial] Making basic character perks (DS, RoG, SW)

Recommended Posts

BraveChicken    16
Posted (edited)

I have seen a lot of people which are still new to modding having troubles with the basic character perks, therefore I decided to create a simple tutorial showing you how to create some basic perks for your character. So if you're having trouble and are working on a mod for DS, RoG, or SW (or... all) then hopefully this could help you out at least a little bit!

I know that I'm not the best modder out there, and that there can be few different ways to achieve some of these things in this tutorial, but I'm gonna focus mainly on the ways that I learned how to do them.

----------------------------------------------------------------------------------------------------------------
(IMPORTANT: DST mods differ in their codding from the DS, RoG, and SW. So sadly this tutorial might not help you if you're working on a DST mod)
----------------------------------------------------------------------------------------------------------------

So most of you probably are already using a basic character template, which provides you with a basic modmain.lua file, same as a  starter character prefab file which already has the basic list of assets, and character stats for you to manipulate.
But just in case you don't have them, then here's where you can get them: Extended Sample Character  << Click

 

In this tutorial I'll show you how to:
- Set/Change your characters Health, Sanity, and hunger.
- Increase/Decrease/Turn off night and dusk sanity drain or how to reverse it.
- Set a HP/Sanity/Hunger regen/damage over time.
- Set a HP/Sanity/Hunger regen/damage during specified time of the day.
- Set a HP/Sanity/Hunger regen/damage during specified season.

- Set a HP/Sanity/Hunger regen/damage from rain or while being in caves.
Set a health/sanity/hunger regern/damage from temperature.
- Set a sanity/health/hunger loss/gain from attacking creatures.
Set a sanity/health/hunger loss/gain from killing creatures.
- Set a Sanity regern/damage by equipping an item.
- Erase/Increase/Decrease an existing sanity regen/damage on an item.
- Add a sanity aura heal/damage to an item/creature.
--------------------------
- Change your character's basic defense/attack power/speed.
- Change defense/power/speed based on the time of the day.
Change defense/power/speed based on season.
- Change defense/power/speed based on rain or caves.
- Change defense/power/speed based on temperature.
--------------------------
Set your character's heat and cold resistance.
Increase/Decrease the HP damage when freezing/overheating.
- Make your character fragile/resistant/immune to heat/cold.
- Make your character immune to fire.
- Turn your character into a monster or make it "not scary to prey".
- Make the spiders/merm ignore your character (if unbothered).
--------------------------
- Set/Change what your character can/can't eat.
- Change the amount of sanity/health/hunger that a specified food gives.
- Create a custom food type/group for your character.
- Make an non-eatable item eatable to your character.
---------------------------
- Give your character starting inventory items.
- Make your character always start with a certain custom item (even in adventure mode).
- Give your character a night vision/glow.
- Unlock recipes for your character.
- Change existing recipes.
- Give your character custom recipes for existing items.
- Remove the sanity gain/loss from picking flowers.

 

(All of the sections are in the same order as in the list above)

BTW, I know that you'll see me repeat the same things many times in this tutorial, but that's just because I made it for people to be able to head right away to the section that they care to learn, without needing to read the whole thing. So I'm sorry if you'll find that annoying.
Anyways, let's start!

 

=========================================================================
Health / Sanity / Hunger
=========================================================================


--=====BASIC=====--

-- Set/Change the character's basic stats --

Spoiler

In your character's prefab file you'll see the lines:

    inst.components.health:SetMaxHealth(150)
    inst.components.hunger:SetMax(150)
    inst.components.sanity:SetMax(200)

Those are the main stats of your character.
By changing the numbers in the parentheses you'll change the main Health, Hunger, and Sanity stats of your character. So simply set them to the amount that you want your character to have.

 

 

-- Increase/Decrease/Turn off night & dusk sanity drain or reverse it --

Spoiler

To do that you'll need to head to your character's prefab file and add this line along with your character's stats.

    inst.components.sanity.night_drain_mult = 0

This is the line that we will work with. 

Increase sanity drain
To increase the sanity drain during night and dusk simply change the number "0" at the end to a higher number (Example: change it to "3". inst.components.sanity.night_drain_mult = 3) and then test it out in the game. If you still won't be satisfied with the sanity drain, then feel free to increase the number as much as you need until you'll feel satisfied with the effect.
(Remember that you can also use "half numbers" like 0.5, 2.7, 3.1 etc.)

Decrease sanity drain
To decrease the sanity drain during night and dusk, simply change the number "0" at the end to any other low number (or "half number" like 0.5, 0.3, etc.) and then test it out in the game. If you still won't be satisfied with the effect, then feel free to lower down the number even more until you'll get the effect that you're looking for.

Turn it off
If you want the night and dusk sanity drain to be turned off, then simply leave the line the way it is. The number "0" at the end of it means that there will be no night and dusk sanity drain bothering your character.

Reverse it to sanity regen
This is a very simple thing to do. If you'll change the number "0" at the end to any negative number (Example: -3. inst.components.sanity.night_drain_mult = -3) then your character instead of losing sanity, will start gaining it during the night and dusk. If after testing it in the game you still won't be satisfied with the effect, then feel free to increase the number even more, until you'll get the effect that you want.
(Remember that you can also use "half numbers" like 0.5, 2.7, 3.1 etc.)

 

 

--=====REGEN/DAMAGE BASED ON TIME OR SEASON=====--

-- Set a HP/Sanity/Hunger regen/damage over time --

Spoiler

To make a HP/Sanity/Hunger regen/damage over time you'll need to head to your character's prefab file, and in there you'll see the "local fn = function(inst)". We will work mainly IN this function.

Health regen
To make your character regenerate health over time you'll need to add this line along with your character's stats.

    inst.components.health:StartRegen(amount, period)

This is the line that we will work with. 
In the parentheses you see the words "amount" and "period". Replace the word "amount" with the amount of HP that you want your character to be regenerating, and replace the word "period" with the time that you want your character to wait before regenerating the set amount of HP again.
(Remember that you can also use "half numbers" like 0.5, 2.7, 3.1 etc.)

    Example
    inst.components.health:StartRegen(1, 5)

    This will make your character regenerate 1 HP every 5 seconds.


Health drain
To make your character lose health over time you'll need to add this line along with your character's stats.

    inst.components.health:StartRegen(amount, period)

This is the line that we will work with. 
In the parentheses you see the words "amount" and "period". Replace the word "amount" with the amount of HP that you want your character to be losing, (just remember to place a "-" in front of the number. Example: -1) and replace the word "period" with the time that you want your character to wait before losing the set amount of HP again. (Remember that you can also use "half numbers" like 0.5, 2.7, 3.1 etc.)

Example
 inst.components.health:StartRegen(-1, 5)
This will make your character lose 1 HP every 5 seconds.


Sanity regen
To make your character regenerate sanity over time you'll need to add this line along with your character's stats.

    inst.components.sanity.dapperness = 1

The number "1" shows how much sanity your character will be regenerating per second. Simply increase/decrease the number until you'll get the effect that you'll looking for.
(Remember that you can also use "half numbers" like 0.5, 2.7, 3.1 etc.)


Sanity drain
To make your character lose sanity over time you'll need to add this line along with your character's stats.

    inst.components.sanity.dapperness = -1

The number "-1" shows how much sanity your character will be losing per second. Simply increase/decrease the number until you'll get the effect that you'll looking for.
(Remember that you can also use "half numbers" like 0.5, 2.7, 3.1 etc.)


Hunger: Increase calorie burn
(1st method)
To increase how fast you want your character to be getting hungry, you'll need to find (or add, if you don't have it) this line in your character's prefab file:

    inst.components.hunger.hungerrate = 1 * TUNING.WILSON_HUNGER_RATE

This is the line that we will work with.
By increasing the number "1" you will increase the speed in which your character will be getting hungry. (Remember that you can also use "half numbers" like 0.5, 2.7, 3.1 etc.)

You can also change the line like this:    

    inst.components.hunger.hungerrate =

Then the number "1" show you how much hunger points the character will be losing per second. (So you might want to work with "half numbers" like 0.5, 0.3, over here.) You may use which ever method seems the most comfortable to you.

(2nd method)
To increase how fast you want your character to be getting hungry, you'll need to add this line in your character's prefab file:

   inst.components.hunger.burnrate = 3

This is the line that we will work with.
By increasing the number "3" you will increase the speed in which your character will be getting hungry. (Remember that you can also use "half numbers" like 0.5, 2.7, 3.1 etc.)


Hunger: Lower calorie burn
To lower the speed in which your character gets hungry, you'll need to add this line in your character's prefab file:

    inst.components.hunger.burnrate = 1

This is the line that we will work with.
By decreasing the number "1" you will decrease the speed in which your character will be getting hungry. (Remember that you can also use "half numbers" like 0.5, 0.7, 0.1 etc.)


Hunger: Reverse
(No idea why would you need it but I'm gonna show you how to do it anyways XD)
(1st method)
To make your character getting less hungry rather than more hungry over time, you'll need to find (or add, if you don't have it) this line in your character's prefab file:

    inst.components.hunger.hungerrate = 1 * TUNING.WILSON_HUNGER_RATE

This is the line that we will work with.
By adding a "-" in front of the number "1" you will reverse the hunger effect. By increasing the number you'll increase the speed in which your character will be getting less hungry.
(Example: inst.components.hunger.hungerrate = -1 * TUNING.WILSON_HUNGER_RATE)
(Remember that you can also use "half numbers" like 0.5, 2.7, 3.1 etc.)

You can also change the line like this:    

    inst.components.hunger.hungerrate = -1 

Then the number "1" show you how much hunger points the character will be gaining per second. (So you might want to work with "half numbers" like 0.5, 0.3, over here.) You may use which ever method seems the most comfortable to you.

(2nd method)
To make your character getting less hungry rather than more hungry over time, you'll need to add this line in your character's prefab file:

    inst.components.hunger.burnrate = -1

This is the line that we will work with.
By adding a "-" in front of the number "1" you will reverse how hunger works. By increasing the number you'll increase the speed in which your character will be getting less hungry.


Hunger: Stop
(1st method)
To stop your character from getting hungry you'll need to find (or add, if you don't have it) this line in your character's prefab file:

    inst.components.hunger.hungerrate = 1 * TUNING.WILSON_HUNGER_RATE

And then simply change it to:

    inst.components.hunger.hungerrate = 0

This will stop your character from getting hungry.

(2nd method)
To stop your character from getting hungry you'll need to add this line in your character's prefab file:

    inst.components.hunger.burnrate = 0

The "0" at the end shows that your character won't be burning any calories, and therefore won't be getting hungry.

 

 

-- Set a HP/Sanity/Hunger regen/damage during specified time of the day --

Spoiler

If you want your character to gain/lose HP/Sanity/Hunger during a specified time of the day, then you'll need to head to your character's prefab file, and in there you'll see the "local fn = function(inst)". We will work mainly IN this function.

Basic lines that you'll be working with
(Inactive)
    inst.components.sanity.dapperness = 0
    inst.components.health:StartRegen(0, 0)    
    inst.components.hunger.hungerrate =  TUNING.WILSON_HUNGER_RATE
    or
    inst.components.hunger.burnrate = 1

(Active)Example:
    inst.components.sanity.dapperness = 0.5
    inst.components.health:StartRegen(1, 2)    
    inst.components.hunger.hungerrate =  2 * TUNING.WILSON_HUNGER_RATE
    or
    inst.components.hunger.burnrate = 2

Depending what you wish to be drained/regenerated during the specified time of day (Day, Dusk, or Night) you may pick the lines that you need, to later place them into the "base code" that you'll find below. If you don't know how the given lines work, then please check the Health, Sanity, and Hunger drain/regen in the "Set a HP/Sanity/Hunger regen/damage over time" section above, as this will work the same way.

Base code

   inst:AddTag("notactive")
    local function CheckTime(inst)
        if GetClock() and GetWorld() then
            if not GetClock():IsDay() and inst:HasTag("active") and not GetWorld():IsCave() then
                PLACE HERE THE INACTIVE PERK
                inst:AddTag("notactive")
                inst:RemoveTag("active")
            end
            if GetClock():IsDay() and inst:HasTag("notactive") and not GetWorld():IsCave() then
                PLACE HERE THE ACTIVE PERK
                inst:AddTag("active")
                inst:RemoveTag("notactive")
            end
        end
    end
    inst:DoPeriodicTask( 0.0, function(inst) 
        CheckTime(inst)
    end)

Now, depending on which time of the day you want your character's perks to activate (Day, Dusk, or Night) simply change the "GetClock():IsDay()" which I marked, to "GetClock():IsDusk()" or "GetClock():IsNight()". And don't forget to place the lines of your character's active/inactive perks in the marked spot.

Side note: If you are working on a custom sanity perk, then remember that unless you have the night/dusk sanity drain turned off, your sanity perk will be affected by it if it'll be activated during dusk or night.

 

 

-- Set a HP/Sanity/Hunger regen/damage during specified season --

Spoiler

If you want your character to gain/lose HP/Sanity/Hunger during a specified season, then you'll need to head to your character's prefab file, and in there you'll see the "local fn = function(inst)". We will work mainly IN this function.

Basic lines that you'll be working with
(Inactive)
    inst.components.sanity.dapperness = 0
    inst.components.health:StartRegen(0, 0)    
    inst.components.hunger.hungerrate =  TUNING.WILSON_HUNGER_RATE
    or
    inst.components.hunger.burnrate = 1

(Active)Example:
    inst.components.sanity.dapperness = 0.5
    inst.components.health:StartRegen(1, 2)    
    inst.components.hunger.hungerrate =  2 * TUNING.WILSON_HUNGER_RATE
    or
    inst.components.hunger.burnrate = 2

Depending what you wish to be drained/regenerated during the specified season, you may pick the lines that you need, to later place them into the "base code" that you'll find below. If you don't know how the given lines work, then please check the Health, Sanity, and Hunger drain/regen in the "Set a HP/Sanity/Hunger regen/damage over time" section above, as this will work the same way.

Base code (RoG)

    inst:ListenForEvent("seasonChange", function(it, data)
        if data.season == SEASONS.WINTER then
            PLACE HERE THE ACTIVE/INACTIVE PERKS
        end
        if data.season == SEASONS.SPRING then
            PLACE HERE THE ACTIVE/INACTIVE PERKS
        end
        if data.season == SEASONS.AUTUMN then
            PLACE HERE THE ACTIVE/INACTIVE PERKS
        end
        if data.season == SEASONS.SUMMER then
            PLACE HERE THE ACTIVE/INACTIVE PERKS
        end
    end, GetWorld())

Depending on the season that you want your character's perks to activate, place the active perks there, while placing the inactive ones to the section of the other seasons.

Side note: If you are working on a custom sanity perk, then remember that unless you have the night/dusk sanity drain turned off, your sanity perk will be affected by it during dusk and night.


Base code (DS) & (RoG)
The normal DS works a bit differently than the DLCs. The game won't notice what season it is unless it just got changed. Therefore we'll need trigger it ourselves.

    inst:ListenForEvent("seasonChange", function(it, data)
        if data.season == SEASONS.WINTER then
            PLACE HERE THE ACTIVE/INACTIVE PERKS
        end
        if data.season == SEASONS.SPRING then
            PLACE HERE THE ACTIVE/INACTIVE PERKS
        end
        if data.season == SEASONS.AUTUMN then
            PLACE HERE THE ACTIVE/INACTIVE PERKS
        end

        if data.season == SEASONS.SUMMER then
            PLACE HERE THE ACTIVE/INACTIVE PERKS
        end
    end, GetWorld())
    inst:PushEvent("seasonChange")

(The last line is literally all we added for it to work!)
Depending on the season that you want your character's perks to activate, place the active perks there, while placing the inactive ones to the section of the other season(s). If you don't intend for your mod to be compatible with RoG then you can erase the grayed out lines, as they won't be necessary.

Side note: If you are working on a custom sanity perk, then remember that unless you have the night/dusk sanity drain turned off, your sanity perk will be affected by it during dusk and night.

 

I would try and give also a base code for the SW version, but... I sadly don't have SW to be aware of what is, and what isn't in the game there. Sorry about that.

 

 

--=====REGEN/DAMAGE BASED ON LOCATION OR RAIN=====--    

-- Set a HP/Sanity/Hunger regen/damage from rain or while being in caves --

Spoiler

If you want your character to gain/lose HP/Sanity/Hunger during rain/while being in caves, then you'll need to head to your character's prefab file, and in there you'll see the "local fn = function(inst)". We will work mainly IN this function.

Basic lines that you'll be working with
(Inactive)
    inst.components.sanity.dapperness = 0
    inst.components.health:StartRegen(0, 0)    
    inst.components.hunger.hungerrate =  TUNING.WILSON_HUNGER_RATE
    or
    inst.components.hunger.burnrate = 1

(Active)Example:
    inst.components.sanity.dapperness = 0.5
    inst.components.health:StartRegen(1, 2)    
    inst.components.hunger.hungerrate =  2 * TUNING.WILSON_HUNGER_RATE
    or
    inst.components.hunger.burnrate = 2

Depending what you wish to be drained/regenerated during rain/while being in caves, you may pick the lines that you need, to later place them into the "base code" that you'll find below. If you don't know how the given lines work, then please check the Health, Sanity, and Hunger drain/regen in the "Set a HP/Sanity/Hunger regen/damage over time" section above, as this will work the same way.

Base code (rain)

    inst:AddTag("notactiverain")
    local function CheckForRain(inst)
        if GetSeasonManager() then
            if not GetSeasonManager():IsRaining() and inst:HasTag("activerain") then
                PLACE HERE THE INACTIVE PERK
                inst:AddTag("notactiverain")
                inst:RemoveTag("activerain")
            end
            if GetSeasonManager():IsRaining() and inst:HasTag("notactiverain") then
                PLACE HERE THE ACTIVE PERK
                inst:AddTag("activerain")
                inst:RemoveTag("notactiverain")
            end
        end
    end
    inst:DoPeriodicTask( 0.0, function(inst) 
        CheckForRain(inst)
    end)


Base code (caves)

    inst:AddTag("notactivecave")
    local function CheckArea(inst)
        if GetWorld() then
            if inst:HasTag("activecave") and not GetWorld():IsCave() then
                PLACE HERE THE INACTIVE PERK
                inst:AddTag("notactivecave")
                inst:RemoveTag("activecave")
            end
            if inst:HasTag("notactivecave") and GetWorld():IsCave() then
                PLACE HERE THE ACTIVE PERK
                inst:AddTag("activecave")
                inst:RemoveTag("notactivecave")
            end
        end
    end
    inst:DoPeriodicTask( 0.0, function(inst)
        CheckArea(inst)
    end)

Side note: If you are working on a custom sanity perk, then remember that unless you have the night/dusk sanity drain turned off, your sanity perk will be affected by it while you're in caves/in the dark.

 

 

--=====REGEN/DAMAGE BASED ON TEMPERATURE=====--

-- Set a health/sanity/hunger regern/damage from temperature --

Spoiler

To make a your character lose/gain sanity/health/hunger when reaching a certain temperature, you'll need to head to your character's prefab file, and in there you'll see the "local fn = function(inst)". We will work mainly IN this function.

Basic lines that you'll be working with
(Inactive)
    inst.components.sanity.dapperness = 0
    inst.components.health:StartRegen(0, 0)    
    inst.components.hunger.hungerrate =  TUNING.WILSON_HUNGER_RATE
    or
    inst.components.hunger.burnrate = 1

(Active)Example:
    inst.components.sanity.dapperness = 0.5
    inst.components.health:StartRegen(1, 2)    
    inst.components.hunger.hungerrate =  2 * TUNING.WILSON_HUNGER_RATE
    or
    inst.components.hunger.burnrate = 2

Depending what you wish to be drained/regenerated when your character will reach the set temperature, you may pick the lines that you need, to later place them into the "base code" that you'll find below. If you don't know how the given lines work, then please check the Health, Sanity, and Hunger drain/regen in the "Set a HP/Sanity/Hunger regen/damage over time" section above, as this will work the same way.

Base code

    local function CheckTemperature(inst)
        if inst.components.temperature then
            local t = inst.components.temperature
            if t:GetCurrent() > 30 and not inst:HasTag("tempy") then
                inst:AddTag("tempy")
                inst:RemoveTag("tempx")
                PLACE HERE THE ACTIVE/INACTIVE PERKS
            end
            if t:GetCurrent() < 30 and not inst:HasTag("tempx") then
                inst:AddTag("tempx")
                inst:RemoveTag("tempy")
                PLACE HERE THE ACTIVE/INACTIVE PERKS
            end
        end
    end
    inst:DoPeriodicTask( 0.0, function(inst)
        CheckTemperature(inst)
    end)

Depending on the temperature that you want your character's perks to react to, you'll need to change the number "30" to higher or lower. The " > " means that the perk will get triggered once your character surpasses the set temperature. The " < " means that the perk will get triggered once your character will go below the set temperature. Depending on when you want your character's perk to get active/inactive, place the active/inactive perks in the right spots.

Temperature info:
Any temperature below 15 is cold.
Any temperature above 60 is hot.
Characters start to freeze when they reach temperature 0.
Characters start to overheat when they reach temperature 70.

 

 

--=====REGEN/DAMAGE BASED ON KILL OR ATTACK=====--

-- Set a sanity/health/hunger loss/gain from attacking creatures --

Spoiler

To make your character lose/gain sanity from attacking creatures, you'll need to head to your character's prefab file, and in there you'll see the "local fn = function(inst)". We will work mainly IN this function.

Sanity/Health/Hunger gain/loss from any creature

    local function OnHit(inst)
        inst.components.sanity:DoDelta(2)
    end
    inst:ListenForEvent("onhitother",OnHit)

Depending on what you wish your character to gain/lose (health, sanity, or hunger) simply change the "components.sanity:DoDelta" to "components.health:DoDelta" or "components.hunger:DoDelta".

This will make your character gain sanity/health/huger when attacking any creature. The number "2" is the amount of sanity/health/hunger that your character will be regaining per attack. To increase/decrease the amount of sanity/health/hunger gain, simply increase/decrease the number in the parentheses. (Remember that you can also use "half numbers" like 0.5, 2.7, 3.1 etc.)

To make your character lose sanity/health/hunger when attacking creatures, simply add a " - " in front of the number. That will cause your character to lose the set amount of sanity/health/hunger. 
(Example: -2. inst.components.sanity:DoDelta(-2) )


Sanity/Health/Hunger gain/loss from specified creature(s)
First, you need to know the prefab name of the creature that you want your character's perk to react to, then you'll be simply placing it into the "base code" that you'll find below.

(If you are not sure, or don't know what is the prefab name of the creature that you want, then you can head to the Don't starve Wiki and look for that creature there. Once you find it check it's "DebugSpawn" code, as this is also it's name.)

Base code

    local function OnHit(target,inst)
        if target and target.prefab then
            if target.prefab == "CreatureHere" then
                inst.components.sanity:DoDelta(
2)
            end

        end
    end
    inst:ListenForEvent( "onhitother", function(inst,data) OnHit(data.target,inst) end )

Depending on what you wish your character to gain/lose (health, sanity, or hunger) simply change the "components.sanity:DoDelta" to "components.health:DoDelta" or "components.hunger:DoDelta".

The number "2" that you see in the parentheses is the amount of sanity/health/hunger that your character will be regaining per hit. You can of course increase/decrease that number to your liking. (Remember that you can also use "half numbers" like 0.5, 2.7, 3.1 etc.)

If you want your character to be losing sanity/health/hunger instead of gaining it, then simply place a " - " in front of the number (Example: -2. inst.components.sanity:DoDelta(-2)). This will make your character lose the set amount of sanity/health/hunger.


Adding more creatures to the list
Let's say for the sake of the example that you wish to make your character lose sanity each time it'll attack a rabbit, and gain sanity when it'll attack a spider. The thing that you'll need to do in order to add more creatures to your list, is to simply copy-paste the lines that I marked with blue, then place the creature's prefab name and set the amount of sanity/health/hunger that your character will be gaining/losing.

Example:

local function OnHit(target,inst)
        if target and target.prefab then
            if target.prefab == "rabbit" then
                inst.components.sanity:DoDelta(
-2)
            end
            if target.prefab == "
spider" then
                inst.components.sanity:DoDelta(
2)
            end

        end
    end
    inst:ListenForEvent( "onhitother", function(inst,data) OnHit(data.target,inst) end )

Just like that, you can add as many creatures to the list as you want.

 

 

-- Set a sanity/health/hunger loss/gain from killing creatures --

Spoiler

To make your character lose/gain sanity/health/hunger from killing creatures, you'll need to head to your character's prefab file, and in there you'll see the "local fn = function(inst)". We will work mainly IN this function.

Sanity gain/loss from any creature

    local function OnKill(inst)
        inst.components.sanity:DoDelta(2)
    end
    inst:ListenForEvent("killed",OnKill)

Depending on what you wish your character to gain/lose (health, sanity, or hunger) simply change the "components.sanity:DoDelta" to "components.health:DoDelta" or "components.hunger:DoDelta".

The number "2" that you see in the parentheses is the amount of sanity/health/hunger that your character will be regaining per kill. You can of course increase/decrease that number to your liking. (Remember that you can also use "half numbers" like 0.5, 2.7, 3.1 etc.)

If you want your character to be losing sanity/health/hunger instead of gaining it, then simply place a " - " in front of the number (Example: -2. inst.components.sanity:DoDelta(-2)). This will make your character lose the set amount of sanity/health/hunger.


Sanity/Health/Hunger gain/loss from specified creature(s)
First, you need to know the prefab name of the creature that you want your character's perk to react to, then you'll be simply placing it into the "base code" that you'll find below.

(If you are not sure, or don't know what is the prefab name of the creature that you want, then you can head to the Don't starve Wiki and look for that creature there. Once you find it check it's "DebugSpawn" code, as this is also it's name.)

Base code

    local function OnKill(victim,inst)
        if victim and victim.prefab then
            if victim.prefab == "CreatureHere" then
                inst.components.sanity:DoDelta(
2)
            end

        end
    end
    inst:ListenForEvent( "killed", function(inst,data) OnKill(data.victim,inst) end )

Depending on what you wish your character to gain/lose (health, sanity, or hunger) simply change the "components.sanity:DoDelta" to "components.health:DoDelta" or "components.hunger:DoDelta".

The number "2" that you see in the parentheses is the amount of sanity/health/hunger that your character will be regaining per kill. You can of course increase/decrease that number to your liking. (Remember that you can also use "half numbers" like 0.5, 2.7, 3.1 etc.)

If you want your character to be losing sanity/health/hunger instead of gaining it, then simply place a " - " in front of the number (Example: -2. inst.components.sanity:DoDelta(-2)). This will make your character lose the set amount of sanity/health/hunger.


Adding more creatures to the list
Let's say for the sake of the example that you wish to make your character lose sanity each time it'll kill  a rabbit, and gain sanity when it'll kill a spider. The thing that you'll need to do in order to add more creatures to your list, is to simply copy-paste the lines that I marked with blue, then place the creature's prefab name and set the amount of sanity/health/hunger that your character will be gaining/losing.

Example:

        local function OnKill(victim,inst)
            if victim and victim.prefab then
                if victim.prefab == "rabbit" then
                    inst.components.sanity:DoDelta(
-2)
                end
                if victim.prefab == "
spider" then
                    inst.components.sanity:DoDelta(
2)
                end

            end
        end
        inst:ListenForEvent( "killed", function(inst,data) OnKill(data.victim,inst) end )

Just like that, you can add as many creatures to the list as you want.

 

 

--=====REGEN/DAMAGE BASED ON ITEMS OR CREATURES=====--

-- Set a sanity regern/damage by equipping an item --

Spoiler

To make a certain item recover/damage your character's Sanity, you'll need to add that perk on the item. So for that you'll need to head to your modmain.lua, and for starters add this line somewhere at the very top.

    GetPlayer = GLOBAL.GetPlayer

We will be using the "GetPlayer()" in this section, so this line will make sure that your mod will know what to do with it instead of crashing.

First, you need to know the prefab name of the item that you want to manipulate, then you'll be simply placing it into the "base code" that you'll find below.

(If you are not sure, or don't know what is the prefab name of the item that you want to manipulate, then you can head to the Don't starve Wiki and look for that item there. Once you find it check it's "DebugSpawn" code, as this is also it's name.)

Base code

    AddPrefabPostInit("ItemHere", function(inst)
        if GetPlayer().prefab == "YourCharacterHere" then
            inst:AddComponent("dapperness")
            inst.components.dapperness.dapperness = TUNING.DAPPERNESS_MED
            inst.components.equippable.dapperness = TUNING.DAPPERNESS_MED
        end
    end)

Place the prefab name of the item and the prefab name of your character in the marked spots. The first line of the code makes the item's perk compatible with DS, while the second line of the code makes it compatible with RoG. If you don't intend on making your mod compatible with both, then you can erase one of the lines keeping only the needed one.

Increase/Decrease the sanity loss/gain
To increase or decrease the amount of sanity that your character will be gaining/losing from the equipped item, all you need to do is change the end of the line ("DAPPERNESS_MED") to the ones available below:
    DAPPERNESS_TINY
    DAPPERNESS_SMALL
    DAPPERNESS_MED
    DAPPERNESS_LARGE
    DAPPERNESS_HUGE

To make your character lose sanity instead of gaining it, all you need to do is add a " - " in front of the "TUNING". That will reverse the way it works.
 Example: -TUNING.DAPPERNESS_MED   
(inst.components.dapperness.dapperness = -TUNING.DAPPERNESS_MED) 

 

 

-- Erase/Increase/Decrease an existing sanity regen/damage on an item --

Spoiler

To remove the sanity ragen/damage from a certain item, you'll need to remove that perk from the item. So for that you'll need to head to your modmain.lua, and for starters add this line somewhere at the very top.

    GetPlayer = GLOBAL.GetPlayer

We will be using the "GetPlayer()" in this section, so this line will make sure that your mod will know what to do with it instead of crashing.

First, you need to know the prefab name of the item that you want to manipulate, then you'll be simply placing it into the "base code" that you'll find below.

(If you are not sure, or don't know what is the prefab name of the item that you want to manipulate, then you can head to the Don't starve Wiki and look for that item there. Once you find it check it's "DebugSpawn" code, as this is also it's name.)

Base code for equippable items (remove)

    AddPrefabPostInit("ItemHere", function(inst)
        if GetPlayer().prefab == "YourCharacterHere" then
            if inst.components.dapperness then
                inst.components.dapperness.dapperness = 0
            else
                inst.components.equippable.dapperness = 0
            end
        end
    end)

Place the prefab name of the item and the prefab name of your character in the marked spots. The blue line of the code makes it compatible with DS, while the purple line of the code makes it compatible with RoG. If you don't intend on making your mod compatible with both, then you can erase one of the lines keeping only the needed one. Which would result in you having only this:

    AddPrefabPostInit("ItemHere", function(inst)
        if GetPlayer().prefab == "YourCharacterHere" then
            inst.components.dapperness.dapperness = 0
        end
    end)


Base code for equippable items (increase/decrease)

    AddPrefabPostInit("ItemHere", function(inst)
        if GetPlayer().prefab == "YourCharacterHere" then
            if inst.components.dapperness then
                inst.components.dapperness.dapperness = TUNING.DAPPERNESS_MED
            else
                inst.components.equippable.dapperness = TUNING.DAPPERNESS_MED
            end
        end
    end)

Place the prefab name of the item and the prefab name of your character in the marked spots. The blue line of the code makes it compatible with DS, while the purple line of the code makes it compatible with RoG. If you don't intend on making your mod compatible with both, then you can erase one of the lines keeping only the needed one. Which would result in you having only this:

    AddPrefabPostInit("ItemHere", function(inst)
        if GetPlayer().prefab == "YourCharacterHere" then
            inst.components.dapperness.dapperness = TUNING.DAPPERNESS_MED
        end
    end)

To increase or decrease the amount of sanity that your character will be gaining/losing from the equipped item, all you need to do is change the end of the line ("DAPPERNESS_MED") to the ones available below:
    DAPPERNESS_TINY
    DAPPERNESS_SMALL
    DAPPERNESS_MED
    DAPPERNESS_LARGE
    DAPPERNESS_HUGE

To make your character lose sanity instead of gaining it, all you need to do is add a " - " in front of the "TUNING". That will reverse the way it works.
 Example: -TUNING.DAPPERNESS_MED   
(inst.components.dapperness.dapperness = -TUNING.DAPPERNESS_MED) 


Base code for non-equippable items (remove)

    AddPrefabPostInit("ItemHere", function(inst)
        if GetPlayer().prefab == "YourCharacterHere" then
            inst:RemoveComponent("sanityaura")
        end
    end)

Place the prefab name of the item and the prefab name of your character in the marked spots. 


Base code for non-equippable items (increase/decrease)

    AddPrefabPostInit("ItemHere", function(inst)
        if GetPlayer().prefab == "YourCharacterHere" then
            inst.components.sanityaura.aura = TUNING.SANITYAURA_MED
        end
    end)

Place the prefab name of the item and the prefab name of your character in the marked spots. To increase or decrease the amount of sanity that your character will be gaining/losing from the item's aura, all you need to do is change the end of the line ("SANITYAURA_MED") to the ones available below:
    SANITYAURA_TINY
    SANITYAURA_SMALL
    SANITYAURA_MED
    SANITYAURA_LARGE
    SANITYAURA_HUGE

To make your character lose sanity instead of gaining it, all you need to do is add a " - " in front of the "TUNING". That will reverse the way it works.
 Example: -TUNING.DAPPERNESS_MED   
(inst.components.dapperness.dapperness = -TUNING.DAPPERNESS_MED

 

 

-- Add a sanity aura heal/damage to an item/creature --

Spoiler

(If an item/creature has a "Sanity Aura" on it, that means that your character will be getting sanity ragen/damage by just standing neat it)
To make a certain item/creature recover/damage your character's Sanity, you'll need to add that perk on the item/creature. So for that you'll need to head to your modmain.lua, and for starters add this line somewhere at the very top.

    GetPlayer = GLOBAL.GetPlayer

We will be using the "GetPlayer()" in this section, so this line will make sure that your mod will know what to do with it instead of crashing.

First, you need to know the prefab name of the item that you want to manipulate, then you'll be simply placing it into the "base code" that you'll find below.

(If you are not sure, or don't know what is the prefab name of the item that you want to manipulate, then you can head to the Don't starve Wiki and look for that item there. Once you find it check it's "DebugSpawn" code, as this is also it's name.)

Base code

    AddPrefabPostInit("ItemHere", function(inst)
        if GetPlayer().prefab == "YourCharacterHere" then
            inst:AddComponent("sanityaura")
            inst.components.sanityaura.aura = TUNING.SANITYAURA_MED
        end
    end)

Place the prefab name of the item and the prefab name of your character in the marked spots. To increase or decrease the amount of sanity that your character will be gaining/losing from the item's aura, all you need to do is change the end of the line ("SANITYAURA_MED") to the ones available below:
    SANITYAURA_TINY
    SANITYAURA_SMALL
    SANITYAURA_MED
    SANITYAURA_LARGE
    SANITYAURA_HUGE

To make your character lose sanity instead of gaining it, all you need to do is add a " - " in front of the "TUNING". That will reverse the way it works.
 Example: -TUNING.DAPPERNESS_MED   
(inst.components.dapperness.dapperness = -TUNING.DAPPERNESS_MED) 

 

 

=========================================================================
Defense / Attack power / Speed
=========================================================================

--=====BASIC=====--

-- Change your character's basic defense/attack power/speed --

Spoiler

In your character's prefab file you'll see the lines:

    inst.components.health.absorb = 0.10    
    inst.components.combat.damagemultiplier = 1
    inst.components.locomotor.walkspeed = 4
    inst.components.locomotor.runspeed = 6

If you don't have them then simply add them along with the rest of your character's stats.
The first line is your character's defense. You can change your character's defense to higher or lower by increasing/decreasing the number "0.10". The number represents the percentage that will be absorbed from the inflicted damage. (Example: 0.10 = 10% less damage, 100 = 100% less damage, 0.25 = 25% less damage... and so on).
The second line is your character's attack power. You can increase your character's attack power by simply increasing the number "1" at the end. As higher the number, as higher attack power your character will have.
The last two lines are your character's movement speed. "walkspeed" is your character normal moving speed, while the "runspeed" is your character's speed when walking with a walking cane or on the roads. To increase/decrease it, simply increase/decrease the numbers at the end. (Remember that you can also use "half numbers" like 0.5, 2.7, 3.1 etc.)

 

 

--=====INCREASE/DECREASE BASED ON TIME OR SEASON=====--

-- Change defense/power/speed based on the time of the day --

Spoiler

To make your character change it's defense/power/speed you'll need to head to your character's prefab file, and in there you'll see the "local fn = function(inst)". We will work mainly IN this function.

Basic lines that you'll be working with
(Inactive)
    inst.components.health.absorb = 0    
    inst.components.combat.damagemultiplier = 0
    inst.components.locomotor.walkspeed = 4
    inst.components.locomotor.runspeed = 6

(Active)Example:
    inst.components.health.absorb = 0.10    
    inst.components.combat.damagemultiplier = 10
    inst.components.locomotor.walkspeed = 5
    inst.components.locomotor.runspeed = 7

Depending what you wish to be increased/decreased during the specified time of day (Day, Dusk, or Night) you may pick the lines that you need, to later place them into the "base code" that you'll find below. If you don't know how the given lines work, then please check the basics in the "Change your character's basic defense/attack power/speed" section above.

Base code

    inst:AddTag("off")
    local function CheckDay(inst)
        if GetClock() and GetWorld() then
            if not GetClock():IsDay() and inst:HasTag("on") and not GetWorld():IsCave() then
                PLACE HERE THE INACTIVE PERK
                inst:AddTag("off")
                inst:RemoveTag("on")
            end
            if GetClock():IsDay() and inst:HasTag("off") and not GetWorld():IsCave() then
                PLACE HERE THE ACTIVE PERK
                inst:AddTag("on")
                inst:RemoveTag("off")
            end
        end
    end
    inst:DoPeriodicTask( 0.0, function(inst) 
        CheckDay(inst)
      end)

Now, depending on which time of the day you want your character's perks to activate (Day, Dusk, or Night) simply change the "GetClock():IsDay()" which I marked, to "GetClock():IsDusk()" or "GetClock():IsNight()". And don't forget to place the lines of your character's active/inactive perks in the marked spot.

 

 

-- Change defense/power/speed based on season --

Spoiler

To make your character change it's defense/power/speed you'll need to head to your character's prefab file, and in there you'll see the "local fn = function(inst)". We will work mainly IN this function.

Basic lines that you'll be working with
(Inactive)
    inst.components.health.absorb = 0    
    inst.components.combat.damagemultiplier = 0
    inst.components.locomotor.walkspeed = 4
    inst.components.locomotor.runspeed = 6

(Active)Example:
    inst.components.health.absorb = 0.10    
    inst.components.combat.damagemultiplier = 10
    inst.components.locomotor.walkspeed = 5
    inst.components.locomotor.runspeed = 7

Depending what you wish to be increased/decreased during the specified season, you may pick the lines that you need, to later place them into the "base code" that you'll find below. If you don't know how the given lines work, then please check the basics in the "Change your character's basic defense/attack power/speed" section above.

Base code (RoG)

    inst:ListenForEvent("seasonChange", function(it, data)
        if data.season == SEASONS.WINTER then
            PLACE HERE THE ACTIVE/INACTIVE PERKS
        end
        if data.season == SEASONS.SPRING then
            PLACE HERE THE ACTIVE/INACTIVE PERKS
        end
        if data.season == SEASONS.AUTUMN then
            PLACE HERE THE ACTIVE/INACTIVE PERKS
        end
        if data.season == SEASONS.SUMMER then
            PLACE HERE THE ACTIVE/INACTIVE PERKS
        end
    end, GetWorld())

Depending on the season that you want your character's perks to activate, place the active perks there, while placing the inactive ones to the section of the other seasons.


Base code (DS) & (RoG)
The normal DS works a bit differently than the DLCs. The game won't notice what season it is unless it just got changed. Therefore we'll need trigger it ourselves.

    inst:ListenForEvent("seasonChange", function(it, data)
        if data.season == SEASONS.WINTER then
            PLACE HERE THE ACTIVE/INACTIVE PERKS
        end
        if data.season == SEASONS.SPRING then
            PLACE HERE THE ACTIVE/INACTIVE PERKS
        end
        if data.season == SEASONS.AUTUMN then
            PLACE HERE THE ACTIVE/INACTIVE PERKS
        end

        if data.season == SEASONS.SUMMER then
            PLACE HERE THE ACTIVE/INACTIVE PERKS
        end
    end, GetWorld())
    inst:PushEvent("seasonChange")

(The last line is literally all we added for it to work!)
Depending on the season that you want your character's perks to activate, place the active perks there, while placing the inactive ones to the section of the other season(s). If you don't intend for your mod to be compatible with RoG then you can erase the grayed out lines, as they won't be necessary.

 

I would try and give also a base code for the SW version, but... I sadly don't have SW to be aware of what is, and what isn't in the game there. Sorry about that.

 

 

--=====INCREASE/DECREASE BASED ON LOCATION OR RAIN=====--

 
-- Change defense/power/speed based on rain or caves --

Spoiler

To make your character change it's defense/power/speed you'll need to head to your character's prefab file, and in there you'll see the "local fn = function(inst)". We will work mainly IN this function.

Basic lines that you'll be working with
(Inactive)
    inst.components.health.absorb = 0    
    inst.components.combat.damagemultiplier = 0
    inst.components.locomotor.walkspeed = 4
    inst.components.locomotor.runspeed = 6

(Active)Example:
    inst.components.health.absorb = 0.10    
    inst.components.combat.damagemultiplier = 10
    inst.components.locomotor.walkspeed = 5
    inst.components.locomotor.runspeed = 7

Depending what you wish to be increased/decreased during rain/while being in caves, you may pick the lines that you need, to later place them into the "base code" that you'll find below. If you don't know how the given lines work, then please check the basics in the "Change your character's basic defense/attack power/speed" section above.

Base code (rain)

    inst:AddTag("offrain")
    local function CheckRain(inst)
        if GetSeasonManager() then
            if not GetSeasonManager():IsRaining() and inst:HasTag("onrain") then
                PLACE HERE THE INACTIVE PERK
                inst:AddTag("offrain")
                inst:RemoveTag("onrain")
            end
            if GetSeasonManager():IsRaining() and inst:HasTag("offrain") then
                PLACE HERE THE ACTIVE PERK
                inst:AddTag("onrain")
                inst:RemoveTag("offrain")
            end
        end
    end
    inst:DoPeriodicTask( 0.0, function(inst) 
        CheckRain(inst)
    end)


Base code (caves)

    inst:AddTag("offcave")
    local function CheckArea(inst)
        if GetWorld() then
            if inst:HasTag("oncave") and not GetWorld():IsCave() then
                PLACE HERE THE INACTIVE PERK
                inst:AddTag("offcave")
                inst:RemoveTag("oncave")
            end
            if inst:HasTag("offcave") and GetWorld():IsCave() then
                PLACE HERE THE ACTIVE PERK
                inst:AddTag("oncave")
                inst:RemoveTag("offcave")
            end
        end
    end
    inst:DoPeriodicTask( 0.0, function(inst)
        CheckArea(inst)
    end)

 

 

--=====INCREASE/DECREASE BASED ON TEMPERATURE=====--

-- Change defense/power/speed based on temperature --

Spoiler

To make your character change it's defense/power/speed you'll need to head to your character's prefab file, and in there you'll see the "local fn = function(inst)". We will work mainly IN this function.

Basic lines that you'll be working with
(Inactive)
    inst.components.health.absorb = 0    
    inst.components.combat.damagemultiplier = 0
    inst.components.locomotor.walkspeed = 4
    inst.components.locomotor.runspeed = 6

(Active)Example:
    inst.components.health.absorb = 0.10    
    inst.components.combat.damagemultiplier = 10
    inst.components.locomotor.walkspeed = 5
    inst.components.locomotor.runspeed = 7

Depending what you wish to be increased/decreased when your character reaches a certain temperature, you may pick the lines that you need, to later place them into the "base code" that you'll find below. If you don't know how the given lines work, then please check the basics in the "Change your character's basic defense/attack power/speed" section above.

Base code

    local function CheckTemperature(inst)
        if inst.components.temperature then
            local t = inst.components.temperature
            if t:GetCurrent() > 30 and not inst:HasTag("tempy") then
                inst:AddTag("tempy")
                inst:RemoveTag("tempx")
                PLACE HERE THE ACTIVE/INACTIVE PERKS
            end
            if t:GetCurrent() < 30 and not inst:HasTag("tempx") then
                inst:AddTag("tempx")
                inst:RemoveTag("tempy")
                PLACE HERE THE ACTIVE/INACTIVE PERKS
            end
        end
    end
    inst:DoPeriodicTask( 0.0, function(inst)
        CheckTemperature(inst)
    end)

Depending on the temperature that you want your character's perks to react to, you'll need to change the number "30" to higher or lower. The " > " means that the perk will get triggered once your character surpasses the set temperature. The " < " means that the perk will get triggered once your character will go below the set temperature. Depending on when you want your character's perk to get active/inactive, place the active/inactive perks in the right spots.

Temperature info:
Any temperature below 15 is cold.
Any temperature above 60 is hot.
Characters start to freeze when they reach temperature 0.
Characters start to overheat when they reach temperature 70.

 

 

=========================================================================
Sensibility / Numbness / Characteristics 
=========================================================================

--=====BASIC=====--

-- Set your character's heat and cold resistance --

Spoiler

To set your character temperature resistance, head to your character's prefab file and add the line(s):

    inst.components.temperature.inherentinsulation = 0    
    inst.components.temperature.inherentsummerinsulation = 0

The first line shows your character's cold resistance, while the second line shows your character's heat resistance. To increase your character's resistance to heat/cold, simply increase the number at the end. As higher the number, as longer it'll take for your character to start freezing/overheating. 
However, don't bother trying to put a negative number (-10, -20, etc.) in an attempt to make your character fragile to heat/cold, as the game is programmed to automatically correct any negative numbers to "0". If you want your character to be fragile to heat/cold, then check the "Make your character fragile/immune to cold/heat" section below.

 

 

-- Increase/Decrease the HP damage when freezing/overheating --

Spoiler

To increase/decrease the amount of damage that your character will be taking while freezing or overheating, head to your character's prefab file and add this line along with the rest of your character's stats.

    inst.components.temperature.hurtrate = 1

The number at the end shows the amount of HP that your character will be losing per second. Simply increase/decrease the number to your liking, and remember that you can also use "half numbers" like 0.5, 2.7, 3.1 etc. (This line works for both, freezing and overheating damage.)

 

 

--=====FRAGILE / IMMUNE=====--

-- Make your character fragile/resistant/immune to heat/cold --

Spoiler

To play with how sensitive your character is to cold/heat, head to your character's prefab file and add this line(s) along with the rest of your character's stats. 
(Note: You don't need to add both if you intend on making your character fragile/immune only to high or only to low temperature.)

    inst.components.temperature.maxtemp = ( 50 )
    inst.components.temperature.mintemp = ( 10 )

This shows the max and the min temperature that your character can reach. Knowing when the characters start to freeze/overheat, helps you be able to set your character to be immune or very fragile to cold/heat.

Temperature info:
Any temperature below 15 is cold.
Any temperature above 60 is hot.
Characters start to freeze when they reach temperature 0.
Characters start to overheat when they reach temperature 70.
The min temperature characters can reach is -25.
The max temperature that characters can reach is 95.


Fragile to cold
Making your character fragile to cold is very simple. By setting your character's max temperature to a low number, (anything below 20) will make your character drop to "0" much faster, than if it would be able to reach max temperature of "70" and higher. However, remember that if you'll set your character's max temperature to be too low, then you'll make your character unable to ever get warm.

Example:  inst.components.temperature.maxtemp = ( 20 )

(Also: This makes your character unable to ever overheat)
(If you want your character to be fragile to cold but still be able to overheat then check the "Max/Min temperatures based on seasons" below.)


Immune to cold
Making your character immune to cold is very simple. By setting your character's min temperature to be anything above 0, means that your character will be unable to ever reach the "freezing temperature" and therefore, won't freeze.

Example: inst.components.temperature.mintemp = ( 5 )


Fragile to heat
Making your character fragile to heat is very simple. By setting your character's min temperature to any number above 60 (But below 70) will make your character reach the temperature of "70" much faster, than if it would be able to reach min temperature of "0" and below. However, remember that if you'll set your character's min temperature to be too high, then you'll make your character unable to ever cool-down.

    Example: inst.components.temperature.mintemp = ( 60 )

(Also: This makes your character unable to ever freeze.)
(If you want your character to be fragile to heat but still be able to freeze then check the "Max/Min temperatures based on seasons" below.)


Immune to heat
Making your character immune to heat is very simple. By setting your character's max temperature to be anything below 70, means that your character will be unable to ever reach the "overheating temperature" and therefore, won't overheat.

Example: inst.components.temperature.maxtemp = ( 60 )


Max/Min temperature based on seasons
If you want your character to be fragile to one temperature but still be able to overheat/freeze, then my advice is to base your character's max and min temperature settings on seasons. Head to your character's prefab file, and in there you'll see the "local fn = function(inst)". We will work mainly IN this function.

Base code

    inst:ListenForEvent("seasonChange", function(it, data)
        if data.season == SEASONS.WINTER then
            PLACE HERE THE MIN/MAX TEMPERATURE PERK
        end
        if data.season == SEASONS.SPRING then
            PLACE HERE THE MIN/MAX TEMPERATURE PERK
        end
        if data.season == SEASONS.AUTUMN then
            PLACE HERE THE MIN/MAX TEMPERATURE PERK
        end
        if data.season == SEASONS.SUMMER then
            PLACE HERE THE MIN/MAX TEMPERATURE PERK
        end
    end, GetWorld())
    inst:PushEvent("seasonChange")

Now, if you don't know how the min and  max temperature works, then please check the fragile/immune to heat/cold explanations above, so you would know how to set your character's temperature perk right.

How it works:
Obviously if you want your character to be fragile to heat, then you would set your character's min temperature to be high during summer but normal during the other seasons.
Or if you want your character to be fragile to cold, then you would set your character's max temp to low during winter but normal during the other seasons. 

 

 

-- Make your character immune to fire --

Spoiler

To make your character immune to fire, simply head to your character's prefab file and add this line along with the rest of your character's stats. 

    inst.components.health.fire_damage_scale = 0

This will make any kind of flame harmless to your character.

 

 

-- Turn your character into a monster or make it "not scary to prey" --

Spoiler

This is one of the easiest things you could set on your character. First, head to your character's prefab file, then add one the lines below. 

If you want your character to be considered a monster then simply add this line along with the rest of your character's stats.

    inst:AddTag("monster")

However, remember that this will also cause the Pigmen and Bunnymen to attack your character on sight. And in RoG it will also make spiders ignore you.

If you want little creatures like rabbits and the goofy gobblers to not run away from your character, then simply add this line along with the rest of your character's stats.

    inst:RemoveTag("scarytoprey")


Make sure that your character keeps the right tags!
Some of the items in the game could remove from your character the tags that you want it to have. To make sure that your character will always be able to reset the needed tags, simply add into your character's prefab file, in the "local fn = function(inst)" this:

    local function CheckTags(inst)
        if inst:HasTag("scarytoprey") then
            inst:RemoveTag("scarytoprey")
        end

        if not inst:HasTag("monster") then
            inst:AddTag("monster")
        end

    end
    inst:DoPeriodicTask( 0.0, function(inst)
        CheckTags(inst)
    end)

This little base code right here will keep an eye on your character's current tags and reset them if changed. ;) 
I marked with 2 different colors the lines responsible for the "scarytoprey" and the "monster" tag so you can easily erase the one you don't need.

 

 

-- Make the spiders/merm ignore your character (if unbothered) --

Spoiler

To make merm and spiders ignore you in both, RoG and DS, you'll need to head to your character's prefab file and add this line along with the rest of your character's stats.

    inst:RemoveTag("character")

This will make both, spiders, and merm simply ignore your character if unbothered.


Make only spiders ignore you
In RoG you can make only spiders ignore you by adding the tag "monster" to your character:

inst:AddTag("monster")


Make only merm ignore you
To make merm ignore you simply add the tag "merm" to your character:

    inst:AddTag("merm")


Make sure that your character keeps the right tags!
Some of the items in the game could remove from your character the tags that you want it to have. To make sure that your character will always be able to reset the needed tags, simply add into your character's prefab file, in the "local fn = function(inst)" this:

    local function CheckTags(inst)
        if not inst:HasTag("merm") then
            inst:AddTag("merm")
        end

        if not inst:HasTag("monster") then
            inst:AddTag("monster")
        end

        if inst:HasTag("character") then
            inst:AddTag("character")
        end

    end
    inst:DoPeriodicTask( 0.0, function(inst)
        CheckTags(inst)
    end)

This little base code right here will keep an eye on your character's current tags and reset them if changed. ;) 
I marked each with a different color so you could easily erase the ones you don't need.

 

 

=========================================================================
Food
=========================================================================

--=====BASIC=====--

-- Set/Change what your character can/can't eat --

Spoiler

To set what your character's food preferences are, simply add this line into your character's prefab file along with the rest of your character's stats.

    inst.components.eater.foodprefs = { "TYPE" }

The food types are:
MEAT  
VEGGIE
INSECT
SEEDS

GENERIC  -  (milk, honey, butter, etc. You can check the Don't Starve Wiki for the full list)
ELEMENTAL  -  (Stones, gems, gold, etc.)
WOOD  -  (logs)

You can add as many food types to your character's preferences as you want.
To add another one, simply place a " , " after the previous type and continue.

    Example: inst.components.eater.foodprefs = { "MEAT", "INSECT", "WOOD" }

 

 

-- Change the amount of sanity/health/hunger that a specified food gives --

Spoiler

To change the amount of sanity/health/hunger that your character receives from certain food(s), you need to change that "food perk" on the specified food. To do that, you'll need to heat to your modmain.lua, and for starters add this line somewhere at the very top.

    GetPlayer = GLOBAL.GetPlayer

We will be using the "GetPlayer()" in this section, so this line will make sure that your mod will know what to do with it instead of crashing.

First, you need to know the prefab name of the food that you want to manipulate, then you'll be simply placing it into the "base code" that you'll find below.

(If you are not sure, or don't know what is the prefab name of the food that you want to manipulate, then you can head to the Don't starve Wiki and look for that food there. Once you find it check it's "DebugSpawn" code, as this is also it's name.)

Basic lines that you'll be working with
(Inactive)
    inst.components.edible.healthvalue = 0
    inst.components.edible.hungervalue = 0
    inst.components.edible.sanityvalue = 0

(Active)Example:
    inst.components.edible.healthvalue = 5
    inst.components.edible.hungervalue = 10 
    inst.components.edible.sanityvalue = 1

Note: Keep in mind that if you won't add one of these lines, then the game will simply use the preset value of the missing category (sanity, health, hunger) for that specified food.

Each line shows how much sanity, health, or hunger your character will receive for the food. You can also use negative numbers if you want the food to deal sanity/health/hunger damage. (Example: inst.components.edible.healthvalue = -5)

Base code

    AddPrefabPostInit("FoodHere", function(inst)
        if GetPlayer().prefab == "YourCharacterHere" then
            PLACE THE CHANGED FOOD PERKS HERE
        end
    end)


Example:

    AddPrefabPostInit("carrot", function(inst)
        if GetPlayer().prefab == "character" then
            inst.components.edible.healthvalue = 2
            inst.components.edible.hungervalue = 0
            inst.components.edible.sanityvalue = -3
        end
    end)

 

 

--=====CUSTOM=====--

-- Create a custom food type/group for your character --

Spoiler

To create a custom food type/group for your character you'll need to do a bit of work in both, modmain.lua and your character's prefab file.

Let's start with modmain.lua.

For starters add this line somewhere at the very top.

    GetPlayer = GLOBAL.GetPlayer

We will be using the "GetPlayer()" in this section, so this line will make sure that your mod will know what to do with it instead of crashing.

So, for the sake of the example let's say that you want your character to only eat Watermelons and Eggplants. Instead of making all of the other foods uneatable, the fastest way would be to simply create a new custom food group for your selected foods and add them to your character.

First, you need to know the prefab name of the food that you want to manipulate, (that would be "watermelon" and "eggplant" for our example) then you'll be simply placing it into the "base code" that you'll find below. I'll provide you with a clean base code, same as an example one for you to see.

(If you are not sure, or don't know what is the prefab name of the food that you want to manipulate, then you can head to the Don't starve Wiki and look for that food there. Once you find it check it's "DebugSpawn" code, as this is also it's name.)

Base code (clean)

    AddPrefabPostInit("FoodHere", function(inst)
        if GetPlayer().prefab == "YourCharacterHere" then
            inst.components.edible.foodtype = "CUSTOM_TYPE"
            (You can add more food perks here if you want. Like sanity/health/hunger values)
        end
    end)


Base code (example)

    AddPrefabPostInit("watermelon", function(inst)
        if GetPlayer().prefab == "character" then
            inst.components.edible.foodtype = "NOM"
        end
    end)
    AddPrefabPostInit("eggplant", function(inst)
        if GetPlayer().prefab == "character" then
            inst.components.edible.foodtype = "NOM"
        end
    end)

In our example the "NOM" is the name of your new custom food group. You can of course name your food group however you want, it doesn't really matter. Just keep in mind that any food that had it's TYPE change, will become uneatable to all of the creatures in the game. You can of course add that custom food group to the needed creatures as well, and I'll show you how to do that at the end of this section.

Now, after sorting your selected foods to your custom food group, we will head into your character's prefab file, and add your new group into your character's food preferences.
To do that, you'll simply need to add these lines along with the rest of your character's stats.

    (Clean)
    inst.components.eater.ablefoods = { "CUSTOM_TYPE" }
    inst.components.eater.foodprefs = { "CUSTOM_TYPE" }

    (Example)
    inst.components.eater.ablefoods = { "NOM" }
    inst.components.eater.foodprefs = { "NOM" }

You can of course also add other existing types along with your custom one.

    Example:
    inst.components.eater.ablefoods = { "NOM", "MEAT", "INSECT" }
    inst.components.eater.foodprefs = { "NOM", "MEAT", "INSECT" }

(For a list of all existing food types, check the "Set/Change what your character can/can't eat" section above.)
And that's it! You have your very own custom food group/type!


Adding your custom food group/type to other creatures
Now, if you are bothered that some creatures won't be able to eat the foods which you manipulated, then you can very easily add your custom food group/type into their food preferences. All you need to do is head to your modmain.lua and add this in there:

Base code (clean)

    AddPrefabPostInit("CreatureHere", function(inst)
        if GetPlayer().prefab == "YourCharacterHere" then
            inst.components.eater.ablefoods = { "CUSTOM_TYPE", "TYPE" }
            inst.components.eater.foodprefs = { "CUSTOM_TYPE", "TYPE" }
        end
    end)


Base code (example)
    AddPrefabPostInit("spider", function(inst)
        if GetPlayer().prefab == "character" then
            inst.components.eater.ablefoods = { "NOM", "MEAT" }
            inst.components.eater.foodprefs = { "NOM", "MEAT" }
        end
    end)

When adding your custom food group/type to other creatures, remember that they all already have a set "vore-type" (they are either omnivore, carnivore, herbivore, etc.) . So you'll need to also re-add the preferences that they already had. (Like in the example)

 

 

-- Make an non-eatable item eatable to your character --

Spoiler

To make a non-eatable item eatable to your character, you need to add the "edible" component to the item, along with it's sanity, health, and hunger values. To do that, you'll need to heat to your modmain.lua, and for starters add this line somewhere at the very top.

    GetPlayer = GLOBAL.GetPlayer

We will be using the "GetPlayer()" in this section, so this line will make sure that your mod will know what to do with it instead of crashing.

So, for the sake of the example let's say that you want your character to be able eat Poop. (Yea, I know. Splendid example!)

First, you need to know the prefab name of the item that you want to manipulate, (That would be "poop" for our example) then you'll be simply placing it into the "base code" that you'll find below. I'll provide you with a clean base code, same as an example one for you to see. 

(If you are not sure, or don't know what is the prefab name of the item that you want to manipulate, then you can head to the Don't starve Wiki and look for that food there. Once you find it check it's "DebugSpawn" code, as this is also it's name.)

Base code (clean)

    AddPrefabPostInit("ItemHere", function(inst)
        if GetPlayer().prefab == "YourCharacterHere" then
            inst:AddComponent("edible")
            inst.components.edible.foodtype = "TYPE"
            inst.components.edible.healthvalue = 0
            inst.components.edible.hungervalue = 0
            inst.components.edible.sanityvalue = 0
        end
    end)


Base code (example)

    AddPrefabPostInit("poop", function(inst)
        if GetPlayer().prefab == "character" then
            inst:AddComponent("edible")
            inst.components.edible.foodtype = "VEGGIE"
            inst.components.edible.healthvalue = -2
            inst.components.edible.hungervalue = 0
            inst.components.edible.sanityvalue = 3
        end
    end)

By making an item edible, you also will need to add a food type/group to it. You can use one of the already existing groups (which are listed in the "Set/Change what your character can/can't eat" section above.) or you can create a new custom group/type for it. (You can check the "Create a custom food type/group for your character" section above for more info.)

However, remember that if you'll use an already existing food type/group for your selected item, then other creatures in the game, which also have that food type/group in their preferences will be able to eat it. But if you'll make a custom group, then only your character will be able to eat it.

The 3 lines that follow, show how much sanity, health, and hunger your character will receive from the food. You can also use negative numbers if you want the food to deal sanity/health/hunger damage. (Example: inst.components.edible.healthvalue = -5)

 

 

=========================================================================
Starter inventory / Night vision / Recipes / Other
=========================================================================

--=====ITEMS=====--

-- Give your character starting inventory items --

Spoiler

To give your character starter inventory items, you'll need to head to your character's prefab file and in there you'll see the line:

       local start_inv = { }

First, you need to know the prefab name of the item that you want to add, then simply place it between then "{ }".

(If you are not sure, or don't know what is the prefab name of the item that you want to add, then you can head to the Don't starve Wiki and look for that item there. Once you find it check it's "DebugSpawn" code, as this is also it's name.)

Example:  local start_inv = { "corn", "carrot", "carrot" }

 

-- Make your character always start with a certain custom item (even in adventure mode) --

Spoiler

If you want your character to always have certain custom item that you made, then you'll need to head to your character's prefab file and in there you'll see the lines:

      local prefabs = {  }
      local start_inv = {  }

First, of course your character needs to have a starter inventory item(s). 
(You can check the "Give your character starting inventory items" section above for more info.)
Then what you need to do is copy-paste the list of custom items that you want your character to always have, into the local prefabs = {  }.

Example:
      local prefabs = { "custom_item_here" }
      local start_inv = { "custom_item_here", "carrot", "carrot" }

After you set that, head to the very bottom of the "local fn = function(inst)" and add this in it. (In the function, not below it)

Base code

    inst:DoTaskInTime(0, function() 
        local found = false
        for k,v in pairs(Ents) do
            if v.prefab == "CustomItemHere" then
                found = true
                break
            end
        end
        if not found then
            inst.components.inventory:GuaranteeItems(prefabs)
        end
    end)

This will keep an eye on your character's custom item(s) each time you'll start/load the game.
Remember that this function will ALWAYS give your character the set item(s), if it/they will be missing from the game not just your character's inventory. So this function is mainly meant to be used for irreplaceable items/items which cannot be crafted nor found.


 

--=====CHARACTER=====--

-- Give your character a night vision/glow --

Spoiler

To give your character a night vision/glow, you'll need to head to  your character's prefab file, and in there you'll see the "local fn = function(inst)". We will work mainly IN this function.

Base code (Night glow)

    local light = inst.entity:AddLight()
    light:SetFalloff(1)
    light:SetIntensity(0.5)
    light:SetRadius(4.0)
    light:SetColour(RRR/255, GGG/255, BBB/255)
    light:Enable(false)
    inst:AddTag("sight_off")
    local function NightGlow(inst)
        if GetClock() and GetWorld() then
            if GetClock():IsDay() and inst:HasTag("sight_on") and not GetWorld():IsCave() or
                GetClock():IsDusk() and inst:HasTag("sight_on") and not GetWorld():IsCave() then
                light:Enable(false)
                inst:AddTag("sight_off")
                inst:RemoveTag("sight_on")
            end
            if GetClock():IsNight() and inst:HasTag("sight_off") or 
                GetWorld():IsCave() and inst:HasTag("sight_off") then
                light:Enable(true)
                inst:AddTag("sight_on")
                inst:RemoveTag("sight_off")
            end
        end
    end
    inst:DoPeriodicTask( 0.0, function(inst)
        NightGlow(inst)
    end)


Base code (Night vision)

    local light = inst.entity:AddLight()
    light:SetFalloff(0.2)
    light:SetIntensity(0.9)
    light:SetRadius(6.0)
    light:SetColour(RRR/255, GGG/255, BBB/255)
    light:Enable(false)
    inst:AddTag("sight_off")
    local function NightVision(inst)
        if GetClock() and GetWorld() then
            if GetClock():IsDay() and inst:HasTag("sight_on") and not GetWorld():IsCave() or
                GetClock():IsDusk() and inst:HasTag("sight_on") and not GetWorld():IsCave() then
                light:Enable(false)
                inst:AddTag("sight_off")
                inst:RemoveTag("sight_on")
            end
            if GetClock():IsNight() and inst:HasTag("sight_off") or 
                GetWorld():IsCave() and inst:HasTag("sight_off") then
                light:Enable(true)
                inst:AddTag("sight_on")
                inst:RemoveTag("sight_off")
            end
        end
    end
    inst:DoPeriodicTask( 0.0, function(inst)
        NightVision(inst)
    end)

Night glow and Night vision are basically the same code with changed light stats. (You can of course play around with the numbers yourself, but just in case you don't, I made those 2 bases for you to pick whichever you need)

Setting the color of your glow/vision
In the first few lines of the base code you can see the line:

    light:SetColour(RRR/255, GGG/255, BBB/255)

This is your color setting. Those 3 sections represent the Red, Green, and Blue amount. By increasing the numbers you are increasing the amount of color that you are adding. Simply  mix the colors until you'll reach the one that you're looking for. 

Example: light:SetColour(019/255, 200/255, 255/255)

Small advice: Try always having at least 001 point in each color, as from my own experience, the game sometimes tends to not recognize only 1 pure corol, which will make your character act as if in complete darkness even though it's not.

 

 

--=====RECIPES=====--

-- Unlock recipes for your character --

Spoiler

If you want your character to already have some recipes unlocked from the start, then head to your character's prefab file and add this line in the "local fn = function(inst)". 

    inst.components.builder:UnlockRecipe("ItemHere")

First, you need to know the prefab name of the item that you want to unlock, then you'll be simply placing it into the line above
Remember that in order to unlock a recipe, such needs to first exist. So if you'll be trying to unlock recipes which don't exist, then that won't work.

(If you are not sure, or don't know what is the prefab name of the item that you want to unlock, then you can head to the Don't starve Wiki and look for it there. Once you find it check it's "DebugSpawn" code, as this is also it's name.)

Example: inst.components.builder:UnlockRecipe("spear")

If you want to unlock many different recipes then simply copy-paste that line as many times as you need, and place the item that you want to be unlocked in the marked spot.

Example
    inst.components.builder:UnlockRecipe("spear")
    inst.components.builder:UnlockRecipe("rope")

 

 

-- Change existing recipes --

Spoiler

If you want your character to be able to craft some items by using different ingredients, then there are 2 different ways of doing it. One is in modmain.lua and the second one is in your character's prefab file. You may use whichever method seems better to you.

Let's start with the modmain.lua method.

For starters add this line somewhere at the very top.

    GetPlayer = GLOBAL.GetPlayer

We will be using the "GetPlayer()" in this section, so this line will make sure that your mod will know what to do with it instead of crashing.

So, for the sake of the example let's say that you want your character to be able to craft a Spear by using 3 twigs, 1 rope, and 2 rocks.

First, you need to know the prefab names of the items that you want to use, (That would be "spear", "twigs", "rope" and "rocks" for our example) then you'll be simply placing them into the "base code" that you'll find below. I'll provide you with a clean base code, same as an example one for you to see. 

(If you are not sure, or don't know what is the prefab name of the items that you want to manipulate, then you can head to the Don't starve Wiki and look for them there. Once you find them check their "DebugSpawn" code, as this is also their name.)

Base code (clean)

    AddSimPostInit(function(inst)
        if GetPlayer().prefab == "YourCharacterHere" then
            local FunctionName = GLOBAL.Recipe("RecipeItemHere", 
                {Ingredient("IngredientHere", 1), Ingredient("IngredientHere", 1)}, 
            RECIPETABS.TAB, {TIER =0} )
        end
    end)


Base code (example)

    AddSimPostInit(function(inst)
        if GetPlayer().prefab == "character" then
            local newspear = GLOBAL.Recipe("spear", 
                {Ingredient("twigs", 3), Ingredient("rope", 1),
                Ingredient("rocks", 2)}, 
            RECIPETABS.FIGHT, {SCIENCE =1} )
        end
    end)

Place the prefab name of the recipe-item, ingredient-item(s), and the name of your character in the marked spots. The number next to the "IngredientHere" is the amount of that certain item that the recipe needs.The "FunctionName " is just (as the text says) a name of the function. You can name it however you like.
If you want to add more ingredients or erase some to make the recipe need less, then add/erase the line:

    Ingredient("IngredientHere", 1)

(You can compare the clean base code and the example one to see the difference.)

The next line:

    RECIPETABS.TAB, {TIER =0} )

Shows in which TAB the recipe will appear, and if you need to use a TIER for it or not.

The existing tabs are:
TOOLS
LIGHT
SURVIVAL
FARM  
-- (Food)
SCIENCE
WAR  
-- (Fight)
TOWN  -- (Structures)
REFINE
MAGIC
DRESS
ANCIENT
BOOKS  
-- (only if you have that tab unlocked and work in your character's prefab file)

NAUTICAL  -- (I do not have SW, so please correct me if I'm wrong here)
VOLCANIC


Tier requirement
SCIENCE =0   -- (Nothing except the recipe items is needed.)
SCIENCE =1   -- (Requires the Science Machine or Alchemy Engine for the prototype.)
SCIENCE =2   -- (Requires the Alchemy Engine for the prototype.)
MAGIC =1   or  (2)   -- (Requires the Prestihatitator or Shadow Manipulator for the prototype.)
MAGIC =3   -- (Requires the Shadow Manipulator for the prototype.)
ANCIENT =1  or  (2)   -- (Requires the Ancient Pseudoscience Station to be made.)
ANCIENT =3  or  (4)   -- (Requires the Ancient Pseudoscience Station (fixed) to be made.)


Now here is the other method that works in your character's prefab file.

So, for the sake of the example let's say that you want your character to be able to craft a Spear by using 3 twigs, 1 rope, and 2 rocks.

First, you need to know the prefab names of the items that you want to use, (That would be "spear", "twigs", "rope" and "rocks" for our example) then you'll be simply placing them into the "base code" that you'll find below. I'll provide you with a clean base code, same as an example one for you to see. 

(If you are not sure, or don't know what is the prefab name of the items that you want to manipulate, then you can head to the Don't starve Wiki and look for them there. Once you find them check their "DebugSpawn" code, as this is also their name.)

Base code (clean)

Recipe("RecipeItemHere", {Ingredient("IngredientHere", 1), Ingredient("IngredientHere", 1)}, RECIPETABS.TAB, {TIER = 0})


Base code (example)

Recipe("spear", {Ingredient("twigs", 2), Ingredient("rope", 1), Ingredient("rocks",3)}, RECIPETABS.WAR, {SCIENCE = 1})

Place the prefab name of the recipe-item, ingredient-item(s), and the name of your character in the marked spots. The number next to the "IngredientHere" is the amount of that certain item that the recipe needs.
If you want to add more ingredients or erase some to make the recipe need less, then add more/erase one of the parts:

    Ingredient("IngredientHere", 1)

(You can compare the clean base code and the example one to see the difference.)

The next part:

    RECIPETABS.TAB, {TIER = 0} )

Shows in which TAB the recipe will appear, and if you need to use a TIER for it or not.
(List of TABS and TIERS is above)

 

 

--=====CUSTOM=====--

-- Give your character custom recipes for existing items --

Spoiler

To give your character a custom recipe for an existing item, you can either do it in your modmain.lua or your character's prefab file. You may use whichever method seems better to you.

Let's start with the modmain.lua method

For starters add this line somewhere at the very top.

    GetPlayer = GLOBAL.GetPlayer

We will be using the "GetPlayer()" in this section, so this line will make sure that your mod will know what to do with it instead of crashing.

So, for the sake of the example let's say that you want your character to be able to craft twigs from a log and a razor.

First, you need to know the prefab names of the items that you want to use, (That would be "twigs", "log" and "razor" for our example) then you'll be simply placing them into the "base code" that you'll find below. I'll provide you with a clean base code, same as an example one for you to see. 

(If you are not sure, or don't know what is the prefab name of the items that you want to use, then you can head to the Don't starve Wiki and look for them there. Once you find them check their "DebugSpawn" code, as this is also their name.)

Base code (clean)

    AddSimPostInit(function(inst)
        if GetPlayer().prefab == "YourCharacterHere" then
            local FunctionName = GLOBAL.Recipe("RecipeItemHere", 
                {Ingredient("IngredientHere", 1), Ingredient("IngredientHere", 1),
                Ingredient("IngredientHere", 1)}, 
            RECIPETABS.TAB, {TIER =0} )
        end
    end)
    GLOBAL.STRINGS.RECIPE_DESC.RECIPE_ITEM_HERE = "Your description here."


Base code (example)

    AddSimPostInit(function(inst)
        if GetPlayer().prefab == "character" then
            local twigscraft = GLOBAL.Recipe("twigs", 
                {Ingredient("log", 1), Ingredient("razor", 1)}, 
            RECIPETABS.REFINE, {SCIENCE =0} )
        end
    end)
    GLOBAL.STRINGS.RECIPE_DESC.TWIGS = "Nicely shaped!"

Place the prefab name of the recipe-item, ingredient-item(s), and the name of your character in the marked spots. The number next to the "IngredientHere" is the amount of that certain item that the recipe needs. The "FunctionName " is just (as the text says) a name of the function. You can name it however you like. The last line of the base code is responsible for the description text that will appear in the recipe window of the item. You can give it whatever description you like.
If you want to add more ingredients or erase some to make the recipe need less, then add more/erase one of the parts: 

    Ingredient("IngredientHere", 1)

(You can compare the clean base code and the example one to see the difference.)

The next line:

    RECIPETABS.TAB, {TIER =0} )

Shows in which TAB the recipe will appear, and if you need to use a TIER for it or not.

The existing tabs are:
TOOLS
LIGHT
SURVIVAL
FARM
 -- (Food)
SCIENCE
WAR  
-- (Fight)
TOWN  -- (Structures)
REFINE
MAGIC
DRESS
ANCIENT
BOOKS
 -- (only if you have that tab unlocked and work in your character's prefab file)

NAUTICAL  -- (I do not have SW, so please correct me if I'm wrong here)
VOLCANIC


Tier requirement
SCIENCE =0   -- (Nothing except the recipe items is needed.)
SCIENCE =1   -- (Requires the Science Machine or Alchemy Engine for the prototype.)
SCIENCE =2   -- (Requires the Alchemy Engine for the prototype.)
MAGIC =1   or  (2)   -- (Requires the Prestihatitator or Shadow Manipulator for the prototype.)
MAGIC =3   -- (Requires the Shadow Manipulator for the prototype.)
ANCIENT =1  or  (2)   -- (Requires the Ancient Pseudoscience Station to be made.)
ANCIENT =3  or  (4)   -- (Requires the Ancient Pseudoscience Station (fixed) to be made.)


Now here is the other method that works in your character's prefab file.

So, for the sake of the example let's say that you want your character to be able to craft twigs from a log and a razor.

First, you need to know the prefab names of the items that you want to use, (That would be "twigs", "log" and "razor" for our example) then you'll be simply placing them into the "base code" that you'll find below. I'll provide you with a clean base code, same as an example one for you to see. 

(If you are not sure, or don't know what is the prefab name of the items that you want to use, then you can head to the Don't starve Wiki and look for them there. Once you find them check their "DebugSpawn" code, as this is also their name.)

Base code (clean)

Recipe("RecipeItemHere", {Ingredient("IngredientHere", 1), Ingredient("IngredientHere", 1), Ingredient("IngredientHere", 1)}, 
RECIPETABS.TAB, {TIER = 0})
STRINGS.RECIPE_DESC.RECIPE_ITEM_HERE= "Your description here."


Base code (example)

Recipe("twigs", {Ingredient("log", 1), Ingredient("razor", 1)}, RECIPETABS.REFINE, {SCIENCE = 0})
STRINGS.RECIPE_DESC.TWIGS = "Nicely shaped!"

Place the prefab name of the recipe-item, ingredient-item(s), and the name of your character in the marked spots. The number next to the "IngredientHere" is the amount of that certain item that the recipe needs. The last line of the base code is responsible for the description text that will appear in the recipe window of the item. You can give it whatever description you like.
If you want to add more ingredients or erase some to make the recipe need less, then add more/erase one of the parts:

    Ingredient("IngredientHere", 1)

(You can compare the clean base code and the example one to see the difference.)

The next part:

    RECIPETABS.TAB, {TIER = 0} )

Shows in which TAB the recipe will appear, and if you need to use a TIER for it or not.
(List of TABS and TIERS is above)

 

 

--=====OTHER=====--

-- Remove the sanity gain/loss from picking flowers --

Spoiler

I actually saw people asking that quite often, so I decided to add that little code right here for you to use if you need it. Place it/them in your modmain.lua.

Normal flowers

    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)


Evil flowers

AddPrefabPostInit("flower_evil", 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
        inst:RemoveComponent("sanityaura")
    end
end)

Keep the blue line if you also want to remove the negative sanity aura from the evil flowers.
And remember to place your character's prefab name in the marked spot.

 

 

=========================================================================

And that would be the end of this tutorial. 

It took me 5 days to compose all this, so I really hope that at least some of you might find it helpful.

However, if any of this parts/sections confused you, then please feel free to ask me whatever it is that you didn't understand, and I'll try to explain it differently to hopefully help you out.

Also:
Please, do not ask any question that have nothing to do with this tutorial (nor anything it shows) in here.
(Just trying to avoid unnecessary mess in the comments) ^^;

Edited by BraveChicken
  • Like 3
  • Thanks 1

Share this post


Link to post
Share on other sites
Siletrea    18

you my friend are a gem!

this is absolutely fantastic! I wish this was made a few years back honestly! but I'm just so happy its here now! I'm positive this will get oodles of views once hamlet comes out for all the new mods!

fantastic work!

  • Like 1

Share this post


Link to post
Share on other sites
axxel    181

Thanks :). But could you tidy up a bit? I mean you can use spoiler or create a table of contents for Ctrl-F navigation.

Share this post


Link to post
Share on other sites
BraveChicken    16
8 hours ago, axxel said:

you can use spoiler or create a table of contents for Ctrl-F navigation

I actually did try to do that due to the fact that this tutorial is soooo looong. ^-^; (I actually am new to klei forums .... and... forums in general, so I'm still kinda learning how these things work XD) But I'm guessing that maybe I did something wrong, because it didn't want to work the way it should  o,o;
I guess I can give it another try XD

And there is a table of contents at the very top.  (I guess I can try to simple it down a bit more  o,o)

Hopefully I'll manage to make it better. :p 
Thanks for the input though! ^-^

 

  • Thanks 1

Share this post


Link to post
Share on other sites
K1NGT1GER609    95

Nice work, a lot of code in the forums become lost overtime (I mean 226 pages? and the search engine is limited to 30+ second penalty per search!) and heck some of the code I post is lost even when I look at my profile for previous posts.

  • Like 1

Share this post


Link to post
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