Replies: 10 (Who?), Viewed: 313 times.
Test Subject
Original Poster
#1 Old 9th May 2022 at 5:47 PM
Default Restricting interaction with skill level
Hi everyone!

I am starting this thread today because I want to refine my script mod that I created a few weeks ago with restricting the interaction I created with the skill level of my sims. (For example, that the interaction is only available at level 6 of the logic skill)

I've tried to find how to but didn’t find it for now...

Any help would be greatly appreciated!

Thanks for your reply,

P16
Advertisement
Field Researcher
#2 Old 9th May 2022 at 7:23 PM
You can do this by checking for a minimum skill level in your interaction's Test() method, like so:

Code:
public override bool Test(Sim actor, GameObject target, bool isAutonomous, ref GreyedOutTooltipCallback greyedOutTooltipCallback)
{
    return actor.SkillManager.HasElement(SkillNames.Logic) && actor.SkillManager.GetElement(SkillNames.Logic).SkillLevel >= 6;
}


In this example, any Sim who has at least level 6 in the Logic skill can access the interaction. Sims who are below this level or do not have the skill will not see the interaction in the pie menu. You can look at the Sims3.Gameplay.Skills.SkillNames enum for a full list of skills (including hidden ones) that you can check for.

"The Internet is the first thing that humanity has built that humanity doesn't understand, the largest experiment in anarchy that we have ever had." - Eric Schmidt

If you enjoy the mods I put out, consider supporting me on patreon: www.patreon.com/Gamefreak130
Test Subject
Original Poster
#3 Old 10th May 2022 at 2:51 AM
Quote:
Originally Posted by gamefreak130
You can do this by checking for a minimum skill level in your interaction's Test() method, like so:

Code:
public override bool Test(Sim actor, GameObject target, bool isAutonomous, ref GreyedOutTooltipCallback greyedOutTooltipCallback)
{
    return actor.SkillManager.HasElement(SkillNames.Logic) && actor.SkillManager.GetElement(SkillNames.Logic).SkillLevel >= 6;
}


In this example, any Sim who has at least level 6 in the Logic skill can access the interaction. Sims who are below this level or do not have the skill will not see the interaction in the pie menu. You can look at the Sims3.Gameplay.Skills.SkillNames enum for a full list of skills (including hidden ones) that you can check for.


Wow, thank you a lot gamefreak130! Again, you solved my problem that I searched for days!

If you can answer this other thing that I am searching for, you'll be my hero!

I am searching how to code to add an opportunity when I interact with something (For example, I want to name an Interaction ''Test'' and when I click on the interraction I want that a specific opportunity to be available for my sims) [Like a kind of a personnalize job board]


Thanks again for your time and knowledge,

P16
Field Researcher
#4 Old 10th May 2022 at 3:14 PM
Assuming you want to use an existing game opportunity, you can use this to prompt the opportunity dialog:

Code:
OpportunityNames opportunityName = OpportunityNames.Special_RestoreGhost; // Replace "Special_RestoreGhost" with whatever opportunity GUID you want
Actor.OpportunityManager.AddOpportunityNow(opportunityName, true, false);


Like with the skills, you can look at Sims3.Gameplay.Opportunities.OpportunityNames for a list of all the opportunity names. Many of them aren't very descriptive, so you may need to use a bit of trial and error to get the one you're looking for.

"The Internet is the first thing that humanity has built that humanity doesn't understand, the largest experiment in anarchy that we have ever had." - Eric Schmidt

If you enjoy the mods I put out, consider supporting me on patreon: www.patreon.com/Gamefreak130
Test Subject
Original Poster
#5 Old 11th May 2022 at 4:47 PM
Quote:
Originally Posted by gamefreak130
Assuming you want to use an existing game opportunity, you can use this to prompt the opportunity dialog:

Code:
OpportunityNames opportunityName = OpportunityNames.Special_RestoreGhost; // Replace "Special_RestoreGhost" with whatever opportunity GUID you want
Actor.OpportunityManager.AddOpportunityNow(opportunityName, true, false);


Like with the skills, you can look at Sims3.Gameplay.Opportunities.OpportunityNames for a list of all the opportunity names. Many of them aren't very descriptive, so you may need to use a bit of trial and error to get the one you're looking for.


It work, thanks! But not the way I expected...

