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 6th Dec 2022 at 4:25 PM
Default Adding Interactions to phones.
I was wondering how I would go about adding custom Interactions to the cellphones that sims have. I have made my own custom interaction as of this moment. However, I fail to load in the interaction. Here is my code for the custom interaction so far. As a test
Code:
 public class SendDP : SendTextBase
    {
        private sealed class Definition : CallDefinition<SendDP>
        {
            public override string[] GetPath(bool isFemale)
            {
                return new string[2]
                {
                    LocalizeString("SocialNetworking") + Localization.Ellipsis,
                    TextingBase.LocalizeTextingString("GroupName") + Localization.Ellipsis
                };
            }
            public override string GetInteractionName(Sim actor, Phone target, InteractionObjectPair interaction)
            {
                return TextingBase.LocalizeTextingString("SendDP") + Localization.Ellipsis;
            }

            public override bool Test(Sim actor, Phone target, bool isAutonomous, ref GreyedOutTooltipCallback greyedOutTooltipCallback)
            {
                if (!base.Test(actor, target, isAutonomous, ref greyedOutTooltipCallback))
                {
                    return false;
                }
                if (!actor.IsAtHome)
                {
                    return false;
                }
                if (!CanSimInviteOver(actor, isAutonomous) || !CanInviteOverToLot(actor.LotCurrent, isAutonomous))
                {
                    greyedOutTooltipCallback = InteractionInstance.CreateTooltipCallback(TravelUtil.LocalizeString(actor.IsFemale, "CannotInviteOver", actor));
                    return false;
                }

                foreach (IMiniRelationship miniRelationship in Relationship.GetMiniRelationships(actor.SimDescription))
                {
                    if (!miniRelationship.AreRomantic())
                    {
                        continue;
                    }
                    SimDescription simDescription = SimDescription.Find(miniRelationship.GetOtherSimDescriptionId(actor.SimDescription));
                    if (simDescription == null || simDescription.CreatedSim == null || simDescription.CreatedSim.LotCurrent == actor.LotCurrent)
                    {
                        continue;
                    }
                }
                return false;
            }
        }
        [Tunable]
        
        public static readonly InteractionDefinition Singleton = new Definition();

        public override string SendBalloonIcon => "balloon_woohoo";

        public override PhoneTextingAnimStates ViewReaction => PhoneTextingAnimStates.ReceiveJoy;

        public override string GetInteractionName()
            {
                if(mOtherSimDesc != null)

                {
                    return TextingBase.LocalizeTextingString(mOtherSimDesc.IsFemale, "SendDPTo", mOtherSimDesc);
                }
                return base.GetInteractionName();
            }
        public override bool SimCanTextWithActor(SimDescription other)
        {
            if (!base.SimCanTextWithActor(other))
            {
                return false;
            }
            return SimCanTextWithActor(Actor, other, foreignText: false);
        }

        public override void OnCallFinished()
        {
            string DislikedDPReaction = Localization.LocalizeString("MonoDoll/BDProblems/SendDPFail:Message", new object[] { base.Target });
            StyledNotification.Show(new StyledNotification.Format(DislikedDPReaction, Target.ObjectId, StyledNotification.NotificationStyle.kSimTalking));            
            
            base.OnCallFinished();
        }

        public static void ShowInviteFailedDialog(string interactionName, Sim actor)
        {
            SimpleMessageDialog.Show(interactionName, TextingBase.LocalizeTextingString("DPFail", actor), ModalDialog.PauseMode.PauseSimulator);
        }

        public new static bool SimCanTextWithActor(Sim actor, IMiniSimDescription other, bool foreignText)
        {
            if (foreignText)
            {
                return false;
            }
            SimDescription simDescription = other as SimDescription;
            Sim sim = simDescription?.CreatedSim;
            if (sim == null)
            {
                return false;
            }
            if (actor.LotCurrent == sim.LotCurrent)
            {
                return false;
            }
            if (!actor.IsInRomanticRelationshipWith(sim))
            {
                return false;
            }
            if (actor.SimDescription.IsEP11Bot)
            {
                if (actor.TraitManager == null || !actor.TraitManager.HasElement(TraitNames.CapacityToLoveChip))
                {
                    return false;
                }
                if (!simDescription.IsEP11Bot || sim.TraitManager == null || !sim.TraitManager.HasElement(TraitNames.CapacityToLoveChip))
                {
                    return false;
                }
            }
            else if (simDescription.IsEP11Bot)
            {
                return false;
            }
            return true;
        }
      }

