Fuffles Posted November 6, 2016 Share Posted November 6, 2016 (edited) 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 November 6, 2016 by DragonflyTheGiant Link to comment https://forums.kleientertainment.com/forums/topic/71462-doing-something-on-pickup-of-a-vanilla-tile/ Share on other sites More sharing options...
alainmcd Posted November 6, 2016 Share Posted November 6, 2016 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. Link to comment https://forums.kleientertainment.com/forums/topic/71462-doing-something-on-pickup-of-a-vanilla-tile/#findComment-834279 Share on other sites More sharing options...
Fuffles Posted November 6, 2016 Author Share Posted November 6, 2016 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 Link to comment https://forums.kleientertainment.com/forums/topic/71462-doing-something-on-pickup-of-a-vanilla-tile/#findComment-834309 Share on other sites More sharing options...
alainmcd Posted November 6, 2016 Share Posted November 6, 2016 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? Link to comment https://forums.kleientertainment.com/forums/topic/71462-doing-something-on-pickup-of-a-vanilla-tile/#findComment-834311 Share on other sites More sharing options...
Fuffles Posted November 6, 2016 Author Share Posted November 6, 2016 (edited) 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 November 6, 2016 by DragonflyTheGiant Link to comment https://forums.kleientertainment.com/forums/topic/71462-doing-something-on-pickup-of-a-vanilla-tile/#findComment-834324 Share on other sites More sharing options...
alainmcd Posted November 6, 2016 Share Posted November 6, 2016 Sorry, I don't know why that would be. Is the mod activated on the server? Other than that, I'm out of ideas. Maybe post the content of your modmain.lua and modinfo.lua so I (or someone smarter) can take a look at it? Link to comment https://forums.kleientertainment.com/forums/topic/71462-doing-something-on-pickup-of-a-vanilla-tile/#findComment-834329 Share on other sites More sharing options...
Fuffles Posted November 6, 2016 Author Share Posted November 6, 2016 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) Link to comment https://forums.kleientertainment.com/forums/topic/71462-doing-something-on-pickup-of-a-vanilla-tile/#findComment-834331 Share on other sites More sharing options...
Lumina Posted November 6, 2016 Share Posted November 6, 2016 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) Link to comment https://forums.kleientertainment.com/forums/topic/71462-doing-something-on-pickup-of-a-vanilla-tile/#findComment-834335 Share on other sites More sharing options...
Fuffles Posted November 6, 2016 Author Share Posted November 6, 2016 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! Link to comment https://forums.kleientertainment.com/forums/topic/71462-doing-something-on-pickup-of-a-vanilla-tile/#findComment-834337 Share on other sites More sharing options...
alainmcd Posted November 6, 2016 Share Posted November 6, 2016 Heads up, your mod will crash for clients. Add these lines if not GLOBAL.TheWorld.ismastersim then return end to the beginning of your fernsets and flowersets functions. Link to comment https://forums.kleientertainment.com/forums/topic/71462-doing-something-on-pickup-of-a-vanilla-tile/#findComment-834346 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now