Jump to content

Recommended Posts

Hello everyone I am trying to make woodie not be able to eat any food with monter meat in it, however it does not seem to be working, I am not sure if the code is deprecated or something, I am using Ultroman's tutorial for woodie with restriction to eating certain food types or tagged, I will post both codes, mine and ultroman's tutorial reference to see what is wrong.

if GLOBAL.TheNet:GetIsServer() then 
AddPrefabPostInit("woodie", function(inst)
local oldCanEat = inst.components.eater.CanEat
function inst.components.eater:CanEat(inst)
	-- Check for certain tags. This example makes all foods with the "mushroom" tag inedible.
	if inst:HasTag("monstermeat") then
		return false
	end
	
	if oldCanEat ~= nil then
		return oldCanEat(inst)
	end
	return true
end
end)
local oldCanEat = inst.components.eater.CanEat
function inst.components.eater:CanEat(inst)
	-- Check for certain tags. This example makes all foods with the "mushroom" tag inedible.
	if inst:HasTag("mushroom") then
		return false
	end
	
	-- Check for certain foodtypes. This example makes all VEGGIES inedible.
	if inst.components.edible then
		if inst.components.edible.foodtype == "VEGGIES" then
			return false
		end
	end
	
	if oldCanEat ~= nil then
		return oldCanEat(inst)
	end
	return true
end

 

If I get the food restriction to work, I will set up more conditionals such as it being only applied if woodie is groggy, so that he cannot transform by eating monster meat or idols.

if inst.components.grogginess.isgroggy == true then 

Here is the mod main in case you can find any issues with it, I highly doubt so, just in case.

modmain.lua

I believe I may be an idiot. Try this.

if GLOBAL.TheNet:GetIsServer() then 
AddPrefabPostInit("woodie", function(inst)
local oldCanEat = inst.components.eater.CanEat
function inst.components.eater:CanEat(inst)
	-- Check for certain tags. This example makes all foods with the "mushroom" tag inedible.
	if inst:HasTag("monstermeat") then
		return false
	end
	
	if oldCanEat ~= nil then
		return oldCanEat(self, inst)
	end
	return true
end
end)

 

image.thumb.png.02d4e56565ce8517e9484eecc70bca3d.png

I tried running your code my woodie mod's main, nothing happened so then I decided to put it in a seperate blank mod main  and I just keep on getting this error.

local AllRecipes = GLOBAL.AllRecipes
local RECIPETABS = GLOBAL.RECIPETABS
local STRINGS = GLOBAL.STRINGS
local TECH = GLOBAL.TECH


TUNING = GLOBAL.TUNING
GetPlayer = GLOBAL.GetPlayer


if GLOBAL.TheNet:GetIsServer() then 
AddPrefabPostInit("woodie", function(inst)
local oldCanEat = inst.components.eater.CanEat
function inst.components.eater:CanEat(inst)
	-- Check for certain tags. This example makes all foods with the "mushroom" tag inedible.
	if inst:HasTag("monstermeat") then
		return false
	end
	
	if oldCanEat ~= nil then
		return oldCanEat(self, inst)
	end
	return true
end
end
end)

I added the appropriate end's to see if it eliminated the <oef> but it keeps on doing it so I am not sure what to do else.

Your indentation is screwing with you. I think you pasted it in after your last "end".

Try this:

local AllRecipes = GLOBAL.AllRecipes
local RECIPETABS = GLOBAL.RECIPETABS
local STRINGS = GLOBAL.STRINGS
local TECH = GLOBAL.TECH


TUNING = GLOBAL.TUNING
GetPlayer = GLOBAL.GetPlayer


if GLOBAL.TheNet:GetIsServer() then 
	AddPrefabPostInit("woodie", function(inst)
		local oldCanEat = inst.components.eater.CanEat
		function inst.components.eater:CanEat(inst)
			-- Check for certain tags. This example makes all foods with the "mushroom" tag inedible.
			if inst:HasTag("monstermeat") then
				return false
			end
			
			if oldCanEat ~= nil then
				return oldCanEat(self, inst)
			end
			return true
		end
	end)
end

 

And get yourself Notepad++ and set the "Language" to Lua. Then you can easily see which "end" ends what.

