How to use GetUsername() in C# Script? #2294
-
Following the sample-script, I write a little script to execute /msg ID command.
I found Send() function cannot access the MCC.GetUsername(). So how to solve the problem? |
Beta Was this translation helpful? Give feedback.
Answered by
BruceChenQAQ
Oct 22, 2022
Replies: 1 comment 1 reply
-
You can write ChatBot scripts to call all ChatBot's APIs. (Save it as //MCCScript 1.0
/* This is a sample script that will load a ChatBot into Minecraft Console Client
* Simply execute the script once with /script or the script scheduler to load the bot */
MCC.LoadBot(new ExampleBot());
//MCCScript Extensions
/* The ChatBot class must be defined as an extension of the script in the Extensions section
* The class can override common methods from ChatBot.cs, take a look at MCC's source code */
public class ExampleBot : ChatBot
{
private const int SendLimit = 30;
private const bool IsAlways = false;
private const double SendInterval = 5.0; // second
private int Counter = 0, SendCnt = 0;
private void Send()
{
SendText("/msg " + GetUsername() + " AKFMsg");
}
public override void Initialize()
{
LogToConsole("ExampleBot Sucessfully Initialized!");
}
public override void Update()
{
if (IsAlways || SendCnt < SendLimit)
{
if (--Counter <= 0)
{
Counter = Settings.DoubleToTick(SendInterval);
++SendCnt;
Send();
}
}
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Sagittaro
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can write ChatBot scripts to call all ChatBot's APIs.
(Save it as
xx.cs
)