The code for my custom cell phone interaction has been taken from EA's cellphone interactions. So that is where I got my code from in terms of making my own custom interaction for phones. Now the method I attempted to load the interaction into was...
Code:
private static void AddSendDPText(Phone phone)
        {
            foreach(InteractionObjectPair interaction in phone.Interactions)
            {
                if (interaction.InteractionDefinition.GetType() == SendDP.Singleton.GetType())
                {
                    return;
                }
            }
            phone.AddInteraction(SendDP.Singleton);
        }
However, even after adding this code into the LoadWorldFinished Event. This does not add my interaction. Additionally, I also tried the same method that I have used for my custom social/immediate interactions...
Code:
private static void AddSendDPText(Sim sim)
        {
            foreach(InteractionObjectPair interaction in sim.Interactions)
            {
                if (interaction.InteractionDefinition.GetType() == SendDP.Singleton.GetType())
                {
                    return;
                }
            }
            sim.AddInteraction(SendDP.Singleton);
        }
Unfortunately, all this does is make sims unable to access their own pie menu's of interactions. Would anyone know any ideas on how to go about loading custom interactions into sims cell phones?
Advertisement
Field Researcher
Original Poster
#2 Old 10th Dec 2022 at 6:57 AM
I managed to load in my custom interaction into sims phone that they use for texting under the Social Networking.../Texting... options. I used the WorldLoadFinished events to add the interaction. However, I fail to add interactions to newly created sims during the game. As of this moment, the interaction only applies to sims whenever the game finished loading up. I have tried the Instantiated event, yet it fails to load my custom texting interactions to new sims phones. I am currently at a loss to why. I will share my code. This is the custom texting interaction.
Code:
public class SendDP : SendTextBase
        {
            public sealed class Definition : CallDefinition<SendDP>
            {
                public override string[] GetPath(bool isFemale)
                {
                    return new string[2]
                    {
                    LocalizeString("SocialNetworking") + Localization.Ellipsis,
                    TextingBase.LocalizeTextingString("GroupName") + Localization.Ellipsis
                    };
                }
                public override string GetInteractionName(Sim actor, Phone target, InteractionObjectPair interaction)
                {
                return "SendDP";
                }
            public override bool Test(Sim actor, Phone target, bool isAutonomous, ref GreyedOutTooltipCallback greyedOutTooltipCallback)
            {
                if (!base.Test(actor, target, isAutonomous, ref greyedOutTooltipCallback))
                {
                    return false;
                }
                bool flag = false;
                if (actor.SimDescription.IsEP11Bot)
                {
                    if (actor.TraitManager == null || !actor.TraitManager.HasElement(TraitNames.CapacityToLoveChip))
                    {
                        return false;
                    }
                    flag = true;
                }
                foreach (IMiniRelationship miniRelationship in Relationship.GetMiniRelationships(actor.SimDescription))
                {
                    if (!miniRelationship.AreRomantic())
                    {
                        continue;
                    }
                    SimDescription simDescription = SimDescription.Find(miniRelationship.GetOtherSimDescriptionId(actor.SimDescription));
                    if (simDescription == null || simDescription.CreatedSim == null || simDescription.CreatedSim.LotCurrent == actor.LotCurrent)
                    {
                        continue;
                    }
                    if (flag)
                    {
                        if (simDescription.IsEP11Bot && simDescription.CreatedSim.TraitManager.HasElement(TraitNames.CapacityToLoveChip))
                        {
                            return true;
                        }
                    }
                    else if (!simDescription.IsEP11Bot)
                    {
                        return true;
                    }
                }
                return false;
            }
        }
           

            public static readonly InteractionDefinition Singleton = new Definition();

        private bool mProceed;

            public override string SendBalloonIcon => "balloon_woohoo";

            public override PhoneTextingAnimStates ViewReaction => PhoneTextingAnimStates.ReceiveJoy;

            public override string GetInteractionName()
            {
                if (mOtherSimDesc != null)

                {
                    return "SendDPicTo";
                }
                return base.GetInteractionName();
            }
            public override bool SimCanTextWithActor(SimDescription other)
            {
                if (!base.SimCanTextWithActor(other))
                {
                    return false;
                }
                return SimCanTextWithActor(Actor, other, foreignText: false);
            }

       

        public override void OnCallFinished()
        {
            if (mOtherSimDesc != null)
            { 

                string DislikedDPReaction = Localization.LocalizeString("MonoDoll/BDP/SendDpicFail:Message", new object[] { base.Target });
                StyledNotification.Show(new StyledNotification.Format(DislikedDPReaction, Target.ObjectId, StyledNotification.NotificationStyle.kSimTalking));
            }
        }

        
            public new static bool SimCanTextWithActor(Sim actor, IMiniSimDescription other, bool foreignText)
            {
                if (foreignText)
                {
                    return false;
                }
                SimDescription simDescription = other as SimDescription;
                Sim sim = simDescription?.CreatedSim;
                if (sim == null)
                {
                    return false;
                }
                if (actor.LotCurrent == sim.LotCurrent)
                {
                    return false;
                }
                if (!actor.IsInRomanticRelationshipWith(sim))
                {
                    return false;
                }
                if (actor.SimDescription.IsEP11Bot)
                {
                    if (actor.TraitManager == null || !actor.TraitManager.HasElement(TraitNames.CapacityToLoveChip))
                    {
                        return false;
                    }
                    if (!simDescription.IsEP11Bot || sim.TraitManager == null || !sim.TraitManager.HasElement(TraitNames.CapacityToLoveChip))
                    {
                        return false;
                    }
                }
                else if (simDescription.IsEP11Bot)
                {
                    return false;
                }
                return true;
            }
        }
