- Site Map >
- Modding and Creation >
- Sims 3 Creation >
- Modding Discussion >
- How to check whether a custom ingredient is on your sims inventory
- Site Map >
- Modding and Creation >
- Sims 3 Creation >
- Modding Discussion >
- How to check whether a custom ingredient is on your sims inventory
Replies: 2 (Who?), Viewed: 692 times.
#1
5th Oct 2023 at 4:19 AM
Posts: 268
Thanks: 1168 in 17 Posts
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:
However, it doesn't seem to work for custom ingredients. Could someone point me in the right direction?
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; } }
Advertisement
#2
8th Oct 2023 at 11:01 PM
Posts: 268
Thanks: 1168 in 17 Posts
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:
And here is the test method which verifies that my sim has at least 15 ingredients in order for the interaction to become available.
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); } } }
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; }
#3
9th Oct 2023 at 9:09 PM
Posts: 268
Thanks: 1168 in 17 Posts
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:
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.
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; }
Who Posted
|