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
Instructor
Original Poster
#26 Old 9th Dec 2014 at 9:17 AM Last edited by SimsMatthew : 9th Dec 2014 at 11:02 AM.
Yes, I do plan using the original animations.
I'll have to see if simply changing == to ".Equals()" will work. If not, then perhaps I'll have to use your code to see if CanAddToinventory actually matters.

Your new code does help, since I believe FindAll<Ingredient>(false) is more reliable.
Advertisement
Instructor
Original Poster
#27 Old 9th Dec 2014 at 12:01 PM Last edited by SimsMatthew : 9th Dec 2014 at 12:11 PM.
Oh YES! YES! YES! It's so difficult for me to hide the happiness of success! I now find out that base.IgnoreInventoryValidation WORKS! This removes the check and I can now drag ingredients into it! Ingredients are successfully purged from inventory, if the input is correct. If not, the items will be returned to Actor Inventory! Just as how I wanted!

Though, the barrel doesn't become "empty" when items are purged. Moreover, the Sim doesn't play any animation at all. I changed it by putting the code in this new way:

Code:
//Block 1
base.AcquireStateMachine ("NectarMaker");
base.SetActor ("nectarMaker", this.Target);
base.SetActorAndEnter ("x", this.Actor, "Enter Add Fruit");
base.AnimateSim ("Exit");

//Block 2
Target.Inventory.DestroyItems ();
Target.mList1.Clear ();
Target.mList2.Clear ();
Target.mAddNonDraggableIngCount = 0;
Target.mChocType = WhiteChocolate + "";


...I changed the order of these two blocks of code, separated by an empty line. It was Block 2, then 1. Now it's 1, and then 2. This should fix my first problem, will test. But since the first block is already what I found in AddFruit, I don't see extra code that can make Sim animate. So what can I do?
Inventor
#28 Old 9th Dec 2014 at 5:14 PM
You are full of resources
So now you can add any kind of object to the inventory?
I guess you just ignore the extra stuff and return it to the sim's inventory.

Maybe the barrel becomes empty with an animation or some kind of change of state
(using geostates or just swapping between different textures).

About the sim's animation, do the comparison with those of the NectarMaker.
Are sims animated when they add fruit?
Instructor
Original Poster
#29 Old 12th Dec 2014 at 1:35 PM
Stuff on animation: help needed!
I have been unable to work on it these days due to schoolwork. Anyway, here is a small update / query.
Just posting the whole code in case needed.

Code:
using System;
using System.Collections.Generic;
using System.Text;
using Sims3.SimIFace;
using Sims3.Gameplay.Actors;
using Sims3.Gameplay.Autonomy;
using Sims3.Gameplay.EventSystem;
using Sims3.Gameplay.Interactions;
using Sims3.Gameplay.Utilities;
using Sims3.UI;
using Sims3.Gameplay.CAS;
using Sims3.Gameplay.Interfaces;
using Sims3.Gameplay.Abstracts;
using Sims3.SimIFace.Enums;
using Sims3.Gameplay.ActorSystems;
using Sims3.Gameplay.Objects.HobbiesSkills;
using Sims3.Gameplay.UI;
using Sims3.Gameplay.Objects.FoodObjects;
using Sims3.Gameplay.Core;

namespace Sims3.Gameplay.Objects.Simsmatthew
{
	public class Simsmatthew_Chocolate : NectarMaker
	{
		//Independent Variables for each Simsmatthew_Chocolate
		public List<ObjectGuid> mList1 = new List<ObjectGuid>();
		public List<ObjectGuid> mList2 = new List<ObjectGuid>();
		public List<Ingredient> mInvItemList = new List<Ingredient> ();
		public Ingredient mFinalIng1;
		public Ingredient mFinalIng2;
		public Ingredient mFinalIng3;
		public Ingredient mFinalIng4;
		public double mChocScore;
		public bool mAddedChoc;
		public string mChocType;

		[Tunable]
		public static bool kInstantiator = true;
		[Tunable]
		public static int kHorrifyingScore = -4;
		[Tunable]
		public static int kPerfectScore = 8;