At first I thought that adding a randomUtil to the code and add the interaction names to an enum would randomize the generated opportunities, but that's not the case... (Why can't it be that simple )

The problem that I get for now is that I want to have 4 different opportunities to be randomize when I click on the interaction and also to edit the Test class so the interaction won't show up when my sims doesn't have the require level or if the opportunity isn't available at the moment...

I've taken a look at your Check for Work mod and NonaGigPoster, but nothing seems to work.

Yes, I thought it would be a walk at the park to add this to my script mod!
Field Researcher
#6 Old 12th May 2022 at 1:47 AM
Quote:
Originally Posted by P16
It work, thanks! But not the way I expected...

At first I thought that adding a randomUtil to the code and add the interaction names to an enum would randomize the generated opportunities, but that's not the case... (Why can't it be that simple )

The problem that I get for now is that I want to have 4 different opportunities to be randomize when I click on the interaction and also to edit the Test class so the interaction won't show up when my sims doesn't have the require level or if the opportunity isn't available at the moment...

I've taken a look at your Check for Work mod and NonaGigPoster, but nothing seems to work.

Yes, I thought it would be a walk at the park to add this to my script mod!


Well, you can use Actor.OpportunityManager.IsOpportunityAvailable() to check whether the Sim meets the requirements for a given opportunity to appear, so you should be able to just check each of your four possible opportunities in your Test() method and return false if none of them are available. Then you can do something like this in your Run() method to get a random opportunity from the ones that are available:

Code:
OpportunityNames[] possibleOpps =
{
    OpportunityNames.Opportunity1,
    OpportunityNames.Opportunity2,
    OpportunityNames.Opportunity3,
    OpportunityNames.Opportunity4
};

OpportunityNames selectedOpp;
do
{
    selectedOpp = RandomUtil.GetRandomObjectFromList(possibleOpps);
}
while (Actor.OpportunityManager.IsOpportunityAvailable(selectedOpp));

Actor.OpportunityManager.AddOpportunityNow(selectedOpp, true, false);


There's almost certainly a better way to do this, but that should get you off the ground for now.

"The Internet is the first thing that humanity has built that humanity doesn't understand, the largest experiment in anarchy that we have ever had." - Eric Schmidt

If you enjoy the mods I put out, consider supporting me on patreon: www.patreon.com/Gamefreak130
Test Subject
Original Poster
#7 Old 12th May 2022 at 7:31 PM
Quote:
Originally Posted by gamefreak130
Well, you can use Actor.OpportunityManager.IsOpportunityAvailable() to check whether the Sim meets the requirements for a given opportunity to appear, so you should be able to just check each of your four possible opportunities in your Test() method and return false if none of them are available. Then you can do something like this in your Run() method to get a random opportunity from the ones that are available:

Code:
OpportunityNames[] possibleOpps =
{
    OpportunityNames.Opportunity1,
    OpportunityNames.Opportunity2,
    OpportunityNames.Opportunity3,
    OpportunityNames.Opportunity4
};

OpportunityNames selectedOpp;
do
{
    selectedOpp = RandomUtil.GetRandomObjectFromList(possibleOpps);
}
while (Actor.OpportunityManager.IsOpportunityAvailable(selectedOpp));

Actor.OpportunityManager.AddOpportunityNow(selectedOpp, true, false);


There's almost certainly a better way to do this, but that should get you off the ground for now.



I've tried the code and also tried editing it a little, but nothing happens when my Sims finished the interaction.
Field Researcher
#8 Old 12th May 2022 at 9:38 PM
Quote:
Originally Posted by P16
I've tried the code and also tried editing it a little, but nothing happens when my Sims finished the interaction.


Interesting. Would you mind posting the code or the package here so we can take a look?

"The Internet is the first thing that humanity has built that humanity doesn't understand, the largest experiment in anarchy that we have ever had." - Eric Schmidt

If you enjoy the mods I put out, consider supporting me on patreon: www.patreon.com/Gamefreak130
Test Subject
Original Poster
#9 Old 12th May 2022 at 9:56 PM
Quote:
Originally Posted by gamefreak130
Interesting. Would you mind posting the code or the package here so we can take a look?


