Hi there! You are currently browsing as a guest. Why not create an account? Then you get less ads, can thank creators, post feedback, keep a list of your favourites, and more!
Quick Reply
Search this Thread
Field Researcher
Original Poster
#1 Old 5th Oct 2023 at 4:19 AM
Default How to check whether a custom ingredient is on your sims inventory
I was struggling in making a function that checks if you happened to have a custom ingredient in your inventory. How would I go about setting that up? I had tried this...
Code:
public override bool Test(Sim actor, EmptyJar target, bool isAutonomous, ref GreyedOutTooltipCallback greyedOutTooltipCallback)
                {
                    List<IGameObject> WhiteWidowBudList = actor.Inventory.FindAllOfType(typeof(WhiteWidowBud));
                    List<IGameObject> PurpleHazeBudList = actor.Inventory.FindAllOfType(typeof(PurpleHazeBud));
                    List<IGameObject> SkunkBudList = actor.Inventory.FindAllOfType(typeof(SkunkBud));
                    List<IGameObject> OGKushBudList = actor.Inventory.FindAllOfType(typeof(OGKushBud));
                    List<IGameObject> AK47BudList = actor.Inventory.FindAllOfType(typeof(AK47Bud));
                    List<IGameObject> AmnesiaBudList = actor.Inventory.FindAllOfType(typeof(AmnesiaBud));
                    

                    if (actor.SimDescription.ChildOrBelow || !actor.SimDescription.IsHuman)
                    {
                        return false;
                    }
                    else if(WhiteWidowBudList.Count >= 15 || PurpleHazeBudList.Count >= 15 || SkunkBudList.Count >= 15 || OGKushBudList.Count >= 15 || AK47BudList.Count >= 15 || AmnesiaBudList.Count >= 15)
                    {
                        return true;
                    }
                    else
                    {
                        string message = Localization.LocalizeString("MonocoDoll/DrugDealing/CuringWeed/Need15Buds:GreyedOutName");
                        greyedOutTooltipCallback = CreateTooltipCallback(message);
                        return false;
                    }
                }
However, it doesn't seem to work for custom ingredients. Could someone point me in the right direction?
Advertisement
Field Researcher
Original Poster
#2 Old 8th Oct 2023 at 11:01 PM
Earlier today I found the solution. Ingredients are different than objects when your script tries to gather them. Here is how the ingredient is set up in my script
Code:
public class WhiteWidowBud : Ingredient
    {
        public override void OnLoad()
        {
            mIngredientKey = "MonocoDoll_CannabisWhiteWidow_Ingredient";
            base.OnLoad();
        }

        public override void OnStartup()
        {
            base.OnStartup();
            if (Data == null)
            {
                mIngredientKey = "MonocoDoll_CannabisWhiteWidow_Ingredient";
                IngredientData.NameToDataMap.TryGetValue(mIngredientKey, out Data);
            }
        }
    }
And here is the test method which verifies that my sim has at least 15 ingredients in order for the interaction to become available.
Code:
 public override bool Test(Sim actor, EmptyJar target, bool isAutonomous, ref GreyedOutTooltipCallback greyedOutTooltipCallback)
                {

                    List<Ingredient> WhiteWidowBudList = actor.Inventory.FindAll<Ingredient>(checkInUse: true);
                    

                    if (actor.SimDescription.TeenOrAbove && actor.SimDescription.IsHuman)
                    {
                        for (int i = 14; i < WhiteWidowBudList.Count; i++)
                        {
                            if ((WhiteWidowBudList[i].IngredientKey == "MonocoDoll_CannabisWhiteWidow_Ingredient"))
                            {
                                return true;
                            }
                        }
                        
                        string message = Localization.LocalizeString("MonocoDoll/DrugDealing/CuringWeed/Need15WhiteWidowBuds:GreyedOutName");
                        greyedOutTooltipCallback = CreateTooltipCallback(message);
                        return false;
                    }

                    return false;
                }
Field Researcher
Original Poster
#3 Old 9th Oct 2023 at 9:09 PM
Wanted to come back and make a correction. On my test method The code to determine whether a sim has a specific number of a specefic ingredient would be this.
Code:
 public override bool Test(Sim actor, EmptyJar target, bool isAutonomous, ref GreyedOutTooltipCallback greyedOutTooltipCallback)
                {

                    List<Ingredient> WhiteWidowBudList = actor.Inventory.FindAll<Ingredient>(checkInUse: true);
                    

                    if (actor.SimDescription.TeenOrAbove && actor.SimDescription.IsHuman)
                    {
                        int num = 0;
                        for (int i = 0; i < WhiteWidowBudList.Count; i++)
                        {
                            if ((WhiteWidowBudList[i].IngredientKey == "MonocoDoll_CannabisWhiteWidow_Ingredient"))
                            {
                                num++;
                                if(num > 15)
                                {
                                    return true;
                                }
                            }
                            
                        }
                        
                        
                        string message = Localization.LocalizeString("MonocoDoll/DrugDealing/CuringWeed/Need15WhiteWidowBuds:GreyedOutName");
                        greyedOutTooltipCallback = CreateTooltipCallback(message);
                        return false;
                    }

                    return false;
                }
On my previous test method, it would return true if the sim had 15 or more ingredients in total and one of them was the proper ingredient. When in actuality I wanted it only to return true if the sim had the proper amount of ingredients.
Back to top