-
I need a script for chat bot to automatically sleep at a certain time so that it can be executed in MCC.thank you |
Beta Was this translation helpful? Give feedback.
Answered by
milutinke
Mar 9, 2024
Replies: 1 comment 13 replies
-
You can use the Script Scheduler chat bot to run the For an example: [[ChatBot.ScriptScheduler.TaskList]]
Task_Name = "Sleep"
Trigger_On_First_Login = false
Trigger_On_Login = false
Trigger_On_Times = { Enable = true, Times = [ 19:00:00, ] }
Trigger_On_Interval = { Enable = false, MinTime = 3.6, MaxTime = 4.8 }
Action = "bed sleep 50" PS: This is for real world time. For in-game time you could use something like this: //MCCScript 1.0
MCC.LoadBot(new CheckForSleep());
//MCCScript Extensions
public class CheckForSleep : ChatBot
{
private DateTime nextTaskRun = DateTime.Now;
private long timeOfDay;
public override void OnTimeUpdate(long worldAge, long timeOfDay)
{
this.timeOfDay = timeOfDay;
}
public override void Update()
{
var dateNow = DateTime.Now;
if (nextTaskRun < dateNow)
{
var (hours, minutes) = GetCurrentInGameTime();
if (hours == 22)
{
PerformInternalCommand("bed 50");
// Schedule next check to run in 15 minutes
nextTaskRun = dateNow.AddMinutes(15);
return;
}
// Schedule next check to run in 1 minute
nextTaskRun = dateNow.AddMinutes(1);
}
}
private (int hours, int minutes) GetCurrentInGameTime()
{
var time = this.timeOfDay;
if (time < 0)
time = time * -1;
time = time % 24000;
var hours = 6 + (int)(time / 1000);
if (hours >= 24)
hours -= 24;
var minutesDouble = (double)time % 1000;
minutesDouble = (minutesDouble / 1000) * 60;
int minutes = (int)Math.Round(minutesDouble);
if (minutes == 60)
{
minutes = 0;
hours++;
}
return (hours, minutes);
}
} |
Beta Was this translation helpful? Give feedback.
13 replies
Answer selected by
Sage4483
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use the Script Scheduler chat bot to run the
bed
commandFor an example:
PS: This is for real world time.
For in-game time you could use something like this: