Jump to content

Custom food values?


Recommended Posts

10 hours ago, Scrumch said:

Continuing from my last post, I figured out where I went wrong.

I need to find a way to change the values of a food item when by a specific character? What would be the best way to do this?

how about the perk from wortox which only receives half of every food value?
It is done within his eater component, so within your masterpostinit after adding the eater component, simply do:

    if inst.components.eater ~= nil then
        inst.components.eater:SetAbsorptionModifiers(health, hunger, sanity)
    end

replace health, hunger, sanity with your values. 1 will be normal, 0.5 will be half like wortox and so on.

(eater component is most likely automatically added, so put this code just somewhere of masterpostinit)

Edited by Serpens
Link to comment
Share on other sites

So you have both, a custom character and a custom food item and you want that food to be eaten by every player, but only your player should get different values?
Hm, no simple solution for this, although it is possible.
But maybe you should think about an easy solution, like to make this food only eatable for your character? Or take a look at webbers monster meat code or I think Wormwood can eat manure?

Link to comment
Share on other sites

wouldn't be simple if it was a certain character to do this

inst.component.edible.oneaten = custom

function custom (inst , eater) 

if eater:HasTag("character tag") then     ---------------------- # i think. if eater.prefab = "your character" then .should work too
inst.components.edible.hungervalue = new value
end
end

 

Edited by thomas4845
Link to comment
Share on other sites

45 minutes ago, thomas4845 said:

wouldn't be simple if it was a certain character to do this


inst.component.edible.oneaten = custom

function custom (inst , eater) 

if eater:HasTag("character tag") then     ---------------------- # i think. if eater.prefab = "your character" then .should work too
inst.components.edible.hungervalue = new value
end
end

 

if you take a look at the eater component, you see that "OnEaten" is called AFTER the hunger/helaht/sanity changes, so that would not solve it. There is a way to do it, but it might be kinda "hacky" (at least I can't imagine another way right now) and you should try to not use hacky ways, if there is an easier solution somehow.

edit:
Another simple way would be to use the foodmemory of warly. This checks for a specific food prefab and you could manipulate it that way, that it always returns 0.5 for a specific food if it is your character.

Edited by Serpens
Link to comment
Share on other sites

idk then maybe go into the character then change it to when he eats it it'll create a increase in health basically stacking it

ok i checked it up and it should be as simple as

inst.components.eater.oneatfn = (newval)

newval (inst, food)
if food.prefab = "yourfood" then 
inst.components.hunger:dodelta("hunger value on top of the old one") # what i mean by this is  that this value stacks on the old one
end
end

 

Link to comment
Share on other sites

Even if you are making a food item, you MAY patch any character (including mod characters).

All you need is prefab name of that character. So you can create AddPrefabPostInit initialization in modmain.lua.

Are you interested in this method?

Edited by Maris
Link to comment
Share on other sites

In ShowMe there already is a method to catch the change. It was made few years ago. And it's described on API page of the mod. I was going to suggest a such method.

I mean function FoodValuesChanger. That's why I'm talking about patching characters.

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