Minecraft server auto restart with announce Topic is solved

Ask gaming related questions (AHK v1.1 and older)
asundrus
Posts: 11
Joined: 28 Apr 2020, 12:39

Minecraft server auto restart with announce

18 Feb 2021, 12:35

Hi.

I've been searching for a scrip that can restart my Minecraft server at set intervals ie. once every 2 hours, and 1 minute before restart, announce to the server that it's going to restart, and then one announce 10 seconds before restart.

I'm new at this Auto HotKey, so I would really hope that someone could help or point me in the right direction.
Last edited by asundrus on 06 Oct 2023, 06:31, edited 3 times in total.
asundrus
Posts: 11
Joined: 28 Apr 2020, 12:39

Re: [Solved]Minecraft server auto restart with announce

23 Feb 2021, 17:19

After some messups in hours to milliseconds, I finally fixed it myself:

Code: Select all

SetTitleMatchMode 2
WinActivate, mc-server
IfWinActive, mc-server
Loop 
		{
		Sleep, 60000
		ControlSend, ahk_parent, say restarting in 3 hours{Enter}, mc-server
		Sleep, 3600000
		ControlSend, ahk_parent, say restarting in 2 hours{Enter}, mc-server
		Sleep, 3600000
		ControlSend, ahk_parent, say restarting in 1 hour{Enter}, mc-server
		Sleep, 3000000
		ControlSend, ahk_parent, say restarting in 10 minutes{Enter}, mc-server
		Sleep, 540000
		ControlSend, ahk_parent, say restarting in 1 minute{Enter}, mc-server
		Sleep, 50000
		ControlSend, ahk_parent, say restarting in 10 seconds{Enter}, mc-server
		Sleep, 1000
		ControlSend, ahk_parent, say restarting in 9 seconds{Enter}, mc-server
		Sleep, 1000
		ControlSend, ahk_parent, say restarting in 8 seconds{Enter}, mc-server
		Sleep, 1000
		ControlSend, ahk_parent, say restarting in 7 seconds{Enter}, mc-server
		Sleep, 1000
		ControlSend, ahk_parent, say restarting in 6 seconds{Enter}, mc-server
		Sleep, 1000
		ControlSend, ahk_parent, say restarting in 5 seconds{Enter}, mc-server
		Sleep, 1000
		ControlSend, ahk_parent, say restarting in 4 seconds{Enter}, mc-server
		Sleep, 1000
		ControlSend, ahk_parent, say restarting in 3 seconds{Enter}, mc-server
		Sleep, 1000
		ControlSend, ahk_parent, say restarting in 2 seconds{Enter}, mc-server
		Sleep, 1000
		ControlSend, ahk_parent, say restarting in 1 seconds{Enter}, mc-server
		Sleep, 1000
		ControlSend, ahk_parent, say restarting...{Enter}, mc-server
		Sleep, 2000
		ControlSend, ahk_parent, stop{Enter}, mc-server
		}
asundrus
Posts: 11
Joined: 28 Apr 2020, 12:39

Re: [Solved]Minecraft server auto restart with announce

26 Aug 2023, 17:47

So I return, AHK Version 2 seems to have broken my scripts, just did a test and this was the result:

Code: Select all

Error: Function calls require a space or "(".  Use comma only between parameters.

Text:	ControlSend, ahk_parent, say restarting in 3 hours{Enter}, mc-server
Line:	8
File:	C:\Users\jt\Desktop\1.ahk

The program will exit.
What changed?
gregster
Posts: 9002
Joined: 30 Sep 2013, 06:48

Re: [Solved]Minecraft server auto restart with announce

26 Aug 2023, 17:58

asundrus wrote:
26 Aug 2023, 17:47
What changed?
Actually a lot. AHK v2 decided to do away with 20 years of backwards compatibility and to fundamentally update the syntax: https://www.autohotkey.com/docs/v2/v2-changes.htm

But you can install v1 and v2 side by side, if you like: https://www.autohotkey.com/docs/v2/Program.htm#install
Then you can still run old v1 scripts, and also run new v2 scripts, if you like. But mixing syntaxes won't work...
gregster
Posts: 9002
Joined: 30 Sep 2013, 06:48

Re: [Solved]Minecraft server auto restart with announce

26 Aug 2023, 18:13

Your script doesn't seem to have any trigger, like a hotkey - how do you determine that it "does nothing"?
If you don't get any (v2) error message, that is good at least.

Does that window mc-server really exist while you start the script? Otherwise, your script will never enter the loop.
How do you start the script? Without a hotkey, this looks less than ideal.

Edit: it seems the post I was answering to, was deleted in the meantime...
asundrus
Posts: 11
Joined: 28 Apr 2020, 12:39

Re: [Solved]Minecraft server auto restart with announce

27 Aug 2023, 08:24

Sorry, I deleted my post, forgot what I wrote, anyways, my bat file which used to work is looking like this:

Code: Select all

@echo off
cls
title mc-server
:start
java -Xmx4G -Xms1G -jar fabric-server-launch.jar nogui
cls

REM I recommend NOT using TIMEOUT /T for the main wait, this way you can skip it and initiate a restart immediately 

TIMEOUT 300

REM 3 hours minus 60 seconds to allow for 60 second restart notification

cls
echo server will restart
TIMEOUT /T 60
cls
goto :start
I start the server with my batfile, and the start the ahk script, it worked just fine back when I made it, that said, I'm far from pro at AHK, maybe I'm just missing some silly things.
asundrus
Posts: 11
Joined: 28 Apr 2020, 12:39

Re: Minecraft server auto restart with announce

06 Oct 2023, 06:35

Still at a lost, can't figure out what's going on, and I'm not using V2.
*EDIT*
So, it seems tha ahk_parent asin't no friend of mine, so I changed that with the ClassNN, sadly that's a long nmae, in my case:

Code: Select all

Windows.UI.Input.InputSite.WindowClass1
But ohh well, it worked.

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 83 guests