Jump to content

Help Needed, Character Mod 'Food Traits'


Iceifirex

Recommended Posts

Hello,

 

This is my very first mod that I've ever made and i'm having trouble on a certain piece of coding. I'm pretty much new to coding and only understand very basic stuff so please don't get too hard on me if I ask/say something that seems impractical or obvious....

 

For my mod, I would like my character to be able to eat your 'generic' food types although since she prefers to eat meat and dislikes vegetables, fruits and seeds:

 

She should gain 1.25x more hunger from meats,

 

She should gain 0.25x more hunger from vegetables,

 

She should gain 0.50x more hunger from fruits,

 

and

 

She should gain 0.25x more hunger from seeds.

 

So technically my character won't gain as much hunger from certain types of foods but will still be able to eat them. I know that I can add a negative value to specific food types to decrease the amount of hunger gained all together, although I feel as though that might negate any benefits from eating certain foods so that eating it would be pretty much pointless or make the character hungrier which wouldn't make much sense.

Speaking of, I really hope what i'm saying makes sense...    -_-   Feel free to let me know if it doesn't.

 

I've downloaded a few other mods for examples in an attempt to figure it out myself, but I really don't know how to piece it all together - it feels like i'm trying to complete a puzzle from multiple other puzzles... I've tried doing it 'logically' although that never seems to work with my experience ^_^. 
 

Here's something that I tried to come up with...

 

-- Making the character gain benefits/losses from eating certain kinds of foods.
local function OnEat(inst, food)
if food.components.edible and food.components.edible.foodtype == "MEAT" then
               (item.components.edible:GetHunger() * 1.25)
          elseif food.components.edible
and food.components.edible.foodtype == "VEGGIE" then
(item.components.edible:GetHunger() * 0.25)
end
end
 
Link to comment
Share on other sites

try this:

 

local function FoodAdjust(inst, food)
    if not food:HasTag("adjustedfood") then

            if food.components.edible.foodtype == "MEAT" then

                      inst.components.hunger:DoDelta(+food.components.edible.hungervalue * 0.25, false, "transformation")
                      food.components.edible.hungervalue = food.components.edible.hungervalue * 1.25
            end

            if food.components.edible.foodtype == "VEGGIE" then

                      inst.components.hunger:DoDelta(-food.components.edible.hungervalue * 0.75, false, "transformation")
                      food.components.edible.hungervalue = food.components.edible.hungervalue * your tuning value goes here
            end

            if food.components.edible.foodtype == "FOODTYPE.ETC" then

                      inst.components.hunger:DoDelta(+/-food.components.edible.hungervalue * inverse of your tuning value -or- remainder of your tuning value, false, "transformation")
                      food.components.edible.hungervalue = food.components.edible.hungervalue * your tuning value goes here
            end
            food:AddTag("adjustedfood")
    end
end

 

and dont forget to put this in your local fn = function(inst) :

    inst.components.eater:SetOnEatFn(FoodAdjust)

 

 

 

1 problem with this is that your character will still get the full effects of the food the first time they eat it. for nstance; fruit is set to .25, character eats berries for the first time, gives 9.4 hunger. then the value gets changed. gimmie a lil bit and i might have a fix for that

 

nevermind, stole a line from the caitlin mod, dunno if %100 of it's needed but, hey, it works

Link to comment
Share on other sites

Thank you so much for helping me out :)

I tried the lines of code you gave me, although it doesn't seem to be working. This is what is looks like on my lilith.lua (my character)

 

local function FoodAdjust(inst, food)
  if not food:HasTag("adjustedfood") then
    if food.components.edible.foodtype == "MEAT" then
      inst.components.hunger:DoDelta(+food.components.edible.hungervalue * 0.25, false, "transformations")
      food.components.edible.hungervalue = food.components.edible.hungervalue * 1.25
   end
      if food.components.edible.foodtype == "VEGGIE" then
      inst.components.hunger:DoDelta(-food.components.edible.hungervalue * 0.75, false, "transformations")
      food.components.edible.hungervalue = food.components.edible.hungervalue * 0.25
   end
      if food.components.edible.foodtype == "SEEDS" then
      inst.components.hunger:DoDelta(-food.components.edible.hungervalue * 0.75, false, "transformations")
      food.components.edible.hungervalue = food.components.edible.hungervalue * 0.25
   end
   food:AddTag("adjustedfood")
 end
