Jump to content

Restarter


Shyke
 Share

Recommended Posts

I am sorry for making a second topic about the same thing but this is on a bit different basis.

I am wondering why the code below does'nt work as it should and I was hoping that some of you may be able to clean it up a bit and make it run more smoothly/correct it:

Dim $t
@SW_MINIMIZE
$pixel = PixelGetColor(105, 207)
HotKeySet("{ESC}", "Terminate")

MsgBox(0, "WoW Server Restarter", "Running WoW server and minimizing..." & @CRLF & "Read read-me for other credits and information!")

Call("Restart_WoW")

While 1
   $t = $t + 1
   If $t = 5 Then
      Call("Restart_WoW")
      $t = ""
   EndIf
   Sleep(1000)
WEnd

If Not ProcessExists ("wowemu.exe") Then
   Run("wowemu.exe")
else
      ProcessSetPriority ("wowemu.exe", 3)
      ProcessWait ("wowemu.exe")
      If $pixel = 16776960 Then
         ProcessClose ("wowemu.exe")
         Run("wowemu.exe")
else
         Call("Restart_WoW")
EndIf
EndIf

Func Restart_WoW()
   If Not ProcessExists ("wowemu.exe") Then
      Run("wowemu.exe", "", @SW_MINIMIZE)
   EndIf
   Sleep(1000)
EndFunc

Func Terminate()
    Exit 0
EndFunc

It's supposed to check to see if the pixel at 105, 207 inside the wowemu.exe window is decimal colored as 16776960 and if it is then restart wowemu.exe and if it isn't 16776960 then run a process that would, if it crashed by it's self restart the entire process over again.

Can anyone help me out because I know that there are alot of very nice people here. Once again I am sorry for making a second topic on the same thing except modifed so please don't smite me.

Edited by Shyke
Link to comment
Share on other sites

If Not ProcessExists ("wowemu.exe") Then
   Run("wowemu.exe")
else
      ProcessSetPriority ("wowemu.exe", 3)
      ProcessWait ("wowemu.exe")
      If $pixel = 16776960 Then
         ProcessClose ("wowemu.exe")
         Run("wowemu.exe")
else
         Call("Restart_WoW")
EndIf
EndIf

This block of code will never be executed because of the infinite While loop in front of it. Perhaps that's part of the problem?

@SW_MINIMIZE

What is that supposed to do? @SW_MINIMIZE is a macro used in GUI creation. It is never used on a line by itself, and your program doesn't have a GUI.

Link to comment
Share on other sites

@SW_MINIMIZE is a macro used in GUI creation. It is never used on a line by itself, and your program doesn't have a GUI.

<{POST_SNAPBACK}>

That's almost correct -- @SW_MINIMIZE is also used with Run(), RunWait() and WinSetState() and is therefore not limited to AutoIt-built GUIs.

Alright, I fixed those two things up, is there anything else that I screwed up/missed that would keep the program from working how I want it to?

Call() is only used when the function name resides in an AutoIt variable. You probably should replace your Call()s with:

Restart_WoW()
Link to comment
Share on other sites

So this:

Dim $t
$pixel = PixelGetColor(105, 207)
HotKeySet("{ESC}", "Terminate")

MsgBox(0, "WoW Server Restarter", "Running WoW server and minimizing..." & @CRLF & "Read read-me for other credits and information!")

While 1
   $t = $t + 1
   If $t = 5 Then
      Start_WoW()
      $t = ""
   EndIf
   Sleep(1000)
WEnd

Func Start_WoW()
If Not ProcessExists ("wowemu.exe") Then
   Run("wowemu.exe")
else
      ProcessSetPriority ("wowemu.exe", 3)
      ProcessWait ("wowemu.exe")
      If $pixel = 16776960 Then
         ProcessClose ("wowemu.exe")
         Run("wowemu.exe")
else
         Restart_WoW()
EndIf
EndIf
EndFunc

While 1
   $t = $t + 1
   If $t = 5 Then
      Restart_WoW()
      $t = ""
   EndIf
   Sleep(1000)
WEnd

Func Restart_WoW()
   If Not ProcessExists ("wowemu.exe") Then
      Run("wowemu.exe", "", @SW_MINIMIZE)
   EndIf
   Sleep(1000)
EndFunc

Func Terminate()
    Exit 0
EndFunc