This is the code which adds the interaction and makes sure not to add a duplicate interaction if sim already has the custom texting interaction.
Code:
private static void AddSendDPInteraction(Phone phone)
        {
            foreach (InteractionObjectPair interaction in phone.Interactions)
            {
                if (interaction.InteractionDefinition.GetType() == SendDP.Singleton.GetType())
                {
                    return;
                }
            }
            phone.AddInventoryInteraction(SendDP.Singleton);
        }
Relevant code inside the OnWorldLoadFinished event method
Code:
 private static void OnWorldLoadFinished(object sender, EventArgs e)
        {
          

            Phone[] objects1 = Sims3.Gameplay.Queries.GetObjects<Phone>();
            Phone[] array1 = objects1;
            foreach (Phone phone in array1)
            {
                AddSendDPInteraction(phone);
            }
       
        }
Relevant code in the Instantiated Event method.
Code:
private static ListenerAction OnSimInstantiated(Event e)
        {
            try
            {
                
                if (e.TargetObject is Phone phone)
                {
                    AddSendDPInteraction(phone);
                }
            }
            catch
            { }
            return ListenerAction.Keep;
        }

I'm happy that I managed to get my custom texting interaction to show up on sims phones finally. Massive thanks to echoweaver and lizcandor. As echoweaver went over adding inventory interactions and I used lizcandor's "Research polyamory" interaction code as a reference to try to make my custom texting interaction work. I would really like to know why newly created sims don't get the custom texting interaction. Especially since I applied the code to add said interaction on sims that are instantiated. Any help would be appreciated. Thanks!
Back to top