		public static string WhiteChocolate = Localization.LocalizeString ("Simsmatthew/Simsmatthew_Chocolate:WhiteChocolate", new object[0]);
		public static string MilkChocolate = Localization.LocalizeString ("Simsmatthew/Simsmatthew_Chocolate:MilkChocolate", new object[0]);
		public static string DarkChocolate = Localization.LocalizeString ("Simsmatthew/Simsmatthew_Chocolate:DarkChocolate", new object[0]);
		public static string Add = Localization.LocalizeString ("Simsmatthew/Simsmatthew_Chocolate:Add", new object[0]);
		public static string GenericFailMsg = Localization.LocalizeString ("Simsmatthew/Simsmatthew_Chocolate:GenericFailMsg", new object[0]);

		public override void OnStartup()
		{
			base.OnStartup();
			base.AddInteraction (AddWhiteChocolate.Singleton);
			base.RemoveInteractionByType (NectarMaker.AddFruit.Singleton);
			base.RemoveInteractionByType (NectarMaker.PlaceGrapesFor.Singleton);
			base.RemoveInteractionByType (NectarMaker.Repair.Singleton);
			base.RemoveInteractionByType (NectarMaker.TakeNectar.Singleton);
			base.RemoveInteractionByType (NectarMaker.SquishGrapes.Singleton);
			base.RemoveInteractionByType (NectarMaker.MakeNectar.Singleton);
			base.RemoveInteractionByType (NectarMaker.PredictComboEffectiveness.Singleton);
			base.RemoveInteractionByType (NectarMaker.UpgradePreventBreakage.Singleton);
			base.RemoveInteractionByType (NectarMaker.UpgradeImprovedPressing.Singleton);
			base.RemoveInteractionByType (NectarMaker.UpgradeFlavorEnhancement.Singleton);
			base.RemoveInteractionByType (NectarMaker.Tinker.Singleton);
			base.Inventory.IgnoreInventoryValidation = true;
		}

		public override void OnCreation()
		{
			base.OnCreation ();
			this.mAddedChoc = false;
			this.mChocScore = 0;
			this.mChocType = "";
		}

		public static double CalScore (Quality quality)
		{
			switch (quality) 
			{
			case Quality.Horrifying:
				return kHorrifyingScore; //=-4

			case Quality.Putrid:
				return kHorrifyingScore + 1; //=-3

			case Quality.Foul:
				return kHorrifyingScore + 2;  //=-2

			case Quality.Bad:
				return kHorrifyingScore + 3;  //=-1

			case Quality.Perfect:
				return kPerfectScore; //=8
			
			case Quality.Outstanding:
				return kPerfectScore - 2;  //=6

			case Quality.Excellent:
				return kPerfectScore - 4;  //=4

			case Quality.Great:
				return kPerfectScore - 5;  //=3

			case Quality.VeryNice:
				return kPerfectScore - 5.5;  //=2.5

			case Quality.Nice:
				return kPerfectScore - 6;  //=2

			case Quality.Neutral:
				return kPerfectScore - 7;  //=1
			}

			return 0;
		}

		//To-be-done Interactions

		public void AddToLists(Simsmatthew_Chocolate ChocolateMaker, String Key1, String Key2)
		{
			foreach (Ingredient ingredient in ChocolateMaker.Inventory.FindAll<Ingredient>(false)) 
			{
				if (ingredient.IngredientKey.Equals(Key1)) 
				{
					ChocolateMaker.mList1.Add (ingredient.ObjectId);
					ChocolateMaker.mChocScore += CalScore (ingredient.GetQuality ());
				} 

				else if (ingredient.IngredientKey.Equals(Key2)) 
				{
					ChocolateMaker.mList2.Add (ingredient.ObjectId);
				}
			}
		}


		public sealed class AddWhiteChocolate : Interaction<Sim, Simsmatthew_Chocolate>
		{
			public static readonly InteractionDefinition Singleton = new Definition();

