Jump to content

Custom Character who should only eat mechanical things.


Recommended Posts

I've spent the last day and a half trying to make a character who can only consume 3 things, Gears, Transistors, and Gold nuggets, to restore Hunger and Health.

I've been lurking around in various forums and places trying to add this functionality but so far no luck. I have this line added in my modmain.lua;


----

local FOODTYPE = GLOBAL.FOODTYPE
FOODTYPE.GEM = "GEM"


function GemPostInit(inst)
    inst:AddTag("edible_"..FOODTYPE.GEM)
end

AddPrefabPostInit("gears", GemPostInit)
AddPrefabPostInit("goldnugget", GemPostInit)
AddPrefabPostInit("gears", GemPostInit)
 

----

And this in my character.lua;
----
inst.components.eater:SetDiet({ FOODGROUP.GEM }, { FOODGROUP.GEM })
        inst.components.eater:SetOnEatFn(foodbonus)
----
local function foodbonus(inst, food)
  if inst.components.eater and food.prefab == "gears" then
    inst.components.sanity:DoDelta(15)
    inst.components.health:DoDelta(150)
    inst.components.hunger:DoDelta(25)
  end
if inst.components.eater and food.prefab == "goldnugget" then
    inst.components.sanity:DoDelta(5)
    inst.components.health:DoDelta(60)
  end
if inst.components.eater and food.prefab == "transistor" then
    inst.components.hunger:DoDelta(100)
  end
end
----


After many crashes and troubleshooting, the game now plays without crashing, but I cannot consume any of these three items. I would like to add the custom foodgroup to these specifically so that other characters don't gain the same benefits, as only this character will be able to consume from the foodgroup. (Note, the name of the foodtype 'GEM' is arbitrary)

The idea behind this character is that they cannot consume food as they are a robot without a mouth, (Or a chemical Engine) so they must utilize transistors to power themselves back up like batteries, and use Gears and Gold nuggets to repair themselves.

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