Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Idea] Script Alarm Bot #2800

Open
3 tasks done
farfromsubtlee opened this issue Oct 1, 2024 · 1 comment
Open
3 tasks done

[Idea] Script Alarm Bot #2800

farfromsubtlee opened this issue Oct 1, 2024 · 1 comment
Labels
a:enhancement Request for improvement of an existing feature a:new-feature Request for a new feature

Comments

@farfromsubtlee
Copy link

Prerequisites

Console Client Version

Latest

Describe your problem

Hello, I looked a little bit including closed topics, but I couldn't see a script that will detect in-game time. Is this possible?
What I want to do is “send me a private message when the in-game time is 12:00”. It would be correct to call it an alarm.

Suggest a possible solution

Since I don't know any command or coding to detect an in-game clock like timeValue setting, maybe it can be handled with .cs.

Attach screenshot here (If applicable)

No response

Minecraft Version

1.16.5 / 1.20.4

Device

Desktop

Operating System

Windows

@farfromsubtlee farfromsubtlee added a:enhancement Request for improvement of an existing feature a:new-feature Request for a new feature labels Oct 1, 2024
@milutinke
Copy link
Member

Here is an example that I made for someone else on Discord a couple of months ago, you can modify it for your needs.

// 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("sleep");

                // 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 *= -1;

        time %= 24000;

        var hours = 6 + (int)(time / 1000);

        if (hours >= 24) 
            hours -= 24;

        double minutesDouble = (double)(time % 1000) / 1000 * 60;
        int minutes = (int)Math.Round(minutesDouble);

        if (minutes == 60)
        {
            minutes = 0;
            hours++;
        }

        return (hours, minutes);
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:enhancement Request for improvement of an existing feature a:new-feature Request for a new feature
Projects
None yet
Development

No branches or pull requests

2 participants