Need help with reading Minecraft chat

Ask gaming related questions (AHK v1.1 and older)
CaptainArschbart
Posts: 26
Joined: 07 Jan 2021, 12:59

Need help with reading Minecraft chat

Post by CaptainArschbart » 16 Sep 2021, 11:02

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"

User avatar
mikeyww
Posts: 26591
Joined: 09 Sep 2014, 18:38

Re: Need help with reading Minecraft chat

Post by mikeyww » 16 Sep 2021, 16:50

Code: Select all

::test::
FileRead, ttext, d:\temp2\test.log
MsgBox, 64, Log, %ttext%
Return

CaptainArschbart
Posts: 26
Joined: 07 Jan 2021, 12:59

Re: Need help with reading Minecraft chat

Post by CaptainArschbart » 17 Sep 2021, 07:55

Currently this is the output https://imgur.com/a/Rgsu3T4

User avatar
mikeyww
Posts: 26591
Joined: 09 Sep 2014, 18:38

Re: Need help with reading Minecraft chat

Post by mikeyww » 17 Sep 2021, 18:31

I imagine that the path to your log file is different than what is shown, so you should adjust line 2 accordingly.

CaptainArschbart
Posts: 26
Joined: 07 Jan 2021, 12:59

Re: Need help with reading Minecraft chat

Post by CaptainArschbart » 23 Sep 2021, 08:48

Sorry for my late answer, but i did change the location and still get this msgbox

User avatar
mikeyww
Posts: 26591
Joined: 09 Sep 2014, 18:38

Re: Need help with reading Minecraft chat

Post by mikeyww » 23 Sep 2021, 08:59

You can check to see whether the file exists.

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
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.

CaptainArschbart
Posts: 26
Joined: 07 Jan 2021, 12:59

Re: Need help with reading Minecraft chat

Post by CaptainArschbart » 23 Sep 2021, 09:03

Now it outputs the whole log file into a msgbox, i only need the last line

User avatar
mikeyww
Posts: 26591
Joined: 09 Sep 2014, 18:38

Re: Need help with reading Minecraft chat

Post by mikeyww » 23 Sep 2021, 09:07

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

CaptainArschbart
Posts: 26
Joined: 07 Jan 2021, 12:59

Re: Need help with reading Minecraft chat

Post by CaptainArschbart » 23 Sep 2021, 09:22

Okay that works, now i want that if in the output is "ExampleText" that it executes the script
is that possible?

User avatar
mikeyww
Posts: 26591
Joined: 09 Sep 2014, 18:38

Re: Need help with reading Minecraft chat

Post by mikeyww » 23 Sep 2021, 09:42

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%
}

CaptainArschbart
Posts: 26
Joined: 07 Jan 2021, 12:59

Re: Need help with reading Minecraft chat

Post by CaptainArschbart » 23 Sep 2021, 10:39

Works! Thank you

CaptainArschbart
Posts: 26
Joined: 07 Jan 2021, 12:59

Re: Need help with reading Minecraft chat

Post by CaptainArschbart » 23 Sep 2021, 11:28

but somehow if i loop the script it just doesnt run. i dont get any kind of error or smth else

CaptainArschbart
Posts: 26
Joined: 07 Jan 2021, 12:59

Re: Need help with reading Minecraft chat

Post by CaptainArschbart » 23 Sep 2021, 11:33

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

CaptainArschbart
Posts: 26
Joined: 07 Jan 2021, 12:59

Re: Need help with reading Minecraft chat

Post by CaptainArschbart » 23 Sep 2021, 11:42

found it out myself, forgot to remove a return

CaptainArschbart
Posts: 26
Joined: 07 Jan 2021, 12:59

Re: Need help with reading Minecraft chat

Post by CaptainArschbart » 23 Sep 2021, 12:13

but now the msgbox still appears even if the last line isnt "Exampletext"

User avatar
mikeyww
Posts: 26591
Joined: 09 Sep 2014, 18:38

Re: Need help with reading Minecraft chat

Post by mikeyww » 23 Sep 2021, 12:40

Feel free to post the log file as well as your revised script.

CaptainArschbart
Posts: 26
Joined: 07 Jan 2021, 12:59

Re: Need help with reading Minecraft chat

Post by CaptainArschbart » 23 Sep 2021, 12:44

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 :D

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

User avatar
mikeyww
Posts: 26591
Joined: 09 Sep 2014, 18:38

Re: Need help with reading Minecraft chat

Post by mikeyww » 23 Sep 2021, 13:03

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"?

CaptainArschbart
Posts: 26
Joined: 07 Jan 2021, 12:59

Re: Need help with reading Minecraft chat

Post by CaptainArschbart » 23 Sep 2021, 13:16

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

User avatar
mikeyww
Posts: 26591
Joined: 09 Sep 2014, 18:38

Re: Need help with reading Minecraft chat

Post by mikeyww » 23 Sep 2021, 13:31

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%
}

Post Reply

Return to “Gaming Help (v1)”