BraveChicken

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

Recommended Posts

Siletrea    20

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    1,015

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    35
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    122

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
BraveChicken    35
13 hours ago, RudyAmericanHero said:

is there a way to use certain items like lucy or wes's balloons or abigail's flower?

Yes, there is. But if you want to give your character the ability to start/use those items then you would need to modify them in your mod, and remove from them the "characterspecific" component. (This component is used to make an item bounded only to 1 specified character)
If you want to do that, then you will need to look into the game's prefab files (in the main don't starve folder, go to data >> scripts >> prefabs) Then you will need to look for the prefab file that you want to modify and copy-paste it into your mod's folder. after you do that simply open the copy of the file that you just made and remove from it the lines:

     inst:AddComponent("characterspecific")
    inst.components.characterspecific:SetOwner("woodie")

or turn them off by simply placing a " -- " in front of them like that:

    --inst:AddComponent("characterspecific")
    --inst.components.characterspecific:SetOwner("woodie")

In Abigail's flower file you also will need to look for the line:

     if not GetPlayer() or GetPlayer().prefab ~= "wendy" then inst:Remove() end 

and for Wes's ballons the line:

     inst:DoTaskInTime(0, function() if not GetPlayer() or GetPlayer().prefab ~= "wes" then inst:Remove() end end)

and remove it/turn it off as this keeps an eye on the character's prefab file and removes the item if it isn't wendy/wes.

Then head to your modmain.lua and add your modified file to the PrefabFiles = { } section along with the prefab file of your character. So it should look something like that:

     PrefabFiles = { "YourCharacterHere", "lucy" }

Then of course you can either create a custom recipe to craft those items or simply make your character start with that item (You can find in the tutorial how to do both of those so you can pick whichever you like) :p 

Edited by BraveChicken

Share this post


Link to post
Share on other sites

sorry, I realized maybe this thread is for dont starve only, I found out in of the sections, where I wanna increase my character's ability at night, there's a GetClock() function that is not been recognized by the system. I figured it might have to do with the DS and DST. I wonder if I am right, if yes what is the correct function name to use in this example? Thanks!!

Share this post


Link to post
Share on other sites
BraveChicken    35
10 hours ago, ricky_loves_cat said:

there's a GetClock() function that is not been recognized by the system. I figured it might have to do with the DS and DST. I wonder if I am right, if yes what is the correct function name to use in this example? Thanks!

If you are working on a DST mod, then yes, there are differences in coding between the "normal" DS and the DST. I would gladly help you if I could, but sadly I do not have DST to even be aware of the coding differences that would need to be made there. However, you may want to ask for help in the DST mods and tools forum section, as I'm sure you'll manage to find someone to help you there. I'm sorry that I can't be of more help.

Edited by BraveChicken

Share this post


Link to post
Share on other sites
On 18.07.2018 at 5:55 PM, BraveChicken said:

Yes, there is. But if you want to give your character the ability to start/use those items then you would need to modify them in your mod, and remove from them the "characterspecific" component. (This component is used to make an item bounded only to 1 specified character)
If you want to do that, then you will need to look into the game's prefab files (in the main don't starve folder, go to data >> scripts >> prefabs) Then you will need to look for the prefab file that you want to modify and copy-paste it into your mod's folder. after you do that simply open the copy of the file that you just made and remove from it the lines:

     inst:AddComponent("characterspecific")
    inst.components.characterspecific:SetOwner("woodie")

or turn them off by simply placing a " -- " in front of them like that:

    --inst:AddComponent("characterspecific")
    --inst.components.characterspecific:SetOwner("woodie")

In Abigail's flower file you also will need to look for the line:

     if not GetPlayer() or GetPlayer().prefab ~= "wendy" then inst:Remove() end 

and for Wes's ballons the line:

     inst:DoTaskInTime(0, function() if not GetPlayer() or GetPlayer().prefab ~= "wes" then inst:Remove() end end)

and remove it/turn it off as this keeps an eye on the character's prefab file and removes the item if it isn't wendy/wes.

Then head to your modmain.lua and add your modified file to the PrefabFiles = { } section along with the prefab file of your character. So it should look something like that:

     PrefabFiles = { "YourCharacterHere", "lucy" }

Then of course you can either create a custom recipe to craft those items or simply make your character start with that item (You can find in the tutorial how to do both of those so you can pick whichever you like) :p 

how can i make nightvision use with button for example open nightvision press F To Open Nightvision

Share this post


Link to post
Share on other sites
BraveChicken    35
On 11/25/2018 at 11:22 PM, 690739_1452792444 said:

how can i make nightvision use with button for example open nightvision press F To Open Nightvision

