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 27th Mar 2023 at 4:06 AM
Default Create an On/Off interaction & Alarm check every 15 minutes
Hello everyone,

I was working on a new mod and am struggling to find how to add an On/Off interaction like for the TV or the stereo object.

Also, I would like to know if it is possible to add an alarm check, say every 15 minutes, so if the temperature drops below 50 for example, that my interaction will reactivate.
For now, I've been able to work my way around with a listener so that every time my Sim changed room, my interaction refreshes, but I was asking myself if it will be possible to do it with an Alarm check so the check will be done automatically without having to change room.

Thanks for your help,

P16
Advertisement
Field Researcher
#2 Old 27th Mar 2023 at 5:55 AM
Here is an example of a alarm I would create with your criteria.
Code:
AlarmHandle handler = AlarmManager.Global.AddAlarm(15f, TimeUnit.Minutes, AlarmCallBack, "SomeName", AlarmType.AlwaysPersisted, null);
//15f and TimeUnit.Minutes is the time the alarm will take to trigger the function //AlarmCallBack is the name of the function you want triggered. //"SomeName" From the best of my understanding the string name that you write is not very important. //AlarmType.AlwaysPersisted makes it so the alarm continues whether the player saves or quits the game. And if you ever wish to remove the alarm. The code would be this.
Code:
AlarmManager.Global.RemoveAlarm(handler)
Test Subject
Original Poster
#3 Old 27th Mar 2023 at 3:16 PM Last edited by P16 : 27th Mar 2023 at 3:51 PM.
Thanks, but I don't get how it would check the temperature or how to implement it to my code...

Edit:
Thanks got it to work!
Test Subject
Original Poster
#4 Old 27th Mar 2023 at 4:45 PM Last edited by P16 : 28th Mar 2023 at 12:54 AM.
The only thing that I can't figure out is how to remove my alarm via a run method if I call it from another run method...? (Like one interaction will activate the alarm and the other will remove the alarm in the run section)

Also, if anyone knows how to create an on/off interaction it'll be really appreciated!
Field Researcher
#5 Old 29th Mar 2023 at 5:11 AM
Hey sorry for the delayed response. I haven't had much free time yesterday. Here is an example of adding an alarm and then removing the alarm. With this you can remove it via a different run method. Let me know if you have any questions. I did test this myself. So it should work.
Code:
 private static AlarmHandle mCheckForAlarmExample = AlarmHandle.kInvalidHandle;

        public static void ArmsDealReceivinAlarm(Sim sim)
        {
           mCheckForAlarmExample = AlarmManager.Global.AddAlarmDay(12f, DaysOfTheWeek.All, AlarmCallBack2, "ArmsDealReceiving Alarm", AlarmType.AlwaysPersisted, null);

           
        }

        public static void RemoveArmsDealReceivingAlarm(Sim sim)
        {

            AlarmManager.Global.RemoveAlarm(mCheckForAlarmExample);
        }
Also regarding your on/off interaction could you let me know what you are trying to do? Depending on what you are trying to do, I may be able to help.
Test Subject
Original Poster
#6 Old 29th Mar 2023 at 5:01 PM
Thank you it is now working like I imagined it! :D

For the turn on/off interaction, I mean that I would like to click on the interaction that is called for example ''Activate'' and that it runs the ''Activate'' run method. Then if I click again on the object, I would like to see the interaction named ''Activate'' replaced to ''Deactivate'' and if I run the interaction, it would run the ''Deactivate'' run method (just like when you click turn on TV and then turn it off if it is open).
Test Subject
Original Poster
#7 Old 31st Mar 2023 at 2:56 AM
After a few days of research and trials and errors, I finally found how to create an On/Off interaction.

Thanks again for your help!
Field Researcher
#8 Old 31st Mar 2023 at 7:04 AM
Glad to hear that you got everything working. Wish you the best for your project.
Test Subject
Original Poster
#9 Old 31st Mar 2023 at 9:14 PM
Well...
I've encountered another problem with my script. Would you know how to write the code so if I want to add a buff to my Sim, not only my sim will receive the buff, but everybody on the lot.
(For example I want to click on an object interaction and that every sim on the lot will acquire a specific buff).
I've tried to edit my code, but after several tries, only my active sim gacquire the buff.
Field Researcher
#10 Old 1st Apr 2023 at 3:04 AM
Maybe something like this would work.
Code:
//In your object class include 

private ulong sLotID;

// In your run method of your object. Assuming it is a immediate interaction. Include
 public override bool Run()
            {
            
                Target.sLotID = Target.LotCurrent.LotId;
                return true;
            }

//For good measure I would also include this.

public void OnExitBuildBuyMode()
        {
            sLotID = base.LotCurrent.LotId;
        }

//And then on your function

public static void ApplySpecificMoodlet(Sim sim)
{
var allsims = Sims3.Gameplay.Queries.GetObjects<Sim>();

foreach (var sim in allsims)
{
//This verifies whether sims are in the same lot as the object
if (sLotId == sim.LotCurrent.LotId)
{
//Function
}
}
}


I haven't tested this myself, but this is what comes to mind. Additionally, I had to review some of my old code from the Remove Shoes Indoors mod. I was such a swot at the time lol.
Test Subject
Original Poster
#11 Old 1st Apr 2023 at 3:44 PM
Wow! That worked! Again, thank you very much for your help!
Back to top