#2
22nd Jan 2021 at 12:58 PM
Posts: 3,860
Thanks: 8548 in 67 Posts
28 Achievements
Quote: Originally posted by CyrusBanefort
I've looked around for some documentation on Reaction Broadcasters, mostly finding information on the TS4 ones. Do they work in a similar fashion in TS3? If not, where could I find some info on them?
|
Heya!
It's funny that you asked, I too was looking into this yesterday :p but it's actually not that difficult.
A simple version of it would be:
Code:
// Our reaction interaction class. Keep in mind that the previous interaction will get canceled and this one will be added to the queue. Sort of like 'react to fire'
public class SeeingSomeoneJournalReaction : Interaction<Sim, LyraleiJournal>
{
public class Definition : InteractionDefinition<Sim, LyraleiJournal, SeeingSomeoneReadJournalReaction>
{
public override string GetInteractionName(Sim a, LyraleiJournal target, InteractionObjectPair interaction)
{
return "Journal Reaction seeing";
}
// This part is super important! Here you check whether the ReactionBroadcast should be triggered for a particular sim. For sims giving birth, you wouldn't want them to react on themselves but sims that are not pregnant, then you'd want to have a special check like ' if(!a.SimDescription.IsPregnant), return true' or something like that
public override bool Test(Sim a, LyraleiJournal target, bool isAutonomous, ref GreyedOutTooltipCallback greyedOutTooltipCallback)
{
if (a.SimDescription.SimDescriptionId != target.mOwnerDescId.SimDescriptionId)
{
return true;
}
return false;
//if (a.SimDescription.SimDescriptionId == target.mOwnerDescId.SimDescriptionId)
//{
// return true;
//}
}
}
public static InteractionDefinition Singleton = new Definition();
public override bool Run()
{
print("Hey!! I'm writing in my journal!!");
string socialName = base.Actor.SimDescription.Teen ? "Teen Insult" : "Shoo";
Sim.ForceSocial(base.Actor, base.Target.CopyingSim, socialName, InteractionPriorityLevel.High, true);
InteractionInstance entry = PickUpJournal.Singleton.CreateInstance(base.Target, base.Actor, new InteractionPriority(InteractionPriorityLevel.High), false, true);
base.Actor.InteractionQueue.Add(entry);
return true;
}
}
public class WriteInJournal : Interaction<Sim, LyraleiJournal>
{
// Pretend everything a regular interaction needs is here....
public override bool Run()
{
base.StandardEntry();
base.BeginCommodityUpdates();
base.Target.SeeingBroadcasterCreate(base.Target);
// When we get to the end of the interaction:
base.Target.SeeingBroadcasterDestroy();
base.StandardExit(true);
return true;
}
}
[Tunable]
// Depending on what you need, there are a few differnet ways to set the params, but most of the time this is enough.
public static ReactionBroadcasterParams kCopyingBroadcasterParams = new ReactionBroadcasterParams();
[Tunable]
public ReactionBroadcaster mCopyingBroadcaster;
public void CopyingBroadcasterCreate(LyraleiJournal copiedHomework)
{
mCopyingBroadcaster = new ReactionBroadcaster(this, kCopyingBroadcasterParams, CopyingReactionCallback);
}
public void CopyingBroadcasterDestroy()
{
mCopyingBroadcaster.Dispose();
mCopyingBroadcaster = null;
}
public static void CopyingReactionCallback(Sim s, ReactionBroadcaster rb)
{
LyraleiJournal homework = rb.BroadcastingObject as LyraleiJournal;
if (s.SimDescription.SimDescriptionId == homework.mOwnerDescId.SimDescriptionId && homework.CopyingSim != null)
{
InteractionInstance entry = SeeingSomeoneReadJournalReaction.Singleton.CreateInstance(homework, s, new InteractionPriority(InteractionPriorityLevel.High), false, true);
s.InteractionQueue.AddNext(entry);
}
}
And voila! You got yourself a simple reactionbroadcast