Jump to content

Recommended Posts

Hello,

I'm trying to add a few new foodtypes to my mod. My endgoal is to have specific, existing items, and use them to feed a very picky NPC.

I am encountering an issue where my "constants.lua" file, the one where all the foodtypes appear to be, does not get overwritten by my mod.

I copied the "constants.lua" file in my mod's "scripts" folder, with the following additions

FOODTYPE =
{
    GENERIC = "GENERIC",
    MEAT = "MEAT",
    VEGGIE = "VEGGIE",
    ELEMENTAL = "ELEMENTAL",
    GEARS = "GEARS",
    HORRIBLE = "HORRIBLE",
    INSECT = "INSECT",
    SEEDS = "SEEDS",
    BERRY = "BERRY", --hack for smallbird; berries are actually part of veggie
    RAW = "RAW", -- things which some animals can eat off the ground, but players need to cook
    BURNT = "BURNT", --For lavae.
    ROUGHAGE = "ROUGHAGE",
	WOOD = "WOOD",
    GOODIES = "GOODIES",
    MONSTER = "MONSTER", -- Added in for woby, uses the secondary foodype originally added for the berries
	TIER2 = "TIER2",
}

(I only added the "Tier2" part, the rest was already there)

And further down : 

	TIER2 =
    {
        name = "TIER2",
        types =
        {
			FOODTYPE.TIER2,
        },
    },

Then, in the "gem.lua" file, I added the line


        inst.components.edible.foodtype = FOODTYPE.TIER2

However, when I'm trying to feed the red gem to the NPC, it won't accept it. This makes me believe that the new foodtype is not recognized by the gem prefab for some reason.

Can someone point me in the right direction?

Thank you!

see my comment here for an example:

but try to think carefully, how you could make your mod compatible to game updates and also other mods (since foodtpye seems to exclusive). Unfortunately, as written in my comment there, I don't have a good idea for that right now.

Edited by Serpens
14 hours ago, penguin0616 said:

@xovoxx You also have to modify the NPC's eater component to also accept your new food type.

Right! I forgot to mention it in my post, but I did that.

I do it right after the NPC eats something else

local function OnEatFirstMeal(inst)
    inst.components.inspectable:SetDescription("He's not hungry anymore! Nice!")
	
    inst.components.eater:SetDiet({ FOODGROUP.TIER2 })
	if numberOfMeals == 0 then
		inst.components.inspectable:SetDescription("He looks better, but still hungry! He would love something shiny.")
	end
	if numberOfMeals == 1 then
		inst.components.inspectable:SetDescription("He's not hungry anymore! Nice!")
	end
	
	numberOfMeals = numberOfMeals + 1
end

 

9 hours ago, Serpens said:

see my comment here for an example:

but try to think carefully, how you could make your mod compatible to game updates and also other mods (since foodtpye seems to exclusive). Unfortunately, as written in my comment there, I don't have a good idea for that right now.

Thanks for the reply! I'm not too worried about compatibility with other mods, I'm doing something really personal for close friends.

What I can see from your post is that writing
 

GLOBAL.FOODTYPE.NIGHTMAREFUEL = "NIGHTMAREFUEL"

in modmain declares this new foodtype, and then I can use it anywhere in my mod?

  • Sanity 1
On 9/30/2020 at 5:50 PM, penguin0616 said:

@xovoxx How is it supposed to be able to accept the new food type if it doesn't get set until after it eats it? 

You need to set the diet BEFORE.

I think you might be misunderstanding what I'm trying to do. I want to be able to feed it anything from its original diet, and THEN adjust its diet so it becomes more picky.

17 minutes ago, penguin0616 said:

Yeah. You still have to set the initial diet.

Even if it's for an existing NPC? (I'm editing the moleworm)

Also, I added the following to my modmain

GLOBAL.FOODTYPE.TIER2 = "TIER2"

AddPrefabPostInit("gem",function(inst)
    inst:AddComponent("edible")
    inst.components.edible.foodtype = GLOBAL.FOODTYPE.TIER2
    inst.components.edible.healthvalue = 10
    inst.components.edible.hungervalue = 20
    inst.components.edible.sanityvalue = 5
end)

