Spotteh Posted January 2, 2015 Share Posted January 2, 2015 Because this egghead: Is firmly convinced that she cant! Jokes aside, I am doing some final play testing for a stable launch of a playable Chocobo mod I have been working on since Christmas. The short and long of it is that Wark the chocobo is mostly an Herbivore, which means that she has the: inst.components.eater.foodprefs = { FOODTYPE.VEGGIE, FOODTYPE.INSECT, FOODTYPE.SEEDS, FOODTYPE.GENERIC, } ... line defining what she can and cannot eat. However, it is a lie to say that chocobo's are entirely herbivorous, as in some of the "Final Fantasy Fables" games they are capable of eating fish. Compiling this with the fact that eggs are generally a healthful food for birds (I mean, they do develop in those things) I am faced with the conundrum that Fish, Fish Tacos, Unagi, Eel, and both eggs are FOODTYPE.MEAT. So my question is this: Is it possible to make exceptions to the foodprefs code so that the character can eat certain meat items like the above listed? Outside a few graphical touches that I want to add before the big update, I think this is the last thing hindering me from releasing Wark. This, and if the code for moulting at the start of summer needs tweaking (Rezecib is entitled to my first born, btw)! Thanks a bunch! Link to comment Share on other sites More sharing options...
Spotteh Posted January 2, 2015 Author Share Posted January 2, 2015 Oh, I just now figured out that this is supposed to go into kleilist, my bad y'all! Link to comment Share on other sites More sharing options...
Mobbstar Posted January 2, 2015 Share Posted January 2, 2015 Well, you can add a caneattest function, but that only tests after checking the foodtype. You'd have to allow her meat in general, but if the foodtype is "meat" and the item prefab is not any of the named, say no. That'd look somewhat like this: local function FoodTest(inst, food) if food.foodtype ~= "MEAT" or food.prefab == "egg" then --don't forget the rest! (...or food.prefab == "" or....) return true endend local function fn()[...] inst.components.eater.foodprefs = { "VEGGIE", "INSECT", "SEEDS", "MEAT", "GENERIC" } inst.components.eater.caneatfn = FoodTest[...] Link to comment Share on other sites More sharing options...
Kzisor Posted January 2, 2015 Share Posted January 2, 2015 @Spotteh, I personally don't like long if statements. I'd rather store my values in memory and save myself the headache of trying to figure out exactly what's going on. Example:local function FoodTest(inst, food)for k,_ in pairs(inst._food)-- You only need the key for this to function, because there are no values with strings.if food.foodtype == "MEAT" and k == food.prefab thenreturn trueendendreturn falseend local function fn(inst) inst._food = {"Egg","Fish","etc..",} if inst.components.eater theninst.components.eater.caneatfn = FoodTestend return instend Link to comment Share on other sites More sharing options...
Mobbstar Posted January 2, 2015 Share Posted January 2, 2015 I personally don't like long if statements. I'd rather store my values in memory and save myself the headache of trying to figure out exactly what's going on. Example:local function FoodTest(inst, food)for k,_ in pairs(inst._food)-- You only need the key for this to function, because there are no values with strings.if food.foodtype == "MEAT" and k == food.prefab thenreturn trueendendreturn falseend local function fn(inst) inst._food = {"Egg","Fish","etc..",} if inst.components.eater theninst.components.eater.caneatfn = FoodTestend return instend You kinda messed up, caneat tests after checking the foodprefs. You foodtest limits to the foods in the table, as those all are meat type anyways and are themselves. I can see where you are going with this though, let me try to adapt it: local function FoodTest(inst, food) if food.foodtype == "MEAT" then for _,v in pairs(inst.meatfood) --key is the array number if v == food.prefab then return true --is accepted meat end end return false --is generic meat end return true --is not meatend local function fn(inst) [...] inst.components.eater.foodprefs = {"VEGGIE","INSECT","SEEDS","MEAT","GENERIC"} --meat foodpref is handled special inst.meatfood = { --allowed meat foods, by code name "egg", "fish", "etc..", } inst.components.eater.caneatfn = FoodTest return instend I really like my custom formating, it's really simple and plain but yet less confusing. I assume you made experiences in other languages before? Link to comment Share on other sites More sharing options...
Kzisor Posted January 2, 2015 Share Posted January 2, 2015 @Mobbstar, my code was theoretical showing the benefit of using a loop instead of long if statements. Not many people think about using a loop in that circumstance. I've seen several of these types of posts in the past few days so getting this knowledge out there will hopefully help people. Link to comment Share on other sites More sharing options...
Spotteh Posted January 2, 2015 Author Share Posted January 2, 2015 Well, you can add a caneattest function, but that only tests after checking the foodtype. You'd have to allow her meat in general, but if the foodtype is "meat" and the item prefab is not any of the named, say no. That'd look somewhat like this: local function FoodTest(inst, food) if food.foodtype ~= "MEAT" or food.prefab == "egg" then --don't forget the rest! (...or food.prefab == "" or....) return true endend local function fn()[...] inst.components.eater.foodprefs = { "VEGGIE", "INSECT", "SEEDS", "MEAT", "GENERIC" } inst.components.eater.caneatfn = FoodTest[...] I literally just realized that this is the base Don't Starve forum and not the DST forum. Holy cows on politicians I am bad at this. Ok, So even so I went and added the local function Foodtest to Wark.lua in prefabs and added "inst.components.eater.caneatfn = foodtest" to "local masterpostinit" because that is where I had: inst.components.eater.foodprefs = { FOODTYPE.VEGGIE, FOODTYPE. MEAT, FOODTYPE.INSECT, FOODTYPE.SEEDS, FOODTYPE.GENERIC, FOODTYPE.WOOD, } Anyways, it did the first part of what you said, were it defined that Wark can eat meat, but it gave her the ability to eat all meat without checking if it was an egg or not. Link to comment Share on other sites More sharing options...
Mobbstar Posted January 2, 2015 Share Posted January 2, 2015 I literally just realized that this is the base Don't Starve forum and not the DST forum. Holy cows on politicians I am bad at this. Ok, So even so I went and added the local function Foodtest to Wark.lua in prefabs and added "inst.components.eater.caneatfn = foodtest" to "local masterpostinit" because that is where I had: inst.components.eater.foodprefs = { FOODTYPE.VEGGIE, FOODTYPE. MEAT, FOODTYPE.INSECT, FOODTYPE.SEEDS, FOODTYPE.GENERIC, FOODTYPE.WOOD, } Anyways, it did the first part of what you said, were it defined that Wark can eat meat, but it gave her the ability to eat all meat without checking if it was an egg or not. I made an error: it should be food.components.edible.foodtype. food.prefab is fine. EDIT: Sincere apologies Link to comment Share on other sites More sharing options...
Kzisor Posted January 2, 2015 Share Posted January 2, 2015 @Spotteh,DST handles eating completely different than DS. You will need to replicate the old DS way of eating a little bit. EaterPostInit = function(self) -- Stored for later usage. self._CanEat = self.CanEat -- Create the variable to store the function. self.caneatfn = nil function self:CanEat(inst) local edible = self._CanEat(inst) if edible then if self.caneatfn then return self.caneatfn(self.inst, inst) --Can be eaten. end end return edible --Unable to be eaten/does not prevent other characters from not eating. end return selfend AddComponentPostInit("eater", EaterPostInit) This should give you that functionality in DST. Link to comment Share on other sites More sharing options...
Spotteh Posted January 2, 2015 Author Share Posted January 2, 2015 I made an error: it should be food.components.edible.foodtype. food.prefab is fine. EDIT: Sincere apologies So like this? local function FoodTest(inst, food) if food.components.edible.foodtype ~= "MEAT" or food.prefab == "egg" then --don't forget the rest! (...or food.prefab == "" or....) return true endend local function fn()[...] inst.components.eater.foodprefs = { "VEGGIE", "INSECT", "SEEDS", "MEAT", "GENERIC" } inst.components.eater.caneatfn = FoodTest[...] Link to comment Share on other sites More sharing options...
Spotteh Posted January 2, 2015 Author Share Posted January 2, 2015 @Spotteh,DST handles eating completely different than DS. You will need to replicate the old DS way of eating a little bit. EaterPostInit = function(self) -- Stored for later usage. self._CanEat = self.CanEat -- Create the variable to store the function. self.caneatfn = nil function self:CanEat(inst) local edible = self._CanEat(inst) if edible then if self.caneatfn then return self.caneatfn(self.inst, inst) --Can be eaten. end end return false --Unable to be eaten. end return selfend AddComponentPostInit("eater", EaterPostInit) This should give you that functionality in DST. I'd hate to sound really stupid but that doesn't look like it defines anything specific, so I am guessing I need to plug in the food list into their somewhere? is it the local edible = self._CanEat(inst) So would it be like: "egg" = self._CanEat(inst)"egg_cooked" = self._CanEat(isnt) ? Thanks a lot for your help, by the way. I really didn't think I was asking so much from everyone. Link to comment Share on other sites More sharing options...
Kzisor Posted January 2, 2015 Share Posted January 2, 2015 I'd hate to sound really stupid but that doesn't look like it defines anything specific, so I am guessing I need to plug in the food list into their somewhere? is it the local edible = self._CanEat(inst) So would it be like: "egg" = self._CanEat(inst)"egg_cooked" = self._CanEat(isnt) ? Thanks a lot for your help, by the way. I really didn't think I was asking so much from everyone. By using the same code that Mobbstar gave you and use what I posted and it should work correctly. In Don't Starve Together there is no eater.caneatfn function that is being called. The code I gave basically determines if the food is edible and then calls the caneatfn which Mobbstar provided to determine if your character can actually eat it. In practice though, the return false should be return edible in my code which I will change. Link to comment Share on other sites More sharing options...
Spotteh Posted January 2, 2015 Author Share Posted January 2, 2015 By using the same code that Mobbstar gave you and use what I posted and it should work correctly. In Don't Starve Together there is no eater.caneatfn function that is being called. The code I gave basically determines if the food is edible and then calls the caneatfn which Mobbstar provided to determine if your character can actually eat it. In practice though, the return false should be return edible in my code which I will change. Ok, so I think I understand. I put both mobbstar's and your DST fix in wark.lua in prefab, but the "AddComponentPostInit("eater", EaterPostInit)" is confusing me. Does the whole line go into the master_postinit? I pasted it their but then I get an error saying "AddComponentPostInit" isn't defined, so I am assuming I put it in the wrong place. Link to comment Share on other sites More sharing options...
Kzisor Posted January 2, 2015 Share Posted January 2, 2015 Ok, so I think I understand. I put both mobbstar's and your DST fix in wark.lua in prefab, but the "AddComponentPostInit("eater", EaterPostInit)" is confusing me. Does the whole line go into the master_postinit? I pasted it their but then I get an error saying "AddComponentPostInit" isn't defined, so I am assuming I put it in the wrong place. The code I gave you goes in the modmain.lua file not in your wark.lua file. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.
Please be aware that the content of this thread may be outdated and no longer applicable.