Jump to content

Help needed for eating gears


Recommended Posts

Hello! i am recently new here, and i also am pretty new to lua coding, but so far i'm getting the hang of it.

 

So, i am trying to get my character to eat gears, I've managed to do so from help here, but it's globally. What i think i have to do is put the gears into a new food type so she can eat them and others cant (unless they also have the food type) but i'm having troubles doing that exactly.

I'm pretty sure its something in modmain, most likely the AddPrefabPostInit.

i'll put the files (modinfo.lua, modmain.lua, eve.lua) here somewhere so you can take a look, what am i doing wrong? or am i just going off the trails?

 

Eventually ill do some sort of skill but one thing at a time

Link to comment
Share on other sites

to make nightmarefuel eatable the code looks like this (adjust it for gears):
all in modmain:

GLOBAL.FOODTYPE.SHADOWFOOD = "SHADOWFOOD"
AddPrefabPostInit("nightmarefuel",function(inst)
    if inst.components.edible==nil then    -- only change it, if no one else made it edible before
        inst:AddComponent("edible")
        inst.components.edible.foodtype = GLOBAL.FOODTYPE.SHADOWFOOD
        inst.components.edible.healthvalue = HEALTH_PER_FUEL
        inst.components.edible.hungervalue = HUNGER_PER_FUEL
    end
end)

AddPrefabPostInit("yourcharacterprefab",function(inst)
    if inst.components.eater==nil then
        inst:AddComponent("eater") -- in case it is no eater yet
    end
    inst.components.eater:SetDiet({ GLOBAL.FOODTYPE.SHADOWFOOD })
end)

this is the general code (the yourcharacter part can ofcourse also be put into masterpostinit of your character, remove the GLOBAL in this case).

Now to gears:
One problem with gears is, that ths robot wx87 or however he is called, can eat gears already. So the gears already have a foodtype. If you change this type, wx87 can not eat gears anymore.
So you should not change gears itself, only copy the eater code from wx87 and you are fine (then both of you can eat gears)
This is the relevant code from wx78:

    if inst.components.eater ~= nil then
        inst.components.eater:SetCanEatGears()
    end

 

Edited by Serpens
Link to comment
Share on other sites

right, that makes sense. for some reason i couldn't find it in wx87. thanks for the help, ill try it out once i have the time

also, the relevent code from wx78

    if inst.components.eater ~= nil then
        inst.components.eater:SetCanEatGears()
    end

goes into the modmain right?

Edited by PixaL SKulLKid
Link to comment
Share on other sites

2 hours ago, PixaL SKulLKid said:

right, that makes sense. for some reason i couldn't find it in wx87. thanks for the help, ill try it out once i have the time

also, the relevent code from wx78


    if inst.components.eater ~= nil then
        inst.components.eater:SetCanEatGears()
    end

goes into the modmain right?

if it is your character it goes into master post init of your character.
If you want to change an existing character it goes into modmain into

AddPrefabPostInit("character you want to change",function(inst)
    ---
end)
Link to comment
Share on other sites

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
 Share

×
  • Create New...