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.
Minecraft server auto restart with announce Topic is solved
Minecraft server auto restart with announce
Last edited by asundrus on 06 Oct 2023, 06:31, edited 3 times in total.
Re: [Solved]Minecraft server auto restart with announce
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
}
Re: [Solved]Minecraft server auto restart with announce
So I return, AHK Version 2 seems to have broken my scripts, just did a test and this was the result:
What changed?
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.
Re: [Solved]Minecraft server auto restart with announce
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...
Re: [Solved]Minecraft server auto restart with announce
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...
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...
Re: [Solved]Minecraft server auto restart with announce
Sorry, I deleted my post, forgot what I wrote, anyways, my bat file which used to work is looking like this:
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.
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
Re: Minecraft server auto restart with announce
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:
But ohh well, it worked.
*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
Who is online
Users browsing this forum: No registered users and 83 guests