Jump to content

Recommended Posts

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.

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.

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.

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.
 

  • Like 1
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.

@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.

  • Like 1

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 by Serpens
  • Thanks 1
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?

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")

 

Screenshot_2.png

Unfortunately I often do not test code I write on the fly for the forum, sry :D
(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 by Serpens

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...