Jump to content

How to get the spice data ?

Recommended Posts

Hi again, new problem here :) And thanks you so much for your help so far on the forums, it helped more than just me, keep goin.


So. I'm trying to make an "oneat" function on a character that will get as much data as possible about the food it eat. For hunger, health and sanity, it's easy. But I also need now to get the spice applied to it. :/

And my attempts are not that successful :

if food.components.edible.spice ~= nil then
     if food.components.edible.spice == "spice_chili" then
           v.components.debuffable:AddDebuff("buff_attack", "buff_attack")

For now it's just figuring out if the food is spiced or not but to detect which one is it, it don't works, err... Hope you know how this data is saved to the food.

Edited by ADM
Link to comment
Share on other sites

3 minutes ago, Ultroman said:

Where do you see any mention of this "spice" variable on the edible component? I can't find any "spice" variable anywhere in the game code.

local Edible = Class(function(self, inst)
    self.spice = nil


Can guarantee you it is here. I tried making prints after eating a food with spice and it worked

Link to comment
Share on other sites

Ultroman: unpack the newest scripts.zip , I also forget this often :D

The self.spice is currently used within edible to multiply different values with help of TUNING.SPICE_MULTIPLIERS[self.spice].
But if you look into TUNING you will see that this table is empty and a note that this will be added later.
So I guess it is very likely that also self.spice is currently always nil (you can print it and see what it is.. if it is not nil, then report back, but if so, there is no problem to solve :D) and it is also added later.

Meanwhile you could use the prefab to find out about the spice. In spicedfoods.lua you see how the name of the food is changed to foodname_spicename, so you can do:

local splitfood = string.split(foodprefab,"_")
local maybe_spicename = splitfood[#splitfood] -- get the last part of the string, it may be the spicename

You can use this in case self.spice is nil. And in case it is not, you use your current code, so after the devs added it, you dont have to update your mod.

Another better way would be to load spicedfoods.lua and see if the food you ate is part of that, (I use this within my Show Me mod version to show the buff of food when hovering over it)

local spicedfoods = require("spicefoods")

-- .. 
-- and within your function:
local spiced = spicefoods[foodprefab]
if spiced~=nil then -- then it is a food from spicefoods.lua and you can get any information you want that is returned within spicedfoods.lua (and also in preparedfoods + preparedfoods_warly)
    print(spiced.prefabs) -- will be the buffs
    print(spiced.spice) -- will be the spicename in upper letters
    - and so on

So if you plan to add another buff to food (your code looks like that)  you should also add that buff to the prefabs (the ones shown in aboves code.. no clue why they called the bufflist "prefabs").
All in all adding those buffs is very poorly made from the devs and it is hard to correctly add new buffs within mods, without breaking everything. It would be better if devs made a "AddDebuffToFood" function, so inexperienced modders can simply add anything they want...
Eg. you also have to make sure that you don't overwrite any previous oneaten function. So if you make an oneaten function, always make sure you call the old function afterwards, if there was any.

Edited by Serpens
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

  • Create New...