I never played around with adding such to a button, so I won't be able to help you out too much with this right now, but I know a mod that did create and use different button commands. Puppy princess Musha
You could look around in the files of this mod to see how the buttons there are scripted.
(I would have checked it out myself but I do not have that much free time lately. Sorry about that)

Edit:
Nevermind! I couldn't resist checking it out!
Here's what you'll need:

Head to your character's prefab file and add in the local fn = function(inst) these lines:

    local light = inst.entity:AddLight()
    light:SetFalloff(0.2)
    light:SetIntensity(0.9)
    light:SetRadius(6.0)
    light:SetColour(001/255, 255/255, 050/255)
    light:Enable(false)
    inst:AddTag("nvoff")

Then head to your modmain.lua and add in there this:

GetPlayer = GLOBAL.GetPlayer
GLOBAL.TheInput:AddKeyDownHandler(GLOBAL.KEY_F, function()
    local light = GetPlayer().entity:AddLight()
    if GetPlayer():HasTag("nvon") then
        light:Enable(false)
        GetPlayer():AddTag("nvoff")
        GetPlayer():RemoveTag("nvon")
        print("Night vision is OFF.")
    elseif GetPlayer():HasTag("nvoff") then   
        light:Enable(true)
        GetPlayer():AddTag("nvon")
        GetPlayer():RemoveTag("nvoff")
        print("Night vision is ON.")
    end
end)

You can of course change the colors of your night vision (The tutorial explains how to do that) and the button from "F" to another by just changing the "F" in the "GLOBAL.KEY_F" which I marked, to the one which you would like to use. This should be enough to make it work.

Edited by BraveChicken

Share this post


Link to post
Share on other sites
VictorG2Ah    0

when I put the custom sanity gain / loss commands, I did as it was in the tutorial, but it did not work, the sanity icon was blinking on the gain and loss arrows at the same time, where did I go wrong?

I'll leave as I put the command

   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
                inst.components.sanity.dapperness = 0
                inst:AddTag("notactive")
                inst:RemoveTag("active")
            end
            if GetClock():IsDay() and inst:HasTag("notactive") and not GetWorld():IsCave() then
                inst.components.sanity.dapperness = 0.3
                inst:AddTag("active")
                inst:RemoveTag("notactive")
            end
        end
    end
    inst:DoPeriodicTask( 0.0, function(inst) 
        CheckTime(inst)
    end)

   inst:AddTag("notactive")
    local function CheckTime(inst)
        if GetClock() and GetWorld() then
            if not GetClock():IsDusk() and inst:HasTag("active") and not GetWorld():IsCave() then
                inst.components.sanity.dapperness = 0
                inst:AddTag("notactive")
                inst:RemoveTag("active")
            end
            if GetClock():IsDusk() and inst:HasTag("notactive") and not GetWorld():IsCave() then
                inst.components.sanity.dapperness = -0.15
                inst:AddTag("active")
                inst:RemoveTag("notactive")
            end
        end
    end
    inst:DoPeriodicTask( 0.0, function(inst) 
        CheckTime(inst)
    end)

   inst:AddTag("notactive")
    local function CheckTime(inst)
        if GetClock() and GetWorld() then
            if not GetClock():IsNight() and inst:HasTag("active") and not GetWorld():IsCave() then
                inst.components.sanity.dapperness = 0
                inst:AddTag("notactive")
                inst:RemoveTag("active")
            end
            if GetClock():IsNight() and inst:HasTag("notactive") and not GetWorld():IsCave() then
                inst.components.sanity.dapperness = -0.4
                inst:AddTag("active")
                inst:RemoveTag("notactive")
            end
        end
    end
    inst:DoPeriodicTask( 0.0, function(inst) 
        CheckTime(inst)
    end)

Please help me

Share this post


Link to post
Share on other sites
BraveChicken    35
11 hours ago, VictorG2Ah said:

when I put the custom sanity gain / loss commands, I did as it was in the tutorial, but it did not work, the sanity icon was blinking on the gain and loss arrows at the same time, where did I go wrong?

The problem is that you putted the same sanity function 3 times in a row. And all of them work with the same tags, which makes the game flicker between all of them all the time. But reading your script I can see what you were trying to do. So here's how to fix that:

