Jump to content

Recommended Posts

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.

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"

 

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.

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 by DenshiDragon

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

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 by DenshiDragon

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

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 by DenshiDragon

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