Does this:?

Check to see if the pixel at 105, 207 inside the wowemu.exe window is decimal colored as 16776960 and if it is then restart wowemu.exe and if it isn't 16776960 then run a process that would, if it crashed by it's self restart the entire process over again.

Edited by Shyke
Link to comment
Share on other sites

So this:

Dim $t
$pixel = PixelGetColor(105, 207)
HotKeySet("{ESC}", "Terminate")

MsgBox(0, "WoW Server Restarter", "Running WoW server and minimizing..." & @CRLF & "Read read-me for other credits and information!")

While 1
   $t = $t + 1
   If $t = 5 Then
      Start_WoW()
      $t = ""
   EndIf
   Sleep(1000)
WEnd

Func Start_WoW()
If Not ProcessExists ("wowemu.exe") Then
   Run("wowemu.exe")
else
      ProcessSetPriority ("wowemu.exe", 3)
      ProcessWait ("wowemu.exe")
      If $pixel = 16776960 Then
         ProcessClose ("wowemu.exe")
         Run("wowemu.exe")
else
         Restart_WoW()
EndIf
EndIf
EndFunc

While 1
   $t = $t + 1
   If $t = 5 Then
      Restart_WoW()
      $t = ""
   EndIf
   Sleep(1000)
WEnd

Func Restart_WoW()
   If Not ProcessExists ("wowemu.exe") Then
      Run("wowemu.exe", "", @SW_MINIMIZE)
   EndIf
   Sleep(1000)
EndFunc

Func Terminate()
    Exit 0
EndFunc

Does this:?

<{POST_SNAPBACK}>

you could probably say better than anyone else if the script does what you intend it to...
Link to comment
Share on other sites

I fixed my code and added other stuff into it to balance out what my boss has added to the server...

Dim $t
$pixel = PixelGetColor(97, 92)
HotKeySet("{ESC}", "Terminate")

MsgBox(0, "WoW Server Restarter", "Running WoW server and minimizing..." & @CRLF & "Read read-me for other credits and information!")

Run ("loader_new.exe")

While 1
   $t = $t + 1
   If $t = 5 Then
      Start_WoW()
      $t = ""
   EndIf
   Sleep(1000)
WEnd

Func Start_WoW()
If ProcessExists ("wowemu.exe") Then
   ProcessClose ("loader_new.exe")
else
   sleep (2500)
   If Not ProcessExists ("wowemu.exe") Then
      Run ("loader_new.exe")
EndIf
EndIf

ProcessWait ("wowemu.exe")
WinActivate ("G:\EMU\wowemu.exe")
WinSetOnTop ("G:\EMU\wowemu.exe", "", 1)
WinMove("G:\EMU\wowemu.exe", "", 0, 0, 200, 200)
ProcessWait ("wowemu.exe")
   If $pixel = 16776960 Then
      ProcessClose ("wowemu.exe")
EndIf
         If ProcessExists ("loader_new.exe") Then
            ProcessClose ("loader_new.exe")
EndIf
EndFunc

Func Terminate()
    Exit 0
EndFunc

Now, that still doesn't work right and I don't know why... at the end parts:

WinActivate ("G:\EMU\wowemu.exe")
WinSetOnTop ("G:\EMU\wowemu.exe", "", 1)
WinMove("G:\EMU\wowemu.exe", "", 0, 0, 200, 200)
ProcessWait ("wowemu.exe")
   If $pixel = 16776960 Then
      ProcessClose ("wowemu.exe")
EndIf

That is where the program stops working... it is supposed to activate wowemu.exe, set it to top, move it to x=0 and y=0 then wait for all that to be done then proceed to checking the specified location done by a variable for the decimal color 16776960 and if it find its it there it is supposed to close wowemu.exe which basically starts the whole process over again until it works.

My problem is that it does not move the window for some reason.

Link to comment
Share on other sites

not sure... but maybe you need to wait a little (sleep) for each command and then do the pixel search

WinActivate ("G:\EMU\wowemu.exe")
WinWaitActive("")
Sleep(1000)
WinSetOnTop ("G:\EMU\wowemu.exe", "", 1)
Sleep(1000)
WinMove("G:\EMU\wowemu.exe", "", 0, 0, 200, 200)
Sleep(1000)
ProcessWait ("wowemu.exe")
$pixel = PixelGetColor(97, 92)
    If $pixel = 16776960 Then
        ProcessClose ("wowemu.exe")
    EndIf

