Jump to content

Recommended Posts

Im trying to get my character to eat grass. but i cant seem to work it out. i have followed this guides with no sucsess 

 

If i do solely Pyrobolser  post, and the games doesn't crash, but it also doesn't let me eat grass.

if i add rezecib post, the game crashes telling me there is a "(" in a weird place or something even though i am copy and pasting the code (and moving the words so it works, otherwise it's a straight line mess thing).

From the guide i put there, the code is making a new foodtype, and then adding the non edibles to said group to make them edible, then its either adding the the items (grass and cutgrass) prefabs which does not cause a crash, but i cant seem to get my character to eat it. Or i don't touch the prefabs and add code to my modmain and get a crash. incase the guide is outdated or i'm just doing it wrong, i'm going to say that all i want to do is make cutgrass and the grass tuff (the one you get from using a shovel) to be edible on a  single character.

Thanks for taking the time to read this!

  

 

-- Create foodtype 'Beefalo'
GLOBAL.FOODTYPE.BEEFALO = "BEEFALO"
local beefalo_food = {"grass", "cutgrass", }
local function AddBeefaloFood(inst)
    inst:AddTag("edible_"..GLOBAL.FOODTYPE.BEEFALO)
end
for k,v in pairs(beefalo_food) do
    AddPrefabPostInit(v, AddBeefaloFood)
end

In modmain. right after the whole thing here

local require = GLOBAL.require
local STRINGS = GLOBAL.STRINGS
 local Eater = require "components/eater"
 local Text = require "widgets/text"
 local Image = require "widgets/image"

 

The code that for some reason crashes my game is put in modmain too (right now it isnt in there)

the code is

AddPrefabPostInit ("grass", function (inst)
    inst:AddComponent ("edible")
    inst.components.edible.foodtype = GLOBAL.FOODTYPE.BEEFALO
    inst.components.edible.healthvalue = 20
    inst.components.edible.sanityvalue = 10 
	inst.components.edible.hungervalue = 100
end

Then i copy and paste that to also edit the "cutgrass"

doing this crashes the game.

the code that doesn't crash the game is put into the respective prefabs (which i hear causes mod incompatibility)

		--------------------- Mod edition :	    
		inst:AddComponent("edible")
		inst.components.edible.foodtype = FOODTYPE.HORRIBLE
		inst.components.edible.oneaten = function(inst, eater)
		if eater.prefab == "jeremiah" then
		eater.components.health:DoDelta(50)
		eater.components.hunger:DoDelta(50)
		eater.components.sanity:DoDelta(100)
		end
		end
		--------------------- End of mod edition

The part of this code that says FOODTYPE.HORRIBLE isn't the problem, i can change it to FOODTYPE.BEEFALO and it doesn't change anything (though, i could be wrong)

Edited by Augustusc
I didn't give enough information/ i could have caused confusion
AddPrefabPostInit ("grass", function (inst)
    inst:AddComponent ("edible")
    inst.components.edible.foodtype = GLOBAL.FOODTYPE.BEEFALO
    inst.components.edible.healthvalue = 20
    inst.components.edible.sanityvalue = 10 
	inst.components.edible.hungervalue = 100
end)

You are missing ")' at the end.

I put one in so that it looks like this

AddPrefabPostInit ("grass",) function (inst)
    inst:AddComponent ("edible")
    inst.components.edible.foodtype = GLOBAL.FOODTYPE.BEEFALO
    inst.components.edible.healthvalue = 50
    inst.components.edible.sanityvalue = 50
	inst.components.edible.hungervalue = 100
end

Gives me the same error.

here is the error in detail (or at least how it say in game)

Quote

The following mod(s) have caused a failure: Jeremiah The Herder (TEST)

[string "../mods/Jeremiah the herder/modmain.lua"]:62: unexpected symbol near ')'

I tried removing the "," after "grass" but it gave another error, so it's not that.

You put ) in the wrong place.

 

AddPrefabPostInit ("grass", function (inst)
    inst:AddComponent ("edible")
    inst.components.edible.foodtype = GLOBAL.FOODTYPE.BEEFALO
    inst.components.edible.healthvalue = 20
    inst.components.edible.sanityvalue = 10 
	inst.components.edible.hungervalue = 100
end
) --missing ) here
Edited by SenL

I don't think that's the way to go. It may make grass edible to all.

Here's how I did with my mod (Groot):

char lua:

inst.components.eater:SetDiet({FOODGROUP.GROOT_FOODGROUP})

modmain lua:

GLOBAL.FOODTYPE.GROOTFOOD = "GROOTFOOD"
local groot_food = {"twigs", "log", "boards", "petals", "petals_evil", "pinecone", "cutgrass", "foliage", "cutlichen", "livinglog"}
local function AddGrootFood(inst)
    inst:AddTag("edible_"..GLOBAL.FOODTYPE.GROOTFOOD)
end
for k,v in pairs(groot_food) do
    AddPrefabPostInit(v, AddGrootFood)
end
GLOBAL.FOODGROUP.GROOT_FOODGROUP = {
    name = "GROOT_FOODGROUP"
    ,types = {
        GLOBAL.FOODTYPE.GROOTFOOD,
    }
}

Experts: please feel free to correct me.

Thanks.

It half worked. i now can eat grass.. but i cant eat anything else. Is the problem related to the set diet part? if so... how do i add more than just that the grass. and how do i add the grass tuff to the diet? (i tried putting grass as a thing, but it didn't work)

inst.components.eater:SetDiet({FOODGROUP.BEEFALO, FOODGROUP.OMNI})
GLOBAL.FOODTYPE.BEEFALOFOOD = "BEEFALOFOOD"
local beefalo_food = {"cutgrass", "dug_grass"}
local function AddBeefaloFood(inst)
    inst:AddTag("edible_"..GLOBAL.FOODTYPE.BEEFALOFOOD)
end
for k,v in pairs(beefalo_food) do
    AddPrefabPostInit(v, AddBeefaloFood)
end
GLOBAL.FOODGROUP.BEEFALO = {
    name = "BEEFALO",
    types = { GLOBAL.FOODTYPE.BEEFALOFOOD, }
} 

 

Edited by zUsername

Everything works other than the dug_grass. that one is being so stubborn. I wonder what is wrong with it.

I figured out what is wrong with the grass tuff. looking in the prefab of cutgrass, there is actually code for it being edible, but grass stuff doesn't have it.

I really appreciate everyone helping me out, it seems to be problem after problem after problem. so i'm glad you guys are sticking around to help 

Edited by Augustusc
I figured out something

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