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
Test Subject
Original Poster
#1 Old 4th Jul 2022 at 4:01 PM
Default (Scripting) Detecting Social Interactions
I want to detect when a sim interacts with the active sim (or a sim in the active household?), so that I can do an action. Is this possible? And how do I do it?
Advertisement
Space Pony
#2 Old 4th Jul 2022 at 8:03 PM
You can create a listener to EventTypeId.kSocialInteraction and check if the Active sim is involved
Test Subject
Original Poster
#3 Old 4th Jul 2022 at 8:25 PM Last edited by YolkSims : 4th Jul 2022 at 8:47 PM.
Can you go into more detail? I haven't learned how to create my own eventlistener yet, only how to copy them from elsewhere.

Edit: Like this?
Code:
EventTracker.AddListener(EventTypeId.kSocialInteraction, new ProcessEventDelegate(OnSocialInteraction));
Space Pony
#4 Old 4th Jul 2022 at 8:46 PM
Quote: Originally posted by YolkSims
Can you go into more detail? I haven't learned how to create my own eventlistener yet, only how to copy them from elsewhere.

Edit: Like this?

Code:
EventTracker.AddListener(EventTypeId.kSocialInteraction, new ProcessEventDelegate(OnSocialInteraction));


Yes like that you can then check the event args for the actor, target and interaction used
Test Subject
Original Poster
#5 Old 4th Jul 2022 at 8:48 PM
Quote: Originally posted by Battery
Yes like that you can then check the event args for the actor, target and interaction used


Alright, I'm getting an error: not all code paths return a value. I tend to get these when making methods (I think that's the word for them) but I don't know how to fix it.
Space Pony
#6 Old 4th Jul 2022 at 8:51 PM
Quote: Originally posted by YolkSims
Alright, I'm getting an error: not all code paths return a value. I tend to get these when making methods (I think that's the word for them) but I don't know how to fix it.


i assume you are getting this in your OnSocialInteraction implementation.

if so you might want to use
Code:
return ListenerAction.Keep;

in that method

E: also it would be helpful if you could post the whole error message in the future (so we dont have to guess were the error stems from)
Test Subject
Original Poster
#7 Old 4th Jul 2022 at 8:54 PM
Thank you! That did it! What does that do?
Space Pony
#8 Old 4th Jul 2022 at 8:58 PM
Quote: Originally posted by YolkSims
Thank you! That did it! What does that do?


It means that you want to keep listening to future events if you only want to listen to the event once (or cancel listening on a certain condition) return ListenerAction.Remove instead
Forum Resident
#9 Old 4th Jul 2022 at 9:12 PM
Quck tip here: This event triggers for both sims that are involved. In many cases that's not really what you want.

So, it's good practice to cast the event as a "SocialEvent"

Code:
      protected static ListenerAction OnSocial(Event ev)
        {
            
            var e = ev as SocialEvent;


which gives you the very useful booleans

e.WasRecipient
e.WasAccepted

This way you can filter out double triggers and cases where a flirt was rejected for example.

Find my Mods: Here at MTS, over at Simlogical
Test Subject
Original Poster
#10 Old 4th Jul 2022 at 10:38 PM Last edited by YolkSims : 4th Jul 2022 at 11:42 PM.
Consort, how do I change this part of the code for that?

Edit: Nevermind, dumb question. Thanks guys. I was able to narrow it down and keep it from firing multiple times.
Back to top