DenshiDragon Posted December 18, 2016 Share Posted December 18, 2016 I am really bad at coding, this is 2 days of effort right now. I have gotten it so my character can eat gold nuggets and has an upgrade system like wx87. The problem is it wont let me use the gold nuggets to upgrade. There is no crash when i eat the nuggets but there is no upgrade either. do i need to use a different line besides if food and food.components.edible and food.components.edible.foodtype == "goldnugget" then because its not normally a food item. i have no idea and am probably just being a really big idiot. Link to comment https://forums.kleientertainment.com/forums/topic/72620-here-we-go-with-eating-stuff-again/ Share on other sites More sharing options...
MigratoryCoconuts Posted December 19, 2016 Share Posted December 19, 2016 it can be useful to put a print line inside if statements you're not sure are triggering! this will let you know for sure if the code inside ever executes. that being said, it seems that your issue is that gold nuggets dont have foodtype "goldnugget", they're "ELEMENTAL" instead (i believe). rather than ... and food.components.edible.foodtype == "goldnugget" try simply ... and food.prefab == "goldnugget" Link to comment https://forums.kleientertainment.com/forums/topic/72620-here-we-go-with-eating-stuff-again/#findComment-850416 Share on other sites More sharing options...
DenshiDragon Posted December 19, 2016 Author Share Posted December 19, 2016 no, sadly that didn't work. same result, eaten but no upgrade. Link to comment https://forums.kleientertainment.com/forums/topic/72620-here-we-go-with-eating-stuff-again/#findComment-850436 Share on other sites More sharing options...
DenshiDragon Posted December 19, 2016 Author Share Posted December 19, 2016 okay, figured it out. i was just being a super big idiot. I was jumping though some super big hoops to make gold edible when all i had to do was make it so my character could eat FOODTYPE.ELEMENTAL. i didnt even know that was a food type. thanks for the help. Link to comment https://forums.kleientertainment.com/forums/topic/72620-here-we-go-with-eating-stuff-again/#findComment-850444 Share on other sites More sharing options...
DenshiDragon Posted December 19, 2016 Author Share Posted December 19, 2016 now I just need to figure out how to make things not edible Link to comment https://forums.kleientertainment.com/forums/topic/72620-here-we-go-with-eating-stuff-again/#findComment-850479 Share on other sites More sharing options...
DenshiDragon Posted December 19, 2016 Author Share Posted December 19, 2016 got it, kinda sorta Link to comment https://forums.kleientertainment.com/forums/topic/72620-here-we-go-with-eating-stuff-again/#findComment-850487 Share on other sites More sharing options...
DenshiDragon Posted December 19, 2016 Author Share Posted December 19, 2016 (edited) okay, final thing and then i will never dare bother you again. so i made it so my character can enjoy the elemental food group. super tastey gems and all that. i dont want him to eat the rocks, flint, moon rocks, thulecite, or the nitre. i already have it so he wont eat them but i want the action for when i right click them to be the examine text and not the eat text. how do i do? i would normaly just throw things at the wall and see what sticks but i dont even know where to start with this. Edited December 19, 2016 by DenshiDragon Link to comment https://forums.kleientertainment.com/forums/topic/72620-here-we-go-with-eating-stuff-again/#findComment-850655 Share on other sites More sharing options...
MigratoryCoconuts Posted December 19, 2016 Share Posted December 19, 2016 hi, glad you worked that all out! unfortunately i do all my coding in single player ds, where this problem doesnt exist...... that being said, it looks like your problem is that the EntityScript's CollectActions method has a pretty naive way of checking whether something is edible: -- componentactions.lua, line 871, inside a fn that starts at line 856 for k, v in pairs(FOODTYPE) do if inst:HasTag("edible_"..v) and doer:HasTag(v.."_eater") then table.insert(actions, ACTIONS.EAT) return end end you are probably going to want to add an extra conditional along the lines of ... and doer.components.eater and doer.components.eater:CanEat(inst) It looks like you can do this with the global AddComponentAction function (defined in the same file at line 1038), however i dont know how this works with overwriting existing component actions! you'll have to experiment with that yourself sorry Link to comment https://forums.kleientertainment.com/forums/topic/72620-here-we-go-with-eating-stuff-again/#findComment-850710 Share on other sites More sharing options...
DenshiDragon Posted December 19, 2016 Author Share Posted December 19, 2016 (edited) that's fine. with the info you gave me, its at least a place to start so i shall see where this leads. i should probably say how i am making things edible. so in the local master_postinit = function(inst) i put in inst.components.eater:SetDiet ({FOODGROUP.OMNI, FOODTYPE.ELEMENTAL}, {FOODGROUP.OMNI, FOODTYPE.ELEMENTAL}) local self = inst.components.eater local old = self.Eat function self:Eat(food, force) if food and food.components.edible and food.components.edible.foodtype == FOODTYPE.SEEDS or food and food.components.edible and food.components.edible.foodtype == FOODTYPE.VEGGIE or food and food.components.edible and food.components.edible.foodtype == FOODTYPE.Meat then return old(self, food, force) end this part lets me eat all the normal stuff exept maybe the deerclops's eye and stuff like that, havent tested yet. it works so im happy with it. after it i used the "if" "or" to specify the gold nuggets and gems so i can use them for stuff. my code is made of spaghetti so if you see something that just makes you wanna facepalm just let me know. Edited December 19, 2016 by DenshiDragon Link to comment https://forums.kleientertainment.com/forums/topic/72620-here-we-go-with-eating-stuff-again/#findComment-850711 Share on other sites More sharing options...
MigratoryCoconuts Posted December 20, 2016 Share Posted December 20, 2016 unfortunately, have you looked at lines 123-125 in components/eater.lua? -- This used to be CanEat. The reason for two checks is to that special diet characters (e.g. -- wigfrid) can TRY to eat all foods (they get the actions for it) but upon actually put it in -- their mouth, they bail and "spit it out" so to speak. they've intentionally structured the code such that food tags are the only thing listened to when testing the validity of an EAT action. tbh i dont see the point in your new Eat method? it doesnt seem to change the old one at all? an easier way to do things based on what is eaten is using the eater component's oneatfn method. tbh, if i were to do what you were doing id use AddComponentPostInit on the eater component and fix their TestFood function so that it calls some prefab-defined caneatfn - function Eater:TestFood(food, testvalues) if food ~= nil and food.components.edible ~= nil then for i, v in ipairs(testvalues) do if type(v) == "table" then for i2, v2 in ipairs(v.types) do if food:HasTag("edible_"..v2) then -- return not self.caneatfn or self.caneatfn(self.inst, food) return true end end elseif food:HasTag("edible_"..v) then -- return not self.caneatfn or self.caneatfn(self.inst, food) return true end end end end my proposed changes are commented out above - as well as changing the eater ComponentAction as outlined in my earlier comment. does any of that make sense to you? i sure hope so!!! Link to comment https://forums.kleientertainment.com/forums/topic/72620-here-we-go-with-eating-stuff-again/#findComment-850873 Share on other sites More sharing options...
DenshiDragon Posted December 20, 2016 Author Share Posted December 20, 2016 (edited) im trying, im sorry. on to attempt #3 of trying to find a way to eat gold that will be better suited for what i need. the more i attempt this, the better i get... maybe. Edited December 20, 2016 by DenshiDragon Link to comment https://forums.kleientertainment.com/forums/topic/72620-here-we-go-with-eating-stuff-again/#findComment-851094 Share on other sites More sharing options...
MigratoryCoconuts Posted December 27, 2016 Share Posted December 27, 2016 hows it going? i really hope i was helpful! any luck so far? Link to comment https://forums.kleientertainment.com/forums/topic/72620-here-we-go-with-eating-stuff-again/#findComment-853319 Share on other sites More sharing options...
DenshiDragon Posted January 2, 2017 Author Share Posted January 2, 2017 still working on it, but sickness is hitting me super hard. so its going super slow. your advice was helpful though, thank you. Link to comment https://forums.kleientertainment.com/forums/topic/72620-here-we-go-with-eating-stuff-again/#findComment-854783 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