lakhnish Posted August 30, 2019 Share Posted August 30, 2019 I wanted to try to make it so that characters could not eat foods with a certain tag that I could assign to them (let's say "masterfood" as an example, which is all of warly's dishes). What I can do with the eater component is to make it so that characters would only eat foods with the "masterfood" tag to them, thus rejecting all other foods without said tag: Spoiler AddPrefabPostInitAny(function(inst) if inst:HasTag("player") and inst.components.eater ~= nil and not inst:HasTag("masterchef") then inst.components.eater:SetPrefersEatingTag("masterfood") end end) What I could not figure out was how to make it do the opposite; i.e. make it reject foods with the tag "masterfood", but allow all other foods otherwise. My attempt to try and make characters hate a tag while accepting all other foods otherwise via some functions based off of SetPrefersEatingTag & PrefersToEat in the eater component, which was doing what I described in the beginning I think the issue is how I did the HatesToEat function, as I was basing it off what they did for Warly, and I'm not sure how to correct it atm. Characters atm just eat foods normally with this. Any advice would be appreciated on what I'm doing wrong. Spoiler --Attempt at making it so that characters can not eat foods with a hated tag, but otherwise act normally. AddComponentPostInit("eater", function(self) --Based off of Eater:SetPrefersEatingTag(tag), getting the method for easy use later when telling a character they hate a tag function self:SetHatesEatingTag(tag) if self.hateseatingtags == nil then self.hateseatingtags = { tag } else table.insert(self.hateseatingtags, tag) end end --Based off of Eater:PrefersToEat(inst) to make it so that characters will reject a hated tag function self:HatesToEat(inst) if self.hateseatingtags ~=nil then local preferred = true for i,v in ipairs(self.hateseatingtags) do if inst:HasTag(v) then preferred = false break end end if not preferred then return true end end return self:TestFood(inst, self.preferseating) end end) --The process of making the character hate a "masterfood" AddPrefabPostInitAny(function(inst) if inst:HasTag("player") and inst.components.eater ~= nil and not inst:HasTag("masterchef") then inst.components.eater:SetHatesEatingTag("masterfood") end end) As references, this is what SetPrefersEatingTag looks like: Spoiler function Eater:SetPrefersEatingTag(tag) if self.preferseatingtags == nil then self.preferseatingtags = { tag } else table.insert(self.preferseatingtags, tag) end end And What PrefersToEat looks like: Spoiler function Eater:PrefersToEat(inst) if inst.prefab == "winter_food4" and self.inst:HasTag("player") then --V2C: fruitcake hack. see how long this code stays untouched - _- return false elseif self.preferseatingtags ~= nil then --V2C: now it has the warly hack for only eating prepared foods ;-D local preferred = false for i, v in ipairs(self.preferseatingtags) do if inst:HasTag(v) then preferred = true break end end if not preferred then return false end end return self:TestFood(inst, self.preferseating) end Link to comment Share on other sites More sharing options...
Thomas Die Posted August 30, 2019 Share Posted August 30, 2019 do you need it to be that way because i'm sure that you can create the same effect but by having every food have that tag expect the food you don't want them to eat or just put in edible component if food.prefab not (inst your food here) then food:addtag("your food tagg") Link to comment Share on other sites More sharing options...
Ultroman Posted August 30, 2019 Share Posted August 30, 2019 I'm still not sure EXACTLY what you want to accomplish. Can you try to describe the functionality you wish as simply as possible, without referring to any code? Like, "I want specifically my character to not be able to eat a food with a particular tag" or something like that? Link to comment Share on other sites More sharing options...
IronHunter Posted August 30, 2019 Share Posted August 30, 2019 --masterpostinit local _PrefersToEat = inst.components.eater.PrefersToEat inst.components.eater.PrefersToEat = function(self, food,...) return _PrefersToEat(self, food,...) and not food:HasTag("masterfood") end Wouldn't just extending the prefers to eat function work? If you just want to refuse those foods? 1 Link to comment Share on other sites More sharing options...
lakhnish Posted August 30, 2019 Author Share Posted August 30, 2019 8 hours ago, Ultroman said: "I want specifically my character to not be able to eat a food with a particular tag" or something like that? A) I want characters (except warly) to specifically not be able to eat a food with a particular tag (this part is working now) B) These tags would be assigned to the foods when made in the portable crockpot (or crockpot X) (Now need to work on). 1 hour ago, IronHunter said: --masterpostinit local _PrefersToEat = inst.components.eater.PrefersToEat inst.components.eater.PrefersToEat = function(self, food,...) return _PrefersToEat(self, food,...) and not food:HasTag("masterfood") end Wouldn't just extending the prefers to eat function work? If you just want to refuse those foods? Yea, that works too and is much simpler than what the final result was. Thanks! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now