			public void LoopDel(StateMachineClient smc, InteractionInstance.LoopData loopData)
			{
				if (HudModel.CurrentSecondaryInventoryOwner != this.Target)
				{
					this.Actor.AddExitReason(ExitReason.Finished);
				}
			}

			public override bool Run()
			{
				HudModel.OpenObjectInventoryForOwner(this.Target);
				bool result = this.DoLoop(ExitReason.Default, new InteractionInstance.InsideLoopFunction(this.LoopDel), null);
				if (HudModel.CurrentSecondaryInventoryOwner == this.Target)
				{
					HudModel.OpenObjectInventoryForOwner(null);
				}

				Target.AddToLists (Target, "Cocoa", "Milk");

				if (Target.Inventory.NumItemsStored == 4 && Target.mList1.Count == 1 && Target.mList2.Count == 3 && !Target.InUse && !Target.mAddedChoc) 
				{
					this.Target.RouteToBarrelSlot (this.Actor);
					base.AcquireStateMachine ("NectarMaker");
					base.SetActor ("nectarMaker", this.Target);
					base.SetActorAndEnter ("x", this.Actor, "Enter Add Fruit");
					base.AnimateSim ("Exit");

					Target.Inventory.DestroyItems ();
					Target.mList1.Clear ();
					Target.mList2.Clear ();
					Target.mAddedChoc = true;
					Target.mChocType = WhiteChocolate + "";
				} 

				else 
				{
					StyledNotification.Show (new StyledNotification.Format (GenericFailMsg, Actor.ObjectId, StyledNotification.NotificationStyle.kGameMessagePositive));
					Target.mList1.Clear ();
					Target.mList2.Clear ();
					Target.mChocScore = 0;
					Target.Inventory.MoveObjectsTo (Actor.Inventory);
				}

				return result;
						
			}

			[DoesntRequireTuning]
			public sealed class Definition : InteractionDefinition<Sim, Simsmatthew_Chocolate, AddWhiteChocolate>
			{
				public override string GetInteractionName(Sim a, Simsmatthew_Chocolate target, InteractionObjectPair interaction)
				{
					return Add + " " + WhiteChocolate;
				}
				public override bool Test(Sim a, Simsmatthew_Chocolate target, bool isAutonomous, ref GreyedOutTooltipCallback greyedOutTooltipCallback)
				{
					return (a != null && target != null && !target.InUse && a.SimDescription.YoungAdultOrAbove && !a.IsPet);
				}
			}
		}
	}
}


I just copied the animation-related code in AddFruit interaction. The sim does do the animation, but not at the correct slot. He will just do it at where he is originally standing. The barrel does become filled (will change the fruit texture to chocolate, easy job). I did use this.Target.RouteToBarrelSlot(this.Actor) as my decompiled code gives. I have only tested without prefix "this." but I believe it's not the main cause. What can I do?
Inventor
#30 Old 12th Dec 2014 at 3:22 PM Last edited by Arsil : 12th Dec 2014 at 3:46 PM.
The routing method's return value is not used as a condition in the "if" statement, so if it fails the code is executed
anyway and you should put the routing check way before its current position, use the AddFruit code as reference.

Try also adding an ITUN for the interaction, copying the one from AddFruit and making the necessary changes.

It's a nice practice to put a big chunk of code inside the spoiler tag.
Field Researcher
#31 Old 12th Dec 2014 at 4:30 PM
You should really stop inheriting from NectarMaker before going any further or you're going to get into troubles at some point. To name one, NRaas ErrorTrap retrieves all the NectarMaker classes (yours will be included) and tries to dereference them. That can either break your object or cause an error in ErrorTrap while trying to read the fields from the class. Also, since as far as EA is concerned NectarMaker has no derived classes, they might be referencing it somewhere and yours will be included, causing some unexpected behavior. This also includes all mods that use the NectarMaker class to add or replace interactions (if there are none out, there could be), and as a result those interactions will be added to your object too, which is not pretty

Nothing's real. Nothing's unreal either.
The frontier between true and untrue is a shady fuzzy line.
Destiny, or maybe the long flight's time-span, shall decide the issue.
Page 2 of 2
Back to top