PDA

View Full Version : Social Interaction


Kitabalibar
5th Mar 2012, 12:19 PM
Hello,

I have successfully created some animations with object interaction, and I think there is a lot to do with it. But still, I have been requested quite a few times to create new interactions between Sims. And that is something I would love to do. But for now, I don't manage to create it.
So I looked at the few mods which do this, like Moar Interaction from Buzzler (especially the HelpwithHomework), and the Kolipoki Wand. But those two mods are pretty complex and massive, and hard to read for a beginner like me.
So I wrote a code, which of course does not work, but I would like to know which step I am missing
I know it has to do with the initialization because the interaction does not show up
Here is the code



namespace Sims3.Gameplay.Socializing.Oscar
{
public class MyInteraction
{
public static void AddInteractions(GameObject sim)
{
sim.AddInteraction(SlowDance.Singleton);
}


public class SlowDance : SocialInteraction
{


// Fields
public static readonly InteractionDefinition Singleton = new Definition();

// Methods
protected override bool Run()
{
Sim actor = base.Actor;
Sim target = base.Target;
base.Actor.SynchronizationLevel = Sim.SyncLevel.NotStarted;
base.Target.SynchronizationLevel = Sim.SyncLevel.NotStarted;
base.Target.InteractionQueue.CancelAllInteractions();
base.Actor.RouteTurnToFace(base.Target.Position);
base.AcquireStateMachine("StateDance");
base.SetActor("x", base.Actor);
base.SetActor("y", base.Target);
base.EnterSim("EnterDance");
base.AnimateSim("SlowDancing");
base.AnimateSim("Exit");
Simulator.Sleep(0x23);
AgingManager.Singleton.CancelAgingAlarmsForSim(base.Target);
Simulator.Sleep(0x41);
return true;
}

public bool TestFunction(IGameObject obj, object customData)
{
return !base.Autonomous;
}

// Nested Types
[DoesntRequireTuning]
public sealed class Definition : InteractionDefinition<Sim, Sim, SlowDance>
{
public string MenuText;

// Methods
protected override string GetInteractionName(Sim a, Sim target, InteractionObjectPair interaction)
{
return "Slow Dance";
}
public Definition(string text)
{
this.MenuText = string.Empty;
}

public Definition()
{
this.MenuText = string.Empty;
}

protected override void AddInteractions(InteractionObjectPair iop, Sim actor, Sim target, List<InteractionObjectPair> results)
{
results.Add(new InteractionObjectPair(new SlowDance.Definition("Slow Dance"), iop.Target));
}

protected override bool Test(Sim a, Sim target, bool isAutonomous, ref GreyedOutTooltipCallback greyedOutTooltipCallback)
{
return true;
}
}
}
}
}



Also I thought that the package file might need something else besides the dll and the clip of the animation..?

Buzzler
5th Mar 2012, 06:42 PM
You need to explicitly add your interaction to all sims. Have a look at the pure scripting tutorial under my profile to make the skeleton of a pure scripting mod. Then in your OnWorldLoaded method call something like this:
foreach (Sim sim in Sims3.Gameplay.Queries.GetObjects<Sim>())
{
AddInteractions(sim);
}
// and this to add the interaction to newly instantiated sims
EventTracker.AddListener(EventTypeId.kSimInstantiated, OnSimInstantiated);
With this callback method:private static ListenerAction OnSimInstantiated(Event e)
{
Sim sim = e.TargetObject as Sim;
if (sim != null)
{
AddInteractions(sim);
}
return ListenerAction.Keep;
}

BTW: Your AddInteractions method should look like this to avoid duplicate interactions:
private static void AddInteractions(Sim sim)
{
foreach (InteractionObjectPair iop in sim.Interactions)
{
if (iop.InteractionDefinition.GetType() == SlowDance.Singleton.GetType())
{
return;
}
}
sim.AddInteraction(SlowDance.Singleton);
}

Kitabalibar
6th Mar 2012, 02:54 AM
Thanks for the info
I've read your tuto as well on the wiki site, but it is still not showing up...
I also added the xml as the tutorial said (with the name OscarInteraction.MyInteraction


namespace OscarInteraction
{
public class MyInteraction
{
[Tunable]
protected static bool kInstantiator = false;

static MyInteraction()
{
World.OnWorldLoadFinishedEventHandler += new EventHandler(OnWorldLoadFinished);
}

private static void OnWorldLoadFinished(object sender, EventArgs e)
{
foreach (Sim sim in Sims3.Gameplay.Queries.GetObjects<Sim>())
{
AddInteractions(sim);
}
EventTracker.AddListener(EventTypeId.kSimInstantiated, OnSimInstantiated);
}

private static ListenerAction OnSimInstantiated(Event e)
{
Sim sim = e.TargetObject as Sim;
if (sim != null)
{
AddInteractions(sim);
}
return ListenerAction.Keep;
}

private static void AddInteractions(Sim sim)
{
foreach (InteractionObjectPair iop in sim.Interactions)
{
if (iop.InteractionDefinition.GetType() == SlowDance.Singleton.GetType())
{
return;
}
}
sim.AddInteraction(SlowDance.Singleton);
}

public class SlowDance : SocialInteraction
{
// Fields
public static readonly InteractionDefinition Singleton = new Definition();

// Methods
protected override bool Run()
{
// run not relevant here
return true;
}

public bool TestFunction(IGameObject obj, object customData)
{
return !base.Autonomous;
}

// Nested Types
[DoesntRequireTuning]
public sealed class Definition : InteractionDefinition<Sim, Sim, SlowDance>
{

// Methods
protected override string GetInteractionName(Sim a, Sim target, InteractionObjectPair interaction)
{
return "Slow Dance";
}

protected override bool Test(Sim a, Sim target, bool isAutonomous, ref GreyedOutTooltipCallback greyedOutTooltipCallback)
{
return true;
}
}
}
}
}

Buzzler
6th Mar 2012, 08:17 AM
Did you add [assembly: Tunable] to the project's AssemblyInfo.cs? If so, please attach your package and I'll have a look at it.

Kitabalibar
6th Mar 2012, 08:48 AM
Is there any particular place for the Assembly? I just need to compile it with the main file right? Anyway here is my upload, thanks for your help :)

Buzzler
6th Mar 2012, 09:48 AM
Is there any particular place for the Assembly? I just need to compile it with the main file right?The S3SA resource just has to be somewhere the game can find it. It can be in its own package no problem.

Your XML has the wrong type. It must be the 0x0333406C one. The rest looks ok, so I think that should be it.

Kitabalibar
6th Mar 2012, 10:05 AM
It works ! That's great, thanks a lot buzzler, you opened me new horizons :)