image.png.e7742e98cda0a13a507991f73848f631.png

image.thumb.png.341374de9d80c33fae689fe39f1a7e63.png

I already have note pad ++ , I do not understand why it is not working still.... Have you gone in game to see if it works? I am clueless about trying to call functions from components or retrieving them, that is what your code is trying to do I think by using functions in the Eater component.

image.thumb.png.da75b89583d38a9e453e0d36dc7fa151.png

also used  the code just provided

image.thumb.png.cb6b7d96c244436af0897f6d9b123463.png

Edited by ColombianCam
I goofed

It is not, please refresh the page, I attached another image, sorry, I took another one to check the ending's of what my note pad++ showed.

Ok the code no longers crash but woodie keeps on eating monster meat and idols

Edited by ColombianCam

That code should work. Are you sure you're editing the file that your game is using, and not another copy of it?

If it doesn't work, try this. I have a sneaking suspicion that I messed up something else in that post.

local AllRecipes = GLOBAL.AllRecipes
local RECIPETABS = GLOBAL.RECIPETABS
local STRINGS = GLOBAL.STRINGS
local TECH = GLOBAL.TECH


TUNING = GLOBAL.TUNING
GetPlayer = GLOBAL.GetPlayer


if GLOBAL.TheNet:GetIsServer() then 
	AddPrefabPostInit("woodie", function(inst)
		local oldCanEat = inst.components.eater.CanEat
		inst.components.eater.CanEat = function(self, inst)
			-- Check for certain tags. This example makes all foods with the "mushroom" tag inedible.
			if inst:HasTag("monstermeat") then
				return false
			end
			
			if oldCanEat ~= nil then
				return oldCanEat(self, inst)
			end
			return true
		end
	end)
end

 

Yes I am sure, I even made another mod folder dedicated to this post in hopes of making it work. There's the mod main and modinfo inside the folder.

What my modmain looks like:

local AllRecipes = GLOBAL.AllRecipes
local RECIPETABS = GLOBAL.RECIPETABS
local STRINGS = GLOBAL.STRINGS
local TECH = GLOBAL.TECH


TUNING = GLOBAL.TUNING
GetPlayer = GLOBAL.GetPlayer


if GLOBAL.TheNet:GetIsServer() then 
	AddPrefabPostInit("woodie", function(inst)
		local oldCanEat = inst.components.eater.CanEat
		function inst.components.eater:CanEat(inst)
			-- Check for certain tags. This example makes all foods with the "mushroom" tag inedible.
			if inst:HasTag("monstermeat") then
				return false
			end
			
			if oldCanEat ~= nil then
				return oldCanEat(self, inst)
			end
			return true
		end
	end)
end

What my modinfo looks like

name = "Wereformhunger test"
description = "The wereforms have a lot of pontential, so I buffed them. Normal woodie still has the same perks before the refresh, made by Klei."
author = "Gothy"
version = "5.3"


forumthread = ""

api_version = 10

priority = -8000

server_filter_tags = {"Woodie mod", "wereform buffed"}

dst_compatible = true

all_clients_require_mod = true
client_only_mod = false
icon_atlas = ""
icon = ""

the mods I have enabled:

enabledmods.thumb.PNG.971fe24e9e98a9d7dead900e8296c175.PNG

then here I have woodie eating monster meat.

screenshot.thumb.png.d8728a80a2f457208cecb333d41fc4ce.png

 

my folder:

modfiles.thumb.PNG.e7106dbe0a2def5f21f69d27b6dd6227.PNG

Edited by ColombianCam

Ah. Reading up on the latest game source code, they've changed the way the eater-component works. It is now PrefersToEat which you're supposed to extend.

if GLOBAL.TheNet:GetIsServer() then 
	AddPrefabPostInit("woodie", function(inst)
		local oldPrefersToEat = inst.components.eater.PrefersToEat
		inst.components.eater.PrefersToEat = function(self, food)
			-- Check for certain tags. This example makes all foods with the "monstermeat" tag inedible.
			if food:HasTag("monstermeat") then
				return false
			end
			
			if oldPrefersToEat ~= nil then
				return oldPrefersToEat(self, food)
			end
			return true
		end
	end)
end

 

Edited by Ultroman

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