mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Add sample script with task (#1281)
This script shows how to run code periodically without using a thread.
This commit is contained in:
parent
2017d5d652
commit
9df255dd29
1 changed files with 32 additions and 0 deletions
32
MinecraftClient/config/sample-script-with-task.cs
Normal file
32
MinecraftClient/config/sample-script-with-task.cs
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
//MCCScript 1.0
|
||||||
|
|
||||||
|
MCC.LoadBot(new PeriodicTask());
|
||||||
|
|
||||||
|
//MCCScript Extensions
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The ChatBot API is not thread-safe so tasks must occur on the main thread.
|
||||||
|
/// This bot shows an example of running a task periodically without using threads.
|
||||||
|
/// </summary>
|
||||||
|
public class PeriodicTask : ChatBot
|
||||||
|
{
|
||||||
|
private DateTime nextTaskRun = DateTime.Now;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called on each MCC tick, around 10 times per second
|
||||||
|
/// </summary>
|
||||||
|
public override void Update()
|
||||||
|
{
|
||||||
|
DateTime dateNow = DateTime.Now;
|
||||||
|
if (nextTaskRun < dateNow)
|
||||||
|
{
|
||||||
|
LogDebugToConsole("Running task @ " + dateNow);
|
||||||
|
|
||||||
|
// Your task here
|
||||||
|
SendText("/ping");
|
||||||
|
|
||||||
|
// Schedule next run
|
||||||
|
nextTaskRun = dateNow.AddSeconds(60);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue