Need help with reading Minecraft chat
-
- Posts: 26
- Joined: 07 Jan 2021, 12:59
Need help with reading Minecraft chat
Hey, i want to read the Minecraft chat-logfile, however i dont know how to make a loop that reads the file and runs my script whenever "test" is in chat
The chatlog looks like this "12-09-2021 13:16:53 | [CHAT] Test"
The chatlog looks like this "12-09-2021 13:16:53 | [CHAT] Test"
Re: Need help with reading Minecraft chat
Code: Select all
::test::
FileRead, ttext, d:\temp2\test.log
MsgBox, 64, Log, %ttext%
Return
-
- Posts: 26
- Joined: 07 Jan 2021, 12:59
Re: Need help with reading Minecraft chat
Currently this is the output https://imgur.com/a/Rgsu3T4
Re: Need help with reading Minecraft chat
I imagine that the path to your log file is different than what is shown, so you should adjust line 2 accordingly.
-
- Posts: 26
- Joined: 07 Jan 2021, 12:59
Re: Need help with reading Minecraft chat
Sorry for my late answer, but i did change the location and still get this msgbox
Re: Need help with reading Minecraft chat
You can check to see whether the file exists.
If you get a null box rather than an error message, then the log is empty or has only white space or other invisible characters, or there might be a file access issue requiring admin rights or something of that sort.
Code: Select all
log = %A_ScriptDir%\test.log
::test::
If FileExist(log) {
FileRead, ttext, %log%
MsgBox, 64, Log, %ttext%
} Else MsgBox, 48, Error, Log file not found.`n`n%log%
Return
-
- Posts: 26
- Joined: 07 Jan 2021, 12:59
Re: Need help with reading Minecraft chat
Now it outputs the whole log file into a msgbox, i only need the last line
Re: Need help with reading Minecraft chat
Code: Select all
log = %A_ScriptDir%\test.log
::test::
If FileExist(log) {
FileRead, ttext, %log%
line := StrSplit(Trim(ttext, "`r`n"), "`n")
MsgBox, 64, Last line, % line[line.Count()]
} Else MsgBox, 48, Error, Log file not found.`n`n%log%
Return
-
- Posts: 26
- Joined: 07 Jan 2021, 12:59
Re: Need help with reading Minecraft chat
Okay that works, now i want that if in the output is "ExampleText" that it executes the script
is that possible?
is that possible?
Re: Need help with reading Minecraft chat
Code: Select all
log = %A_ScriptDir%\test.log
::test::
If !Instr(lastLine(log), "ExampleText")
Return
MsgBox, 64, Done, Done!
Return
lastLine(file) {
If FileExist(file) {
FileRead, ttext, %file%
line := StrSplit(Trim(ttext, "`r`n"), "`n")
Return line[line.Count()]
} Else MsgBox, 48, Error, File not found.`n`n%file%
}
-
- Posts: 26
- Joined: 07 Jan 2021, 12:59
Re: Need help with reading Minecraft chat
Works! Thank you
-
- Posts: 26
- Joined: 07 Jan 2021, 12:59
Re: Need help with reading Minecraft chat
but somehow if i loop the script it just doesnt run. i dont get any kind of error or smth else
-
- Posts: 26
- Joined: 07 Jan 2021, 12:59
Re: Need help with reading Minecraft chat
I've got this now
Code: Select all
#SingleInstance, force
loop {
log = C:\Users\garle\AppData\Roaming\.minecraft\logs\latest.log
If !Instr(lastLine(log), "Exampletext")
Return
msgbox done
Return
lastLine(file) {
If FileExist(file) {
FileRead, ttext, %file%
line := StrSplit(Trim(ttext, "`r`n"), "`n")
Return line[line.Count()]
}
}
}
Return
-
- Posts: 26
- Joined: 07 Jan 2021, 12:59
Re: Need help with reading Minecraft chat
found it out myself, forgot to remove a return
-
- Posts: 26
- Joined: 07 Jan 2021, 12:59
Re: Need help with reading Minecraft chat
but now the msgbox still appears even if the last line isnt "Exampletext"
Re: Need help with reading Minecraft chat
Feel free to post the log file as well as your revised script.
-
- Posts: 26
- Joined: 07 Jan 2021, 12:59
Re: Need help with reading Minecraft chat
I've got this code now,
the five mouseclicks should stop if "Exampletext2" is in the log file, i tried doing it but i dont know how to do it
the five mouseclicks should stop if "Exampletext2" is in the log file, i tried doing it but i dont know how to do it
Code: Select all
#SingleInstance, force
log = C:\Users\garle\AppData\Roaming\.minecraft\logs\latest.log
lastLine(file) {
If FileExist(file) {
FileRead, ttext, %file%
line := StrSplit(Trim(ttext, "`r`n"), "`n")
Return line[line.Count()]
} Else MsgBox, 48, Error, File not found.`n`n%file%
}
loop {
If Instr(lastLine(log), "Exampletext")
If (ErrorLevel = 0) {
Mouseclick , left, 1777, 900, 1, 0
Mouseclick , left, 1850, 900, 1, 0
Mouseclick , left, 1925, 900, 1, 0
Mouseclick , left, 2000, 900, 1, 0
Mouseclick , left, 2060, 900, 1, 0
}}
numpad3::ExitApp
Return
Re: Need help with reading Minecraft chat
I do not see any log file posted here. What are you trying to achieve with the ErrorLevel? Why would it stop for "Exampletext2" since that contains "Exampletext"?
-
- Posts: 26
- Joined: 07 Jan 2021, 12:59
Re: Need help with reading Minecraft chat
I'm Trying to make a script that searches for "Du durchwühlst den Mülleimer" if thats in chat, the script clicks on every slot of the GUI that opens ingame, and if it has clicked the right slot there's "Du hast etwas aus dem Mülleimer geholt" in chat, then the script should stop and search for the first one again
Re: Need help with reading Minecraft chat
Code: Select all
log = %A_AppData%\.minecraft\logs\latest.log
Loop {
Sleep, 200
If Instr(lastLine(log), "Du durchwühlst den Mülleimer")
For each, x in [1777, 1850, 1925, 2000, 2060] {
MouseClick,, x, 900
Sleep, 200
If Instr(lastLine(log), "Du hast etwas aus dem Mülleimer geholt")
Break
}
}
Numpad3::ExitApp
lastLine(file) {
If FileExist(file) {
FileRead, ttext, %file%
line := StrSplit(Trim(ttext, "`r`n"), "`n")
Return line[line.Count()]
} Else MsgBox, 48, Error, File not found.`n`n%file%
}