just guessing

8)

NEWHeader1.png

Link to comment
Share on other sites

Here's my question.

While 1
   $t = $t + 1
   If $t = 5 Then
      Start_WoW()
      $t = ""
   EndIf
   Sleep(1000)
WEnd

Why?

If I'm reading that correctly.. you are basically putting in a 5 second sleep...

Why not just this..?

While 1
  Sleep(5000)
  Start_WoW()
WEnd

(Don't think this will Make It Work but, it's cleaner at least)

Also, try indenting properly. I thought you had two functions going at the end there.

*Edit: Hang on a sec... I think I found the problem. You're only checking the colour of the pixel at the very start of your code.

You need to move this line:

$pixel = PixelGetColor(97, 92)

Somewhere inside of your looped function.

*Edit2: Oops, looks like Valuator pointed that out already.

Edited by Saunders
Link to comment
Share on other sites

It still doesn't move or detect if there is color....

EDIT:

Also all of this section:

ProcessWait ("wowemu.exe")
WinActivate ("G:\EMU\wowemu.exe")
WinWaitActive ("G:\EMU\wowemu.exe")
Sleep(1000)
WinSetOnTop ("G:\EMU\wowemu.exe", "", 1)
Sleep(1000)
WinMove("G:\EMU\wowemu.exe", "", 0, 0, 200, 200)
ProcessWait ("wowemu.exe")

$pixel = PixelGetColor(97, 92)

If $pixel = 16776960 Then
   ProcessClose ("wowemu.exe")
EndIf
If ProcessExists ("loader_new.exe") Then
   ProcessClose ("loader_new.exe")
EndIf
EndFunc

Isn't working right.

Edited by Shyke
Link to comment
Share on other sites

Alright you guys I made some mock-up files so you can test too:

http://www.geocities.com/shykexmaster/MockUp.zip

And the current code for you to test with is:

HotKeySet("{ESC}", "Terminate")

MsgBox(0, "WoW Server Restarter", "Running WoW server and minimizing..." & @CRLF & "Read read-me for other credits and information!")

Run ("loader_new.exe")

While 1
  Sleep(2500)
  Start_WoW()
WEnd

Func Start_WoW()
If ProcessExists ("wowemu.exe") Then
   ProcessClose ("loader_new.exe")
else
sleep (1000)
If Not ProcessExists ("wowemu.exe") Then
      Run ("loader_new.exe")
EndIf
EndIf

ProcessWait ("wowemu.exe")
WinActivate ("C:\Documents and Settings\Shyke\Desktop\WoWemu.exe")
; WinActivate ("G:\EMU\wowemu.exe")
WinWaitActive ("C:\Documents and Settings\Shyke\Desktop\WoWemu.exe")
; WinWaitActive ("G:\EMU\wowemu.exe")
Sleep(1000)
WinSetOnTop ("C:\Documents and Settings\Shyke\Desktop\WoWemu.exe", "", 1)
; WinSetOnTop ("G:\EMU\wowemu.exe", "", 1)
Sleep(1000)
WinMove("C:\Documents and Settings\Shyke\Desktop\WoWemu.exe", "", 0, 0, 200, 200)
; WinMove("G:\EMU\wowemu.exe", "", 0, 0, 200, 200)
ProcessWait ("wowemu.exe")

$pixel = PixelGetColor(97, 98)

If $pixel = 16776960 Then
   ProcessClose ("wowemu.exe")
EndIf
If ProcessExists ("loader_new.exe") Then
   ProcessClose ("loader_new.exe")
EndIf
EndFunc

Func Terminate()
    Exit 0
EndFunc

Just change the titles and stuff.

Link to comment
Share on other sites

  • Moderators

Are you using the correct Opt("PixelCoordMode", "") at the top of your script?:

Opt("PixelCoordMode", 0) ; for window coordinates

Opt("PixelCoordMode", 1) ; for screen coordinates

Opt("PixelCoordMode", 2) ; for client coordinates

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

The main purpose of this script seems to be to read the information provided by one of the EXEs. Have you considered upgrading to the beta version and looking at the StdOutRead() function? This would most likely be a much cleaner way of doing things since it won't be necessary to keep the window on-top, in view etc.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...