Code:
protected override bool Test(Sim a, Computer target, bool isAutonomous, ref GreyedOutTooltipCallback greyedOutTooltipCallback)
            {
                a.OpportunityManager.IsOpportunityAvailable(OpportunityNames.EP6_DJTurntable_CompletedMiniShow_Bistro);
                a.OpportunityManager.IsOpportunityAvailable(OpportunityNames.EP6_DJTurntable_CompletedMiniShow_Hangout);
                a.OpportunityManager.IsOpportunityAvailable(OpportunityNames.EP6_DJTurntable_CompletedMiniShow_Private);
                a.OpportunityManager.IsOpportunityAvailable(OpportunityNames.EP6_DJTurntable_CompletedMiniShow_Park);
                return true;
            }


Edit: I've tried to return it false, but by doing so, the interaction would not show up in the game.

Code:
protected override bool Run()
        {
            base.StandardEntry();
            if (!this.Target.StartComputing(this, SurfaceHeight.Table, true))
            {
                base.StandardExit();
                return false;
            }
            this.Target.StartVideo(Computer.VideoType.Browse);
            TimedStage timedStage = new TimedStage(GetInteractionName(), 10f, true, true, true);
            base.Stages = new List<Stage>(new Stage[1] { timedStage });
            base.UpdateCaption = true;
            base.StartStages();
            base.BeginCommodityUpdates();
            base.AnimateSim("WorkTyping");
            bool flag = base.DoLoop(ExitReason.Default);
            base.EndCommodityUpdates(flag);
            this.Target.StopComputing(this, Computer.StopComputingAction.TurnOff, false);
            base.StandardExit();
            OpportunityNames[] possibleOpps =
            {
                OpportunityNames.EP6_DJTurntable_CompletedMiniShow_Bistro,
                OpportunityNames.EP6_DJTurntable_CompletedMiniShow_Hangout,
                OpportunityNames.EP6_DJTurntable_CompletedMiniShow_Private,
                OpportunityNames.EP6_DJTurntable_CompletedMiniShow_Park
            };

            OpportunityNames selectedOpp;
            do
            {
                selectedOpp = RandomUtil.GetRandomObjectFromList(possibleOpps);
            }
            while (Actor.OpportunityManager.IsOpportunityAvailable(selectedOpp));

            Actor.OpportunityManager.AddOpportunityNow(selectedOpp, true, false);
            return flag;
        }
Field Researcher
#10 Old 12th May 2022 at 10:34 PM Last edited by gamefreak130 : 13th May 2022 at 5:35 PM.
Oh, I'm dumb, it needs to loop while the opportunity is not available:

Code:
OpportunityNames selectedOpp;             
do
{                 
    selectedOpp = RandomUtil.GetRandomObjectFromList(possibleOpps);
}
while (!Actor.OpportunityManager.IsOpportunityAvailable(selectedOpp)); // Note the exclamation point


Also in your Test() method, you're running the availability check, but the results are being immediately discarded, which is why the "return false" is always removing the interaction. You need to explicitly compare the results of the availability check by doing something like:

Code:
protected override bool Test(Sim a, Computer target, bool isAutonomous, ref GreyedOutTooltipCallback greyedOutTooltipCallback)
{
    return a.OpportunityManager.IsOpportunityAvailable(OpportunityNames.EP6_DJTurntable_CompletedMiniShow_Bistro) ||
           a.OpportunityManager.IsOpportunityAvailable(OpportunityNames.EP6_DJTurntable_CompletedMiniShow_Hangout) ||
           a.OpportunityManager.IsOpportunityAvailable(OpportunityNames.EP6_DJTurntable_CompletedMiniShow_Private) ||
           a.OpportunityManager.IsOpportunityAvailable(OpportunityNames.EP6_DJTurntable_CompletedMiniShow_Park);
}


The "||" is an "OR" operator. This is basically saying "Run all four availability checks, return true if any of them are true, and return false if all of them are false." If you're interested, there's some more info on C# boolean operators here.

"The Internet is the first thing that humanity has built that humanity doesn't understand, the largest experiment in anarchy that we have ever had." - Eric Schmidt

If you enjoy the mods I put out, consider supporting me on patreon: www.patreon.com/Gamefreak130
Test Subject
Original Poster
#11 Old 12th May 2022 at 11:17 PM
Yeah, it works!

Thank you a lot for your help! You are officially my hero! :P

Thanks again for your time and for helping me improving my script modding skills! :D

P16
Back to top