Closed Twi5TeD closed 5 years ago
Instead of public override Update()
use public override void Update()
as done in here
now i get
[MCC] [Script] Script 'rejoin.cs' failed to run (LoadError). [MCC] [Script] System.InvalidOperationException: Expected catch or finally
changed script to this now i get `//MCCScript 1.0
MCC.LoadBot(new RejoinHandler());
//MCCScript Extensions class RejoinHandler : ChatBot { System.Diagnostics.Stopwatch stopwatch; static int hours = 60 60 1000; int maxSessionLength = hours / 30; int reconnectTimeout = 2; string server = play.server.net; bool andReconnect = true; bool result = Settings.SetServerIP(server);
public override void AfterGameJoined()
{
LogToConsole("Rejoin handler loaded.");
stopwatch = new System.Diagnostics.Stopwatch();
stopwatch.Start();
}
public override void Update()
{
try
{
if (stopwatch.ElapsedMilliseconds > maxSessionLength)
{
LogToConsole("It's been " + maxSessionLength.ToString() + " milliseconds, attempting to relog to server.");
stopwatch.Restart();
if (result && andReconnect)
ReconnectToTheServer();
return result;
}
}
catch (Exception e)
{
LogToConsole("Something went wrong in Update method. " + e.ToString());
}
}
}`
[MCC] [Script] Script 'rejoin.cs' failed to run (LoadError). [MCC] [Script] System.InvalidOperationException: Since 'ScriptLoader.Script.RejoinHandler.Update()' returns void, a return keyword must not be followed by an object expression
Why do you try to return result;
in Update()
?
The error that you get is telling you the following:
your method Update()
doesn't declare a return type (that's the void
). However by using return result;
inside the method Update()
you attempt to return a bool
and thus C# is complaining.
Either remove return result;
(which is kinda pointless) or change the method to public override bool Update()
. Not sure if the second approach would even work, but you can simply test that out.
public override bool Update() this wouldnt work and i need it to return result how else could i do it?
Lets start with what do you want to achieve?
And why do you think you need bool result = Settings.SetServerIP(server);
?
so i want my list of alts to rejoin the server every couple hours but sometimes they wont connect so instead i want to restart the console client instead
Why would you even try to write a c# script for that? What you need and want is the Auto Relog Bot.
Inside your MinecraftClient.ini
put for example the following:
[AutoRelog]
enabled=true
delay=10
retries=-1 #-1 = unlimited
kickmessagesfile=kickmessages.txt
inside your kickmessages.txt
:
Connection has been lost
Server is restarting
Server is full
too many people
disconnect.spam
You seem to be logged in already.n
Internal Exception: java.io.IOException: An existing connection was forcibly closed by the remote host.
...
Or whatever kickmessages your server has. Search on google and youtube for tutorials full configuration examples (not really hard to find).
already have this but sometimes the alts just stay at the hub on rejoin does execute the commands i have in the anti afk part
Try adding a ScriptScheduler
or AutoRespond
ScriptScheduler
MinecraftClient.ini
[ScriptScheduler]
enabled=true
tasksfile=tasks.ini
tasks.ini
[Task]
triggerOnInterval=true
triggerOnFirstLogin=true
timeInterval=60
script=joinyourserver.txt
joinyourserver.txt
send /server [REALM]
AutoRespond
MinecraftClient.ini
[AutoRespond]
enabled=true
matchesfile=matches.ini
matches.ini
[Match]
match=--------------------[Hub]--------------------
actionother=script joinyourserver
# or simply actionother=send /server [REALM]
is there a placeholder to get the ign of the player so i can use matches.ini?
match=Welcome, %ign% to My Server!
[Match]
match=hi
action=send hi, $u!
actionprivate=send /tell $u Hello!
actionother=log detected "hi" message
ownersonly=false
As a response has been given, I'll close this thread. Feel free to reopen if you still need help.
`//MCCScript 1.0
MCC.LoadBot(new RejoinHandler());
//MCCScript Extensions class RejoinHandler : ChatBot { System.Diagnostics.Stopwatch stopwatch; static int hours = 60 60 1000; int maxSessionLength = hours / 30; int reconnectTimeout = 2; string server = play.server.net; bool andReconnect = true; bool result = Settings.SetServerIP(server);
}`
this is the script that i want to do it will reconnect every alt back every 60 seconds(just for testing atm) but the error i get is [MCC] [Script] Script 'rejoin.cs' failed to run (LoadError). [MCC] [Script] System.InvalidOperationException: Method must have a return type