Sign in to follow this  
soaringblaze

Custom Edibility

Recommended Posts

So, basically, I'm making a personal character mod. I would like for said character (and only the character) to be able eat bone shards to regain health and sanity, but I have no idea how to code it (this is my first time making a mod of any kind). Can I have some help, please?

Share this post


Link to post
Share on other sites
nateonus    1

So, as the mechanic you're describing is very similar to WX78's mechanic of eating gears, I recommend you look at that.

WX78's instance has a line that says:

table.insert(inst.components.eater.foodprefs, "GEARS")

You need to add something like this to the new character, however instead of gears you would add in the ID for bone shards (I believe it's "BONESHARD").

 

Now you need to add in the edible component for bone shards. The following is the code within the gears' instance that adds this.

    inst:AddComponent("edible")
    inst.components.edible.foodtype = "GEARS"
    inst.components.edible.healthvalue = TUNING.HEALING_HUGE
    inst.components.edible.hungervalue = TUNING.CALORIES_HUGE
    inst.components.edible.sanityvalue = TUNING.SANITY_HUGE

So, you need to access the bone shards' instance when your mod loads, and add in the component 'edible'. You will then need to set the values to whatever you want them to be, and this should work.

 

Hopefully this helps :)

Share this post


Link to post
Share on other sites
BraveChicken    19
Posted (edited)

You can actually very easilly add any kind of food stats and edibility to any kind of item in the game.
All you need is to head to your mondmain.lua and add this in it:
    
GetPlayer = GLOBAL.GetPlayer    
AddPrefabPostInit("boneshard", function(inst)
        if GetPlayer().prefab == "YourCharacterHere" then
            inst:AddComponent("edible")
            inst.components.edible.foodtype = "NOMS"
            inst.components.edible.healthvalue = 5
            inst.components.edible.sanityvalue = 5
            inst.components.edible.hungervalue = 5
        end
    end)
    
This will add the edibility to the bone shards. Of course you can change the numbers "5" to increase/decrease the sanity, health, and hunger values that they will give to your character.
The "NOMS" is your new custom food group. You can give it any name you want really, it doesn't really matter.
Then you will need to head to your character's prefab file and add that new custom food group into your character, like this:
    
    inst.components.eater.ablefoods = { "NOMS", "MEAT", "VEGGIE", "INSECT", "SEEDS", "GENERIC" }
    inst.components.eater.foodprefs = { "NOMS", "MEAT", "VEGGIE", "INSECT", "SEEDS", "GENERIC" } 
    
    (Place it along with your character's stats)

Or... a different approach would be to simply place them into an already existing food group like this:

 AddPrefabPostInit("boneshard", function(inst)
        if GetPlayer().prefab == "YourCharacterHere" then
            inst:AddComponent("edible")
            inst.components.edible.foodtype = "VEGGIE"
            inst.components.edible.healthvalue = 5
            inst.components.edible.sanityvalue = 5
            inst.components.edible.hungervalue = 5
        end
    end)

However this might cause other creatures react to it as food as well (for example the pigmen might attempt to eat them if they spot them laying on the ground, that's why I believe that creating a custom food group would be the best idea)

 I also talked about creating custom food groups in here:
  


(Just in case you're interested)
    
I hope this will solve some of your problems.
And good luck with your mod ^-^

Edited by BraveChicken

Share this post


Link to post
Share on other sites
On 6/3/2018 at 1:01 PM, BraveChicken said:

GetPlayer = GLOBAL.GetPlayer    
AddPrefabPostInit("boneshard", function(inst)
        if GetPlayer().prefab == "YourCharacterHere" then
            inst:AddComponent("edible")
            inst.components.edible.foodtype = "NOMS"
            inst.components.edible.healthvalue = 5
            inst.components.edible.sanityvalue = 5
            inst.components.edible.hungervalue = 5
        end
    end)

I seem to have encountered a slight issue. What goes in the parentheses "GetPlayer().prefab"? My game crashes when I try to play as my custom character, and the error screen says there's an issue with that specific part.

Share this post


Link to post
Share on other sites
BraveChicken    19
14 hours ago, soaringblaze said:

What goes in the parentheses "GetPlayer().prefab"?

Nothing does. o.o
The only thing that you should change is the "YourCharacterHere" which should be replaced with your character's prefab name.
It would be helpful if I could see your crash log, so I could see what exactly is the issue in that one part. ^^;

Also, just to be sure, I need to ask (as many new member  tend to do this mistake)
You are attempting to make a mod which is compatible with DS, RoG and/or SW. Right?  o.o
Because if you are working on a mod which you wish to be compatible with DST then this is the wrong forum section for this.
The right forum section for it is the [Don't Starve Together] Mods and tools where you can get a lot more help if you're working on a DST mod. :) 

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

Sign in to follow this