icantevenname Posted October 16, 2018 Share Posted October 16, 2018 Fruits are delicious and are a manifestation of Mother Nature's love. Vegetables are her hate. How do I get my character to only eat fruits? Link to comment Share on other sites More sharing options...
AkaiNight Posted November 2, 2018 Share Posted November 2, 2018 Well i don't exactly how to do but you can try this. To your characters .lua local function oneat(inst, food) if food and food.components.edible and food.prefab = not "fruit name" or "other fruid" or "other"... then local hungerboost = 0 local sanityboost = 0 local healtboost = 0 end end with this you still able to eat other things but they do not effect anything. I'm not sure but you can try this for not able to eat local function oneat(inst, food) if food and food.components.edible and food.prefab = not "fruit name" or "other fruid" or "other"... then return end end I'm not sure about this but give a try and also add this to master postinit inst.components.eater:SetOnEatFn(oneat). Hope that will help Link to comment Share on other sites More sharing options...
Ultroman Posted November 3, 2018 Share Posted November 3, 2018 You can take a look at that vanilla character that can only eat meat. There's gotta be some code doing that. Link to comment Share on other sites More sharing options...
Lumina Posted November 3, 2018 Share Posted November 3, 2018 The thing is that the character eating only meat will do this based on the foodtype of the food, as far as i know. But there isn't a foodtype fruit, there is only the veggie one. So it will require a bit different coding, like having a list of "fruit" food somewhere (probably not a good idea to change the foodtype of the food) Link to comment Share on other sites More sharing options...
BakaSchwarz Posted November 4, 2018 Share Posted November 4, 2018 Like Lumina said, this is normally handled with the foodtype. My idea to solve this would be to overwrite the PrefersToEat function in the eater component. Include a list of acceptable foods inside your mod and check for it in there. Link to comment Share on other sites More sharing options...
icantevenname Posted November 6, 2018 Author Share Posted November 6, 2018 So make a table with all the fruits and have the foodtype thing recognize it? I should've mentioned this earlier, but this is for a transformation. What is the normal diet's coding? Link to comment Share on other sites More sharing options...
BakaSchwarz Posted November 7, 2018 Share Posted November 7, 2018 (edited) Like AkaiNight already said: If you just want to make your character do different stuff (like a transformation) based on the food item, then you would be better of to supply an oneatfn. For this you put the following in your master_postinit: inst.components.eater:SetOnEatFn(OnEat) where OnEat is something like the following function: local function OnEat(inst, food) if not food:HasTag("spoiled") then if food.prefab == "seeds" then inst.components.sanity:DoDelta(2) elseif food.prefab == "dragonfruit_seeds" then inst.components.sanity:DoDelta(-5) inst.components.temperature:DoDelta(20) elseif food.prefab == "carrot_seeds" then inst.components.sanity:DoDelta(6) inst.components.health:DoDelta(1) elseif food.prefab == "durian_seeds" then inst.components.sanity:DoDelta(-9999) inst.components.hunger:DoDelta(9999) elseif food.prefab == "eggplant_seeds" then inst.components.hunger:DoDelta(10) elseif food.prefab == "pomegranate_seeds" then inst.components.health:DoDelta(15) elseif food.prefab == "pumpkin_seeds" then inst.components.sanity:DoDelta(10) elseif food.prefab == "watermelon_seeds" then inst.components.sanity:DoDelta(-5) inst.components.temperature:DoDelta(-5) elseif food.prefab == "sweet_potato_seeds" then inst.components.sanity:DoDelta(5) inst.components.hunger:DoDelta(1) elseif food.prefab == "corn_seeds" then inst.components.sanity:DoDelta(1) end end end This OnEat function is from my character Avia. She can only eat seeds, but each different seed gives her extra benefits. You could use this function to do the transformation, deal punishment for eating non fruit items, etc. This function gets called AFTER you eat the food item. Also i am not really sure what you mean with "normal diet's coding"? Edited November 7, 2018 by BakaSchwarz Link to comment Share on other sites More sharing options...
icantevenname Posted November 8, 2018 Author Share Posted November 8, 2018 Wigfrid's diet is coded like this: inst.components.eater:SetDiet({ FOODGROUP.OMNI }, { FOODTYPE.MEAT, FOODTYPE.GOODIES }) So what would be the normal diet's code? Link to comment Share on other sites More sharing options...
BakaSchwarz Posted November 9, 2018 Share Posted November 9, 2018 inst.components.eater:SetDiet({ FOODGROUP.OMNI }, nil) because the SetDiet function is defined as follows: function Eater:SetDiet(caneat, preferseating) self.caneat = caneat self.preferseating = preferseating or caneat end You can ignore the preferseating argument and just set it to nil, because it will then assume caneat is also what the character prefers to eat. With this setup your character will be able to eat the "default" stuff (as defined in constants.lua): FOODGROUP = { OMNI = { name = "OMNI", types = { FOODTYPE.MEAT, FOODTYPE.VEGGIE, FOODTYPE.INSECT, FOODTYPE.SEEDS, FOODTYPE.GENERIC, FOODTYPE.GOODIES, }, } } Link to comment Share on other sites More sharing options...
icantevenname Posted December 2, 2018 Author Share Posted December 2, 2018 I found this code that forbids this cactus character from eating other cacti. local forbidden = { cactus_meat = true, cactus_meat_cooked = true, cactus_flower = true, guacamole = true, flowersalad = true, } local _PrefersToEat = inst.components.eater.PrefersToEat inst.components.eater.PrefersToEat = function(self, food) return _PrefersToEat(self, food) and not forbidden[food.prefab] end Maybe it's possible to turn this table into a "eat only" table? Link to comment Share on other sites More sharing options...
Parusoid Posted December 3, 2018 Share Posted December 3, 2018 (edited) 22 hours ago, icantevenname said: I found this code that forbids this cactus character from eating other cacti. local forbidden = { cactus_meat = true, cactus_meat_cooked = true, cactus_flower = true, guacamole = true, flowersalad = true, } local _PrefersToEat = inst.components.eater.PrefersToEat inst.components.eater.PrefersToEat = function(self, food) return _PrefersToEat(self, food) and not forbidden[food.prefab] end Maybe it's possible to turn this table into a "eat only" table? change forbidden to preferred and put all the prefabs you want to be able to eat. If its truit, i looked in the files and there like only 7 fruits in the whole game, pretty restrictive (watermelon, durian, berries_juicy, berries, pomegranate, dragonfruit, cave_banana). Then change "return _PrefersToEat(self, food) and not forbidden[food.prefab]" to "return _PrefersToEat(self, food) and preferred[food.prefab]" Edited December 3, 2018 by Parusoid Link to comment Share on other sites More sharing options...
icantevenname Posted December 3, 2018 Author Share Posted December 3, 2018 2 hours ago, Parusoid said: change forbidden to preferred and put all the prefabs you want to be able to eat. If its truit, i looked in the files and there like only 7 fruits in the whole game, pretty restrictive (watermelon, durian, berries_juicy, berries, pomegranate, dragonfruit, cave_banana). Then change "return _PrefersToEat(self, food) and not forbidden[food.prefab]" to "return _PrefersToEat(self, food) and preferred[food.prefab]" That works fine, but when the character transforms back, the fruit diet persists. Link to comment Share on other sites More sharing options...
Parusoid Posted December 3, 2018 Share Posted December 3, 2018 (edited) 7 hours ago, icantevenname said: That works fine, but when the character transforms back, the fruit diet persists. Then you need to put that code in the part of code that represents the transformation and put the code that makes the diet back to normal in the part of code that represents the other form Spoiler local _PrefersToEat = inst.components.eater.PrefersToEat inst.components.eater.PrefersToEat = function(self, food) return _PrefersToEat(self, food) end Edited December 3, 2018 by Parusoid Link to comment Share on other sites More sharing options...
icantevenname Posted December 4, 2018 Author Share Posted December 4, 2018 15 hours ago, Parusoid said: Then you need to put that code in the part of code that represents the transformation and put the code that makes the diet back to normal in the part of code that represents the other form Hide contents local _PrefersToEat = inst.components.eater.PrefersToEat inst.components.eater.PrefersToEat = function(self, food) return _PrefersToEat(self, food) end That doesn't seem to be working. Should I post the LUA? Link to comment Share on other sites More sharing options...
Wolf_EX Posted December 4, 2018 Share Posted December 4, 2018 I'm not sure if what I did would apply to you but I made an item that changes a characters diet when you equip and reverts it on unequip. The code I used to change it is --onequip owner.eattags = owner.components.eater.caneat owner.preferseattags = owner.components.eater.preferseating owner.components.eater:SetDiet({})--stick the new diet in here and on the unequip i used --onunequip if owner.eattags then owner.components.eater:SetDiet(owner.eattags, owner.preferseattags) end Link to comment Share on other sites More sharing options...
icantevenname Posted December 4, 2018 Author Share Posted December 4, 2018 (edited) 1 hour ago, Wolf_EX said: I'm not sure if what I did would apply to you but I made an item that changes a characters diet when you equip and reverts it on unequip. The code I used to change it is --onequip owner.eattags = owner.components.eater.caneat owner.preferseattags = owner.components.eater.preferseating owner.components.eater:SetDiet({})--stick the new diet in here and on the unequip i used --onunequip if owner.eattags then owner.components.eater:SetDiet(owner.eattags, owner.preferseattags) end It keeps crashing because "owner" is not declared? I think it's because "owner" is meant for equipable items. But I bet we can turn this into something usable. Edited December 4, 2018 by icantevenname Link to comment Share on other sites More sharing options...
Wolf_EX Posted December 4, 2018 Share Posted December 4, 2018 (edited) 1 hour ago, icantevenname said: It keeps crashing because "owner" is not declared? I think it's because "owner" is meant for equipable items. But I bet we can turn this into something usable. I was just using my code as an example on how it was done, you would probably use "inst" instead. maybe something like local eattags = inst.components.eater.caneat local preferseattags = inst.components.eater.preferseating inst.components.eater:SetDiet({"pomegranate", "dragonfruit", "cave_banana"})--im not sure if this is how you set it's diet. --and to undo if eattags then inst.components.eater:SetDiet(eattags, preferseattags) end my gpu is dying atm so I can't really test this. You probably don't even need to do it this way if your character normally eats regular food. Could probably just set the diet to FOODTYPE.GENERIC or something. Edited December 4, 2018 by Wolf_EX Link to comment Share on other sites More sharing options...
icantevenname Posted December 5, 2018 Author Share Posted December 5, 2018 16 hours ago, Wolf_EX said: I was just using my code as an example on how it was done, you would probably use "inst" instead. maybe something like local eattags = inst.components.eater.caneat local preferseattags = inst.components.eater.preferseating inst.components.eater:SetDiet({"pomegranate", "dragonfruit", "cave_banana"})--im not sure if this is how you set it's diet. --and to undo if eattags then inst.components.eater:SetDiet(eattags, preferseattags) end my gpu is dying atm so I can't really test this. You probably don't even need to do it this way if your character normally eats regular food. Could probably just set the diet to FOODTYPE.GENERIC or something. It seems to ignore all foods... Link to comment Share on other sites More sharing options...
Wolf_EX Posted December 5, 2018 Share Posted December 5, 2018 (edited) I found an answer here You have to make a custom food group. In the modmain add local FOODTYPE = GLOBAL.FOODTYPE local FOODGROUP = GLOBAL.FOODGROUP FOODTYPE.FRUITS = "FRUIT" FOODGROUP.FRUIT = {} FOODGROUP.FRUIT.name = "FRUIT" FOODGROUP.FRUIT.types = { FOODTYPE.FRUITS, } local function MakeFruit(inst) inst:AddTag("edible_"..FOODTYPE.FRUITS) end --Do this for each food that you want in the fruit group AddPrefabPostInit("dragonfruit", MakeFruit) AddPrefabPostInit("pomegranate", MakeFruit) and the code to change the caneat is inst.components.eater:SetDiet({FOODGROUP.FRUIT}) and assuming your character has a regular diet when you transform back, just use FOODGROUP.OMNI(or whatever type of diet it has) Edited December 5, 2018 by Wolf_EX Link to comment Share on other sites More sharing options...
icantevenname Posted December 5, 2018 Author Share Posted December 5, 2018 45 minutes ago, Wolf_EX said: I found an answer here You have to make a custom food group. In the modmain add local FOODTYPE = GLOBAL.FOODTYPE local FOODGROUP = GLOBAL.FOODGROUP FOODTYPE.FRUITS = "FRUIT" FOODGROUP.FRUIT = {} FOODGROUP.FRUIT.name = "FRUIT" FOODGROUP.FRUIT.types = { FOODTYPE.FRUITS, } local function MakeFruit(inst) inst:AddTag("edible_"..FOODTYPE.FRUITS) end --Do this for each food that you want in the fruit group AddPrefabPostInit("dragonfruit", MakeFruit) AddPrefabPostInit("pomegranate", MakeFruit) and the code to change the caneat is inst.components.eater:SetDiet({FOODGROUP.FRUIT}) and assuming your character has a regular diet when you transform back, just use FOODGROUP.OMNI(or whatever type of diet it has) FINALLY. Thank you! It's weird that fruit ain't it's own food group from the get-go... 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