penguin0616 Posted September 15, 2020 Share Posted September 15, 2020 @JennaBelle You can stick it next to any of the other :AddComponent()'s. 1 Link to comment https://forums.kleientertainment.com/forums/topic/121450-how-to-make-it-so-a-character-can-only-eat-a-specific-item/page/2/#findComment-1371386 Share on other sites More sharing options...
ninidelos Posted September 15, 2020 Share Posted September 15, 2020 I think you have to add it to your copy of the nighmarefuel.lua (or whatever you named it) since it's the item you want to make edible Link to comment https://forums.kleientertainment.com/forums/topic/121450-how-to-make-it-so-a-character-can-only-eat-a-specific-item/page/2/#findComment-1371525 Share on other sites More sharing options...
DecDuck Posted September 15, 2020 Share Posted September 15, 2020 Ok, after some testing, the problem is as follows: @JennaBelle has put the :AddComponent("edible") in nightmarefuel.lua. The problem is that the component is failing to initialise because she is trying to set the foodtype of one that doesn't exist (I think). Nevertheless, I found a solution. Looking at WX-78's code, there is some code that allows him to eat gears. In modmain: PrefabFiles = { "nightmarefuel" } AddPrefabPostInit("wilson",function(inst) if inst.components.eater~=nil then local _TestFood_Old = inst.components.eater.TestFood or (function() return end) inst.components.eater.TestFood = function(self,food,testvalues) if food:HasTag("nightmarefuel_food") then return true end return false --return _TestFood_Old(self,food,testvalues) end table.insert(inst.components.eater.preferseating, "NIGHTMAREFUEL") table.insert(inst.components.eater.caneat, "NIGHTMAREFUEL") inst:AddTag("NIGHTMAREFUEL_eater") end end) And nightmarefuel.lua: local assets = { Asset("ANIM", "anim/nightmarefuel.zip"), } local function fn() local inst = CreateEntity() inst.entity:AddTransform() inst.entity:AddAnimState() inst.entity:AddNetwork() MakeInventoryPhysics(inst) inst.AnimState:SetBank("nightmarefuel") inst.AnimState:SetBuild("nightmarefuel") inst.AnimState:PlayAnimation("idle_loop", true) inst.AnimState:SetMultColour(1, 1, 1, 0.5) MakeInventoryFloatable(inst) inst.entity:SetPristine() if not TheWorld.ismastersim then return inst end inst:AddComponent("stackable") inst.components.stackable.maxsize = TUNING.STACK_SIZE_SMALLITEM inst:AddComponent("inspectable") inst:AddComponent("fuel") inst.components.fuel.fueltype = FUELTYPE.NIGHTMARE inst.components.fuel.fuelvalue = TUNING.LARGE_FUEL inst:AddComponent("edible") inst.components.edible.foodtype = "NIGHTMAREFUEL" inst.components.edible.healthvalue = 0 inst.components.edible.hungervalue = 0 inst.components.edible.sanityvalue = 0 inst:AddTag("nightmarefuel_food") MakeHauntableLaunch(inst) inst:AddComponent("inventoryitem") return inst end return Prefab("nightmarefuel", fn, assets) There. Link to comment https://forums.kleientertainment.com/forums/topic/121450-how-to-make-it-so-a-character-can-only-eat-a-specific-item/page/2/#findComment-1371592 Share on other sites More sharing options...
JennaBelle Posted September 16, 2020 Author Share Posted September 16, 2020 4 hours ago, decduck3 said: Ok, after some testing, the problem is as follows: @JennaBelle has put the :AddComponent("edible") in nightmarefuel.lua. The problem is that the component is failing to initialise because she is trying to set the foodtype of one that doesn't exist (I think). Nevertheless, I found a solution. Looking at WX-78's code, there is some code that allows him to eat gears. In modmain: PrefabFiles = { "nightmarefuel" } AddPrefabPostInit("wilson",function(inst) if inst.components.eater~=nil then local _TestFood_Old = inst.components.eater.TestFood or (function() return end) inst.components.eater.TestFood = function(self,food,testvalues) if food:HasTag("nightmarefuel_food") then return true end return false --return _TestFood_Old(self,food,testvalues) end table.insert(inst.components.eater.preferseating, "NIGHTMAREFUEL") table.insert(inst.components.eater.caneat, "NIGHTMAREFUEL") inst:AddTag("NIGHTMAREFUEL_eater") end end) And nightmarefuel.lua: local assets = { Asset("ANIM", "anim/nightmarefuel.zip"), } local function fn() local inst = CreateEntity() inst.entity:AddTransform() inst.entity:AddAnimState() inst.entity:AddNetwork() MakeInventoryPhysics(inst) inst.AnimState:SetBank("nightmarefuel") inst.AnimState:SetBuild("nightmarefuel") inst.AnimState:PlayAnimation("idle_loop", true) inst.AnimState:SetMultColour(1, 1, 1, 0.5) MakeInventoryFloatable(inst) inst.entity:SetPristine() if not TheWorld.ismastersim then return inst end inst:AddComponent("stackable") inst.components.stackable.maxsize = TUNING.STACK_SIZE_SMALLITEM inst:AddComponent("inspectable") inst:AddComponent("fuel") inst.components.fuel.fueltype = FUELTYPE.NIGHTMARE inst.components.fuel.fuelvalue = TUNING.LARGE_FUEL inst:AddComponent("edible") inst.components.edible.foodtype = "NIGHTMAREFUEL" inst.components.edible.healthvalue = 0 inst.components.edible.hungervalue = 0 inst.components.edible.sanityvalue = 0 inst:AddTag("nightmarefuel_food") MakeHauntableLaunch(inst) inst:AddComponent("inventoryitem") return inst end return Prefab("nightmarefuel", fn, assets) There. It didn't work. After implementing it and loading my game I was sent back to character select then it froze and crashed. Link to comment https://forums.kleientertainment.com/forums/topic/121450-how-to-make-it-so-a-character-can-only-eat-a-specific-item/page/2/#findComment-1371643 Share on other sites More sharing options...
penguin0616 Posted September 16, 2020 Share Posted September 16, 2020 @JennaBelle You should post the crash log so we can figure out the issue. 1 Link to comment https://forums.kleientertainment.com/forums/topic/121450-how-to-make-it-so-a-character-can-only-eat-a-specific-item/page/2/#findComment-1371646 Share on other sites More sharing options...
JennaBelle Posted September 17, 2020 Author Share Posted September 17, 2020 On 9/15/2020 at 9:09 PM, penguin0616 said: @JennaBelle You should post the crash log so we can figure out the issue. If you mean where it tells me on screen what the error is and where, it didn't show me that. As I said, I tried loading my game and it sent me back to character select then froze and crashed. No error message, it just stopped working. Link to comment https://forums.kleientertainment.com/forums/topic/121450-how-to-make-it-so-a-character-can-only-eat-a-specific-item/page/2/#findComment-1371939 Share on other sites More sharing options...
DecDuck Posted September 17, 2020 Share Posted September 17, 2020 Post the server log. Link to comment https://forums.kleientertainment.com/forums/topic/121450-how-to-make-it-so-a-character-can-only-eat-a-specific-item/page/2/#findComment-1372206 Share on other sites More sharing options...
JennaBelle Posted September 19, 2020 Author Share Posted September 19, 2020 On 9/17/2020 at 4:10 PM, decduck3 said: Post the server log. Where do I find it? Link to comment https://forums.kleientertainment.com/forums/topic/121450-how-to-make-it-so-a-character-can-only-eat-a-specific-item/page/2/#findComment-1372653 Share on other sites More sharing options...
penguin0616 Posted September 19, 2020 Share Posted September 19, 2020 I'll assume you're on windows. Documents -> Klei -> DoNotStarveTogether Grab the client_log.txt, and post it here.If for some reason you decided to do the testing on a world with caves, there is an additional log to submit. One of the folders in there is your 32bit steam ID. It's also most likely the only folder in there. The folder name will be entirely numbers. Open it. There will be a bunch of folders named Cluster_# The # corresponds to which save slot it is. Cluster_1 is the first save slot, Cluster_5 is the fifth save slot. Open the one with the save slot you've been testing on. Grab server_log.txt from the Master folder if you were in the forest, grab it from the Caves folder if you were in the caves. 1 Link to comment https://forums.kleientertainment.com/forums/topic/121450-how-to-make-it-so-a-character-can-only-eat-a-specific-item/page/2/#findComment-1372737 Share on other sites More sharing options...
JennaBelle Posted September 20, 2020 Author Share Posted September 20, 2020 16 hours ago, penguin0616 said: I'll assume you're on windows. Documents -> Klei -> DoNotStarveTogether Grab the client_log.txt, and post it here.If for some reason you decided to do the testing on a world with caves, there is an additional log to submit. One of the folders in there is your 32bit steam ID. It's also most likely the only folder in there. The folder name will be entirely numbers. Open it. There will be a bunch of folders named Cluster_# The # corresponds to which save slot it is. Cluster_1 is the first save slot, Cluster_5 is the fifth save slot. Open the one with the save slot you've been testing on. Grab server_log.txt from the Master folder if you were in the forest, grab it from the Caves folder if you were in the caves. I can't find it. Also, my number isn't going to be the only one. My sister uses my computer to play her steam games too. Link to comment https://forums.kleientertainment.com/forums/topic/121450-how-to-make-it-so-a-character-can-only-eat-a-specific-item/page/2/#findComment-1372875 Share on other sites More sharing options...
penguin0616 Posted September 20, 2020 Share Posted September 20, 2020 @JennaBelleAlternately, I recently found out you can use the "Data" button in DST and it will take you there. However, for the crash to actually be present in the logs, you have to submit the logs before you re-open DST. Which means you'll have to: 1) Open DST and press "Data", leave the folder open. 2) Go trigger your crash. 3) Close DST and submit the files. 1 Link to comment https://forums.kleientertainment.com/forums/topic/121450-how-to-make-it-so-a-character-can-only-eat-a-specific-item/page/2/#findComment-1372947 Share on other sites More sharing options...
Serpens Posted September 21, 2020 Share Posted September 21, 2020 (edited) Please do it correct from the start, so NOT overwrite the nightmarefuel.lua file. Delete it from your modfolder. Instead you can do everything within modmain.lua. This way it is also easy to apply to any other character, without editing other files at all. Put this into modmain.lua and adjust to your liking: GLOBAL.FOODTYPE.NIGHTMAREFUEL = "NIGHTMAREFUEL" -- the following few lines are the change of nightmarefuel, so no need to overwrite the whole file AddPrefabPostInit("nightmarefuel",function(inst) inst:AddComponent("edible") inst.components.edible.foodtype = GLOBAL.FOODTYPE.NIGHTMAREFUEL inst.components.edible.healthvalue = 10 inst.components.edible.hungervalue = 20 inst.components.edible.sanityvalue = 5 end) AddPlayerPostInit(function(inst) if inst.prefab=="wilson" then -- replace wilson with your character prefab if inst.components.eater==nil then inst:AddComponent("eater") end inst.components.eater:SetDiet({ GLOBAL.FOODTYPE.NIGHTMAREFUEL }) -- only allow to eat this foodtype we defined above end end) This will work without any errors (tested). But: If any user is using another mod, that also makes nightmarefuel edible, the mods will conflict and one will not work correctly. I tried to find a good way to make any of such mods compatible, but I fear there is no easy way without modyfiing game code... (and then all mods would need to use such modified code, to make sure it is compatible) Edited February 18, 2021 by Serpens 1 Link to comment https://forums.kleientertainment.com/forums/topic/121450-how-to-make-it-so-a-character-can-only-eat-a-specific-item/page/2/#findComment-1373145 Share on other sites More sharing options...
JennaBelle Posted September 23, 2020 Author Share Posted September 23, 2020 On 9/21/2020 at 11:56 AM, Serpens said: Please do it correct from the start, so NOT overwrite the nightmarefuel.lua file. Delete it from your modfolder. Instead you can do everything within modmain.lua. This way it is also easy to apply to any other character, without editing other files at all. Put this into modmain.lua and adjust to your liking: GLOBAL.FOODTYPE.NIGHTMAREFUEL = "NIGHTMAREFUEL" -- the following few lines are the change of nightmarefuel, so no need to overwrite the whole file AddPrefabPostInit("nightmarefuel",function(inst) inst:AddComponent("edible") inst.components.edible.foodtype = GLOBAL.FOODTYPE.NIGHTMAREFUEL inst.components.edible.healthvalue = 10 inst.components.edible.hungervalue = 20 inst.components.edible.sanityvalue = 5 end) AddPlayerPostInit(function(inst) if inst.prefab=="wilson" then -- replace wilson with your character prefab if inst.components.eater==nil then inst.AddComponent("eater") end inst.components.eater:SetDiet({ GLOBAL.FOODTYPE.NIGHTMAREFUEL }) -- only allow to eat this foodtype we defined above end end) This will work without any errors (tested). But: If any user is using another mod, that also makes nightmarefuel edible, the mods will conflict and one will not work correctly. I tried to find a good way to make any of such mods compatible, but I fear there is no easy way without modyfiing game code... (and then all mods would need to use such modified code, to make sure it is compatible) That seems to be working perfectly. Thank you! Will I be able to replace nightmare fuel with other items though? Link to comment https://forums.kleientertainment.com/forums/topic/121450-how-to-make-it-so-a-character-can-only-eat-a-specific-item/page/2/#findComment-1373478 Share on other sites More sharing options...
DecDuck Posted September 23, 2020 Share Posted September 23, 2020 Yes I think you can. Sorry about leading you on a wild goose chase. 1 Link to comment https://forums.kleientertainment.com/forums/topic/121450-how-to-make-it-so-a-character-can-only-eat-a-specific-item/page/2/#findComment-1373526 Share on other sites More sharing options...
Near4422 Posted February 18, 2021 Share Posted February 18, 2021 On 9/21/2020 at 6:56 PM, Serpens said: Please do it correct from the start, so NOT overwrite the nightmarefuel.lua file. Delete it from your modfolder. Instead you can do everything within modmain.lua. This way it is also easy to apply to any other character, without editing other files at all. Put this into modmain.lua and adjust to your liking: GLOBAL.FOODTYPE.NIGHTMAREFUEL = "NIGHTMAREFUEL" -- the following few lines are the change of nightmarefuel, so no need to overwrite the whole file AddPrefabPostInit("nightmarefuel",function(inst) inst:AddComponent("edible") inst.components.edible.foodtype = GLOBAL.FOODTYPE.NIGHTMAREFUEL inst.components.edible.healthvalue = 10 inst.components.edible.hungervalue = 20 inst.components.edible.sanityvalue = 5 end) AddPlayerPostInit(function(inst) if inst.prefab=="wilson" then -- replace wilson with your character prefab if inst.components.eater==nil then inst.AddComponent("eater") end inst.components.eater:SetDiet({ GLOBAL.FOODTYPE.NIGHTMAREFUEL }) -- only allow to eat this foodtype we defined above end end) This will work without any errors (tested). But: If any user is using another mod, that also makes nightmarefuel edible, the mods will conflict and one will not work correctly. I tried to find a good way to make any of such mods compatible, but I fear there is no easy way without modyfiing game code... (and then all mods would need to use such modified code, to make sure it is compatible) Hey guys! I am currently trying to actually let my character eat nightmare fuel and just found your topic. I tried copying the code quoted above into my modmain.lua but it actually doesn't work and causes error (attatched below). Anybody got an idea what is happening? The line 47 is essentialy this part: inst.AddComponent("eater") Link to comment https://forums.kleientertainment.com/forums/topic/121450-how-to-make-it-so-a-character-can-only-eat-a-specific-item/page/2/#findComment-1430766 Share on other sites More sharing options...
Serpens Posted February 18, 2021 Share Posted February 18, 2021 (edited) Unfortunately I often do not test code I write on the fly for the forum, sry (while I did test this one, but not in every single situation, eg the one that the character has no eater component already) Of course it must be: inst:AddComponent("eater") Edited February 18, 2021 by Serpens Link to comment https://forums.kleientertainment.com/forums/topic/121450-how-to-make-it-so-a-character-can-only-eat-a-specific-item/page/2/#findComment-1430779 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