Jump to content

[TUTORIAL] Fun With Food


Ultroman
 Share

Recommended Posts

On 8/12/2020 at 10:31 PM, Scrumch said:

I just found out that if you run the "Applying DIFFERENT Values To Several Food Entities" snippet to a mod and then run that mod in a server with Caves enabled, it cause a game crash? I think?

Anyways, I fixed it by just adding the edible component to the for food_prefab, food_stats in pairs(food_stat_dict) do part.

How do you mean?

-----------------------------------------------------------------------------------------------------------------------------------------------

On 2/18/2021 at 1:08 AM, Near4422 said:

I' am trying to change the values for the MonsterMeat for my character.
I've added this code to the modmain.lua, as your tutorial says:
 


AddPrefabPostInit("monstermeat", function(inst)
	inst.components.edible.healthvalue = 10
	inst.components.edible.hungervalue = 10
	inst.components.edible.sanityvalue = 10
end)

And for whatever reason i do get crash everytime i try to interact with monstermeat.
The error message attatched.

Could I ask for a help here?

Screenshot_1.png

Are you by any chance joining your own dedicated server or playing on your own computer with Caves on? Because then it sounds like you are missing some IsServer-checks to see whether the code is being executed on the server or a client. ONLY the server should run this code, because ONLY on the server do the entities have "full components", whereas on clients they just have some "replica components" which facilitate sharing of state and interaction with the server. There are sources to find on how to do IsServer-checks properly, but since I can't even seem to do this right for my own mods, I should not be advising people on how to do it :)

Edited by Ultroman
Link to comment
Share on other sites

On 12/6/2019 at 11:09 PM, bizziboi said:

Just stumbled across this - not sure if this could work, couldn't you make the item a unique foodtype and only extend the character to have that in their diet?

I don't know much about the game code, so I may be way off but figured I'd throw it out there.

Im having a bit of trouble putting this into code form, what could we do for that? also, would this still be compatible with ShowMe?

Link to comment
Share on other sites

Hey there!

I've tried to make some foods inedible with the coding in the article, but I feel like I misunderstand something: I can't make it work. The survivor still capable to eat the banned foods.

I put these lines into my master_postnit section:

Spoiler

 

local inedibles = {
    "spoiled_food",
    "petals",
    "foliage",
    "lightbulb",
    "ice",
    "seeds",
    "foliage"
    }

    local old_CanEat = inst.components.eater.CanEat
    inst.components.eater.CanEat = function(self, food_inst)
        for i, v in ipairs(inedibles) do
            if food_inst.prefab == v then
                return false
            end
        end
        return old_CanEat(self, food_inst)
    end

 

What do I do wrong?

Thanks in advance for the help!

Edited by C_Thun
Link to comment
Share on other sites

On 3/27/2021 at 8:29 PM, C_Thun said:

Hey there!

I've tried to make some foods inedible with the coding in the article, but I feel like I misunderstand something: I can't make it work. The survivor still capable to eat the banned foods.

I put these lines into my master_postnit section:

  Hide contents

 

local inedibles = {
    "spoiled_food",
    "petals",
    "foliage",
    "lightbulb",
    "ice",
    "seeds",
    "foliage"
    }

    local old_CanEat = inst.components.eater.CanEat
    inst.components.eater.CanEat = function(self, food_inst)
        for i, v in ipairs(inedibles) do
            if food_inst.prefab == v then
                return false
            end
        end
        return old_CanEat(self, food_inst)
    end

 

What do I do wrong?

Thanks in advance for the help!

Sorry for the late and useless answer: I don't know. It looks correct, but since I can't see the whole code, I can't be sure. The code looks right.  Perhaps you have to move the inedibles-list outside the master_postinit, so it doesn't get cleared when the function ends?

Edited by Ultroman
Link to comment
Share on other sites

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
 Share

×
  • Create New...