Which seems to work. However, this is still not working

local function OnEatFirstMeal(inst)
    inst.components.inspectable:SetDescription("He's not hungry anymore! Nice!")
	
    inst.components.eater:SetDiet({ FOODGROUP.TIER2 })
	if numberOfMeals == 0 then
		inst.components.inspectable:SetDescription("He looks better, but still hungry! He would love something shiny.")
	end
	if numberOfMeals == 1 then
		inst.components.inspectable:SetDescription("He's not hungry anymore! Nice!")
	end
	
	numberOfMeals = numberOfMeals + 1
end

What happens is this : 

- I feed the moleworm his usual meal (Since it has its usual diet, that I did not change).

- After feeding it once, it looks as if the game did not recognize my FOODGROUP.TIER2 constant, and the moleworm no longer eats anything.

@penguin0616

I'll try to rephrase what I'm trying to do. I'm probably not clear enough!

What I want to happen :

- Feed the moleworm any "ELEMENTAL" food once.

- Then, I want to be able to feed "TIER2" food, and only "TIER2" food, to the moleworm

What actually happens :

- I feed the moleworm any "ELEMENTAL" food once, successfully.

- Then, when I attempt to feed the red gem (A "TIER2" food item, thanks to the script in modmain) to the moleworm, the "feed" prompt does not show up.

- Additionally, any "ELEMENTAL" food is no longer accepted (the "feed" prompt does not show up).

 

Does that make more sense?

Edited by xovoxx

/facepalm that couldn't have helped.

However, I fixed it and it doesn't work any better.

Is there a way to add this function to modmain? Instead of having it in mole.lua, where it currently is.

local function OnEatFirstMeal(inst)
    inst.components.inspectable:SetDescription("He's not hungry anymore! Nice!")
	
    inst.components.eater:SetDiet({ FOODTYPE.TIER2 })
	if numberOfMeals == 0 then
		inst.components.inspectable:SetDescription("He looks better, but still hungry! He would love something shiny.")
		SpawnPrefab("flowerhat").Transform:SetPosition(inst.Transform:GetWorldPosition())
	end
	if numberOfMeals == 1 then
		inst.components.inspectable:SetDescription("He's not hungry anymore! Nice!")
		SpawnPrefab("amulet").Transform:SetPosition(inst.Transform:GetWorldPosition())
	end
	
	numberOfMeals = numberOfMeals + 1
end

 

You shouldn't be replacing DST prefabs. That being said,

local function OnEatFirstMeal(inst)
	-- too lazy to copy your code
	-- also, you can use eater:TimeSinceLastEating() to figure out when they last ate.
end

AddPrefabPostInit("mole", function(inst)
	inst.eater:SetOnEatFn(OnEatFirstMeal) -- will now trigger whenever moleworm eats something
end)

 

Edited by penguin0616
  • Like 1

Thanks @penguin0616 !

That makes sense. 

That being said, I get the same result as before.

Here's my updated "modmain" code

GLOBAL.FOODTYPE.TIER2 = "TIER2"

AddPrefabPostInit("gem",function(inst)
    inst:AddComponent("edible")
    inst.components.edible.foodtype = GLOBAL.FOODTYPE.TIER2
    inst.components.edible.healthvalue = 10
    inst.components.edible.hungervalue = 20
    inst.components.edible.sanityvalue = 5
end)

local function OnEatFirstMeal(inst)
    inst.components.eater:SetDiet({ GLOBAL.FOODTYPE.TIER2 })
	inst.components.inspectable:SetDescription("He looks better, but still hungry! He would love something shiny.")
	SpawnPrefab("flowerhat").Transform:SetPosition(inst.Transform:GetWorldPosition())
end

AddPrefabPostInit("mole", function(inst)
	inst.components.eater:SetOnEatFn(OnEatFirstMeal) -- will now trigger whenever moleworm eats something
end)

I should note that the description does get updated to "He looks better, but still hungry! He would love something shiny."

Thanks a lot for your help! I'm learning a lot thanks to your input :)

Edited by xovoxx

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