end
 
I also put the  inst.components.eater:SetOnEatFn(FoodAdjust) with the local fn = function(inst) but for some reason it isn't working. I had a look at the game's log file and it says:
 
...ps/common/dont_starve/data/scripts/mainfunctions.lua:71: Error loading file prefabs/lilith
...amapps/common/dont_starve/data/../mods/Lilith/scripts/prefabs/lilith.lua:78: unexpected symbol near '+'
 
Any idea on what that might be?
I also tried getting rid of the "transformations" lines since I haven't really specified what "transformations" is in the coding, but that didn't seem to make a difference.
 
When I load the game, it comes up with the follow prompt:

"Mods Installed!"
"The following mods failed to run last time and have been disabled: "Lilith"
Check the forums for updated versions"

[ I Understand ]           [ Disable Mods ]          [ Mod Forums ]
 
The screen then freezes and I can't click on any of the three options; forcing me to close the game.

Am I doing anything wrong?
 
Link to comment
Share on other sites

Okay, I removed the positive and negative values in the code and it works... but afterwards, there was an error complaining about FoodAdjust not being assigned a variable or something like that. So, before local function FoodAdjust(inst, food), I put in the line FoodAdjust = 1. Of course, I didn't expect it to work, but it did. Until I ate something of course (which was a plain carrot).

Is there anything I can add or change to make this code work? Also, thank you for your time.

Link to comment
Share on other sites

okay, so first thing that stands out to me is that "+" is unnecessary, my bad. keep the "-"'s tho.
 
outside of that, FoodAdjust inst a variable, it's a function. I've had this problem a lot and usually find some really ugly way to go around it rather than solve the problem itself. (still very new to lua)
 
 
now, i've tried your exact code (without the single "+") myself and it works for me. so something that hasnt been mentioned thus-far in the post is to blame most likely. would you mind sharing your lilith.lua and modmain.lua? personally troubleshooting this is all i can really offer.

 

 

 

 

edit:

 

replace :

inst.components.hunger:DoDelta(-food.components.edible.hungervalue * 0.75, false, "transformations")

 

 

with :

inst.components.hunger.current = (inst.components.hunger.current - food.components.edible.hungervalue * 0.75)

 

 

bit cleaner and wont give you that 'stat injury' noise when you eat a food for the first time.

Link to comment
Share on other sites

Sorry that I haven't replied in a while. My computer currently doesn't have access to the internet so I couldn't exactly check this page. It would be great if you'd take a look at my files to see what's going on - thanks for that. It might have to wait a couple more days though.

Sorry for all the problems.

Link to comment
Share on other sites

I managed to fix the problem. Turns out I was at fault for not placing the main part of the code above the 'local fn = function(inst)'. I don't know why I didn't try it earlier. It works perfectly fine now, although it's a little bit slow when it comes to deducting the hunger gain from the total hunger. It's all good though - barely noticeable.
 

Thanks so much for helping me out with this, I really needed it. When/if I release this mod on Steam, i'll be sure to mention you for all your help. (If there's a particular username you would like me to refer to you as, just let me know.) Have a great Christmas!

Link to comment
Share on other sites

Yes, you do need to remove the "+"'s from everywhere. So I guess it should look like something similar to this:

 

local function FoodAdjust(inst, food)
  if not food:HasTag("adjustedfood") then
      if food.components.edible.foodtype == "MEAT" then
      inst.components.hunger.current = (inst.components.hunger.current - food.components.edible.hungervalue * 0.65)
      food.components.edible.hungervalue = food.components.edible.hungervalue * 1.35
      end
    if food.components.edible.foodtype == "VEGGIE" then
      inst.components.hunger.current = (inst.components.hunger.current - food.components.edible.hungervalue * 0.75)
      food.components.edible.hungervalue = food.components.edible.hungervalue * 0.25
      end
    food:AddTag("adjustedfood")
  end
end
 
With no positives or negatives.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...