Jump to content

Recommended Posts

Hello Dont Starvians,

I recently started modding for Dont Starve Together and Im trying to add the same thing as for flowers to the cave ferns, this is what Im currently using but it doesnt work, please help!
 

Quote

local function fernpick(inst, picker)
    if picker and picker.components.sanity and GetModConfigData("fernsanity") == ("true") then
        picker.components.sanity:DoDelta(TUNING.SANITY_TINY)
    else
        --No Sanity Reward
    end
end

AddPrefabPostInit("cave_fern", fernpick)

 

Edited by DragonflyTheGiant

Your function in AddPrefabPostInit() is called when the prefab is spawned, and should tell the game how to edit the prefab's behaviour. You want to modify the fern's behaviour when it's picked, so you'll want to change the prefabs pickable component, which is what controls this action.

local function onpickedfn(inst, picker)
	if picker and picker.components.sanity then
		picker.components.sanity:DoDelta(TUNING.SANITY_TINY)
	end
	inst:Remove()
end

local function FernPostInit(inst)
    inst.components.pickable.onpickedfn = onpickedfn
end

AddPrefabPostInit("cave_fern", FernPostInit)

FernPostInit() is called when a fern is spawned into the world (via worldgen, loading or console) and it tells the game to override the onpickedfn function of the pickable component with your new onpickedfn.

1 hour ago, alainmcd said:

Your function in AddPrefabPostInit() is called when the prefab is spawned, and should tell the game how to edit the prefab's behaviour. You want to modify the fern's behaviour when it's picked, so you'll want to change the prefabs pickable component, which is what controls this action.


local function onpickedfn(inst, picker)
	if picker and picker.components.sanity then
		picker.components.sanity:DoDelta(TUNING.SANITY_TINY)
	end
	inst:Remove()
end

local function FernPostInit(inst)
    inst.components.pickable.onpickedfn = onpickedfn
end

AddPrefabPostInit("cave_fern", FernPostInit)

FernPostInit() is called when a fern is spawned into the world (via worldgen, loading or console) and it tells the game to override the onpickedfn function of the pickable component with your new onpickedfn.

Sadly as I tried it didnt change anything, althought thanks for the effort

 

It's working for me. I'm using the code in my previous post as the modmain.lua, and the code below as the modinfo.lua:

name = "Fern test"
description = ""
author = ""
restart_required = false
forumthread = ""
version = "1"
api_version = 10
dont_starve_compatible = false
reign_of_giants_compatible = false
dst_compatible = true
all_clients_require_mod = false
client_only_mod = false

In any case, do you receive any error message?

28 minutes ago, alainmcd said:

It's working for me. I'm using the code in my previous post as the modmain.lua, and the code below as the modinfo.lua:


name = "Fern test"
description = ""
author = ""
restart_required = false
forumthread = ""
version = "1"
api_version = 10
dont_starve_compatible = false
reign_of_giants_compatible = false
dst_compatible = true
all_clients_require_mod = false
client_only_mod = false

In any case, do you receive any error message?

No, it only doesnt give any sanity on pickup and by any chance do you know how to check if its daytime? not twilight/night

Edited by DragonflyTheGiant

Its enabled but Imma post the whole code anyway
Modinfo
 

Quote

name = "Enviromental Tweaks"
description = "Small tweaks to make your surviving a bit better!"
author = "Fuffles"
version = "1.0"

forumthread = ""

api_version = 10

icon_atlas = "tweaks.xml"
icon = "tweaks.tex"

dst_compatible = true

all_clients_require_mod = true
restard_required = false

server_filter_tags = 
{
    "enviromental tweaks",
}

configuration_options=
{
    {
        name = "flowerstrenght",
        label = "Flower Sanity Aura",
        options =
        {
            {description = "None", data = "0"},
            {description = "Tiny", data = "1"},
            {description = "Small", data = "2"},
            {description = "Normal", data = "3"},
        },
        default = "0"
    },
    {
        name = "fernstrenght",
        label = "Fern Sanity Aura",
        options =
        {
            {description = "None", data = "0"},
            {description = "Tiny", data = "1"},
            {description = "Small", data = "2"},
            {description = "Normal", data = "3"},
        },
        default = "0"
    },
    {
        name = "fernsanity",
        label = "Fern Sanity on pickup",
        options =
        {
            {description = "No", data = false},
            {description = "Yes", data = true},
        },
        default = true
    },
}
 

Modmain
 

Quote

local require = GLOBAL.require

local function flowersets(inst)
    inst:AddComponent("sanityaura")
    if GetModConfigData("flowerstrenght") == ("1") then
        inst.components.sanityaura.aura = TUNING.SANITYAURA_SUPERTINY
    elseif GetModConfigData("flowerstrenght") == ("2") then
        inst.components.sanityaura.aura = TUNING.SANITYAURA_TINY
    elseif GetModConfigData("flowerstrenght") == ("3") then
        inst.components.sanityaura.aura = TUNING.SANITYAURA_SMALL
    else
    --No Aura
    end
end

AddPrefabPostInit("flower", flowersets)

local function pickfern(inst, picker)
    if picker and picker.components.sanity then
        picker.components.sanity:DoDelta(TUNING.SANITY_TINY)
    end
    inst:Remove()
end

local function fernsets(inst)
    inst:AddComponent("sanityaura")
    if GetModConfigData("fernstrenght") == ("1") then
        inst.components.sanityaura.aura = TUNING.SANITYAURA_SUPERTINY
    elseif GetModConfigData("fernstrenght") == ("2") then
        inst.components.sanityaura.aura = TUNING.SANITYAURA_TINY
    elseif GetModConfigData("fernstrenght") == ("3") then
        inst.components.sanityaura.aura = TUNING.SANITYAURA_SMALL
    else
        --No Aura
    end
    
    inst.components.pickable.pickfern = pickfern
end

AddPrefabPostInit("cave_fern", fernsets)

 

I don't understand the code very well, but why this line is :

     inst.components.pickable.pickfern = pickfern

Shouldn't be :

    inst.components.pickable.onpickedfn = onpickedfn

Or at least

    inst.components.pickable.onpickedfn = pickfern

I was thinking that the "inst.components.pickable.onpickedfn" part is fixed by the game (by the pickable component) and that you can't change the name of it, no ? And if you want to start a custom function, you change the = nameofyourfunction, but not the first part ?
 

(Sorry if i'm wrong, i'm just trying to understand how it works)

5 minutes ago, Lumina said:

I don't understand the code very well, but why this line is :


     inst.components.pickable.pickfern = pickfern

Shouldn't be :


    inst.components.pickable.onpickedfn = onpickedfn

Or at least


    inst.components.pickable.onpickedfn = pickfern

I was thinking that the "inst.components.pickable.onpickedfn" part is fixed by the game (by the pickable component) and that you can't change the name of it, no ? And if you want to start a custom function, you change the = nameofyourfunction, but not the first part ?
 

(Sorry if i'm wrong, i'm just trying to understand how it works)

Yes you were right, thanks a lot for help!

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
×
  • Create New...