inst:AddTag("notactive")
    local function CheckTime(inst)
        if GetClock() and GetWorld() then
            if GetClock():IsDay() and (inst:HasTag("notactive") or inst:HasTag("activedusk") or inst:HasTag("activenight")) and not GetWorld():IsCave() then
                inst.components.sanity.dapperness = 0.3
                inst:AddTag("activeday")
                inst:RemoveTag("notactive")
                inst:RemoveTag("activedusk")
                inst:RemoveTag("activenight")
            end
            if GetClock():IsDusk() and (inst:HasTag("notactive") or inst:HasTag("activeday") or inst:HasTag("activenight")) and not GetWorld():IsCave() then
                inst.components.sanity.dapperness = -0.15
                inst:AddTag("activedusk")
                inst:RemoveTag("notactive")
                inst:RemoveTag("activeday")
                inst:RemoveTag("activenight")
            end
            if GetClock():IsNight() and (inst:HasTag("notactive") or inst:HasTag("activedusk") or inst:HasTag("activeday")) and not GetWorld():IsCave() then
                inst.components.sanity.dapperness = -0.4
                inst:AddTag("activenight")
                inst:RemoveTag("notactive")
                inst:RemoveTag("activedusk")
                inst:RemoveTag("activeday")
            end
        end
    end
    inst:DoPeriodicTask( 0.0, function(inst) 
        CheckTime(inst)
    end)


Try using this instead. I simply combined everything into 1.
I marked you the Day, Dusk, and Night parts along with your custom sanity perk so you could easily change it if you'd like :) 

Share this post


Link to post
Share on other sites
BraveChicken    35
On 1/19/2019 at 3:53 AM, bloopers said:

where exactly do i put the code in the file?

Everything is literally explained in the tutorial o.o
All lines go either in the modmain.lua or in your character's prefab file in the "local fn = function(inst)"

Every section tells you exactly where to place the  Base code which you are given.

If you feel confused about one of the sections then let me know which one it is so I could give you more directions/help.

Share this post


Link to post
Share on other sites
Scrumch    82

I don't know if you can still help, but is there a way to completely negate the sanity penalty from equipping wet items? The sanity drain for moisture seems to only work for the wetness of the character. Also the sanity regain in the rain doesn't stay for the entire period of rain, is that supposed to happen?

  • Like 1

Share this post


Link to post
Share on other sites
EscapeMan4    1

I did the custom Food Type thing and i tried adding multiple food items, and this is the code

GetPlayer = GLOBAL.GetPlayer

-- Food Pref
AddPrefabPostInit("log", function(inst)
    if GetPlayer().prefab == "fbot" then
        inst:AddComponent("edible")
        inst.components.edible.foodtype = "FLAMABLE"
        inst.components.edible.healthvalue = -55
        inst.components.edible.hungervalue = -55
        inst.components.edible.sanityvalue = -30
        end
    end)     
AddPrefabPostInit("petals", function(inst)
        if GetPlayer().prefab == "fbot" then
        inst:AddComponent("edible")
        inst.components.edible.foodtype = "FLAMABLE"
        inst.components.edible.healthvalue = -55
        inst.components.edible.hungervalue = -55
        inst.components.edible.sanityvalue = -30
        end
    end)

(the negative stats are just for testing)

When I add two or more Items this happens

 image.png.e6e142c3e95850ac640bb0c1e2eb2cea.png

 

Can someone help me with this please

Share this post


Link to post
Share on other sites
EscapeMan4    1
20 hours ago, EscapeMan4 said:

I did the custom Food Type thing and i tried adding multiple food items, and this is the code

GetPlayer = GLOBAL.GetPlayer

-- Food Pref
AddPrefabPostInit("log", function(inst)
    if GetPlayer().prefab == "fbot" then
        inst:AddComponent("edible")
        inst.components.edible.foodtype = "FLAMABLE"
        inst.components.edible.healthvalue = -55
        inst.components.edible.hungervalue = -55
        inst.components.edible.sanityvalue = -30
        end
    end)     
AddPrefabPostInit("petals", function(inst)
        if GetPlayer().prefab == "fbot" then
        inst:AddComponent("edible")
        inst.components.edible.foodtype = "FLAMABLE"
        inst.components.edible.healthvalue = -55
        inst.components.edible.hungervalue = -55
        inst.components.edible.sanityvalue = -30
        end
    end)

(the negative stats are just for testing)

When I add two or more Items this happens

 image.png.e6e142c3e95850ac640bb0c1e2eb2cea.png

 

Can someone help me with this please

Edit: I Figured out that it only crashes for certain items like Logs and Cut Grass

Share this post


Link to post
Share on other sites
htv1lla1n    9

Can't turn off the moisture sanity penalty (SW). 

I put the code under the local(fn) = function(inst), and copypasted the code there. So the code's 

Quote

    inst:DoTaskInTime( 0.1, function(inst) 
        if inst.components.moisture then
            local m = inst.components.moisture
            if m:GetMoisture() then
                TUNING.MOISTURE_SANITY_PENALTY_MAX = 0
            end
        end
    end)

But the game ignores it completely. No crash, nothing - I just get the sanity drain. 
 

I'm figuring I need a different code for SW? 

 

EDIT: Items. Ok, I need a code to remove the sanity penalty from wet items. can't figure it out. 

Edited by htv1lla1n
^^

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