Sign in to follow this  
Followers 0
CapsAdmin

My script is doing an infinite loop

19 posts in this topic

ProcessClose("srcds.exe")
WinKill("CapsAdmin's Wiremod Server")
Run("C:\Program Files\Valve\Server\orangebox\srcds.exe")

do
    WinSetOnTop("Start Dedicated Server", "", 1)
    WinWait("Start Dedicated Server")
    WinActivate("Start Dedicated Server")
    WinWaitActive("Start Dedicated Server")
    Send("{ENTER}")
until WinExists("Start Dedicated server") = WinActivate("Start Dedicated Server")

This is my first script so please be nitpicky.

What's wrong here?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I'd rather do it this way:

ProcessClose("srcds.exe")
WinKill("CapsAdmin's Wiremod Server")
$PID = Run("C:\Program Files\Valve\Server\orangebox\srcds.exe")

Do
  If @error <> 0 Then ;Do something  
  Sleep(500)
Until ProcessExists($PID)

To be a bit more nitpicky:

- To have a good script you should have error handling.

Edit: nitpicky

Edited by DMEE

In the beginning there was nothing and then even that exploded - anonymous

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I'm a little confused here. It doesn't do what my script does I think.

Edit:

What I want my script to do is to

1. Kill srcds if it's already open

2. Open srcds

3. Bring srcds to the front

4. Press enter

5. Terminate the script.

My script does all that but it doesn't terminate the script. So if I try to start srcds again, it creates 2 servers.

Edited by CapsAdmin

Share this post


Link to post
Share on other sites

why did you place it in a Do Loop?


In the beginning there was nothing and then even that exploded - anonymous

Share this post


Link to post
Share on other sites

Becuase I wanted it to loop until it starts the server.

Like If I'm doing something the window will appear in the background and thus enter won't work until it's on top.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

ProcessClose("srcds.exe")
WinKill("CapsAdmin's Wiremod Server")
$PID = Run("C:\Program Files\Valve\Server\orangebox\srcds.exe")

Do
  If @error <> 0 Then ;Do something 
  Sleep(500)
Until ProcessExists($PID)

At this point we are sure that the server does work

Then we want to send it a command: Enter.

The best we can do is send the command to the control directly, then the window does not have to be on top.

You can find the control info using the au3info.exe for example.

So we add:

ControlClick("Start Dedicated Server", "", "[CLASSNN:......]")

This way you are not dependent on the active state of the window and it is more reliable for that reason

Edited by DMEE

In the beginning there was nothing and then even that exploded - anonymous

Share this post


Link to post
Share on other sites

The gui it uses is different so it won't work. I've tried.

Posted Image

Share this post


Link to post
Share on other sites

Can you show the info given by au3info.exe


In the beginning there was nothing and then even that exploded - anonymous

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

>>>> Window <<<<
Title:  Start Dedicated Server
Class:  Surface
Position:   270, 446
Size:   310, 360
Style:  0x960A0000
ExStyle:    0x00000000
Handle: 0x00E0069C

>>>> Control <<<<
Class:  
Instance:   
ClassnameNN:    
Advanced (Class):   
ID: 
Text:   
Position:   
Size:   
ControlClick Coords:    
Style:  
ExStyle:    
Handle: 0x0002017C

>>>> Mouse <<<<
Position:   442, 778
Cursor ID:  0
Color:  0x4C5844

>>>> StatusBar <<<<

>>>> Visible Text <<<<


>>>> Hidden Text <<<<

It just doesn't work. When hovering over srcds's start button the control thing is blank.

Edited by CapsAdmin

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Opt("MouseCoordMode", 1)
Opt("CaretCoordMode", 1)

$hServer = _WinAPI_FindWindow("Surface", "")
$xy = WinGetPos($hServer)

If @error = 0 Then
; window does not exist
ElseIf @error < 0 Then
  WinSetState ($hServer, "", @SW_MAXIMIZE )
Endif

MouseClick("left", $xy[0]+442, $xy[1]+778, 1)  

; readjust the opts if you need to e.g.
  Opt("MouseCoordMode", 2)
  Opt("CaretCoordMode", 2)

I do hope that this works

Edited by DMEE

In the beginning there was nothing and then even that exploded - anonymous

Share this post


Link to post
Share on other sites

I'm not sure what that does, nor do I know where to put it.

Sorry, I'm very new to this.

I see some mouse stuff there. Isn't is easier to send the window on top and press enter?

Share this post


Link to post
Share on other sites

#include <Winapi.au3>

;Opt("MouseCoordMode", 1) ; needed to set absolute position of the window
;Opt("CaretCoordMode", 1)

ProcessClose("srcds.exe")
WinKill("CapsAdmin's Wiremod Server")
$PID = Run("C:\Program Files\Valve\Server\orangebox\srcds.exe")

Do
  If @error <> 0 Then $a=1 ;Do something 
  Sleep(500)
Until ProcessExists($PID)

; find the handle to the window see the manual for the proper use
$hServer = _WinAPI_FindWindow("Surface", "")

; $xy = WinGetPos($hServer) ; find the position of the window, only needed for the mouse action

If @error = 0 Then
; window does not exist
ElseIf @error < 0 Then ; the window is minimized
  WinSetState ($hServer, "", @SW_MAXIMIZE ) 
Endif

; click the button (left click, absolute position by giving the window position + the position within the window)
; MouseClick("left", $xy[0]+442, $xy[1]+778, 1) 

; Just send enter as you correctly noticed
Send("{ENTER}")

I hope this works and that you get the comment, otherwise just ask


In the beginning there was nothing and then even that exploded - anonymous

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

It doesn't seem to press enter.

Edit:

I think you need to insert a winwaitactive.

Edit:

Yeah it seems to work if I put "WinWaitActive("Start Dedicated Server")" before the enter.

But it still doesn't bring the window up if it's in the background.

Edited by CapsAdmin

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

I've made it so it brings the window up if it's in the background.

Thanks a lot.

#include <Winapi.au3>

ProcessClose("srcds.exe")
WinKill("CapsAdmin's Wiremod Server")
$PID = Run("C:\Program Files\Valve\Server\orangebox\srcds.exe")
Do
  If @error <> 0 Then $a=1 
  Sleep(500)
Until ProcessExists($PID)

$hServer = _WinAPI_FindWindow("Surface", "")

If @error = 0 Then

ElseIf @error < 0 Then 
  WinSetState ($hServer, "", @SW_MAXIMIZE ) 
Endif

WinSetOnTop("Start Dedicated Server", "", 1)
WinActivate("Start Dedicated Server")
WinWaitActive("Start Dedicated Server")
Send("{ENTER}")

Edit:

Hold on. It doesn't open srcds when it's compiled. :S

Edited by CapsAdmin

Share this post


Link to post
Share on other sites

I used to play GMod, and I've even ran my own Dedicated Server for a few years too. I'd say, use the -console switch on the server, it removes the "Start Dedicated Server" dialog, and starts the server directly instead, and gives you only a console window for the game(most, if not all ppl. run the source/gold source dedicated servers this way).

basically, just change your

$PID = Run("C:\Program Files\Valve\Server\orangebox\srcds.exe")

To

$PID = Run("C:\Program Files\Valve\Server\orangebox\srcds.exe -console")

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

I know this and I hate the console.

I'm using the GUI version because the DOS console is terrible to work with. I spend time with the console equally as much as I spend time in game. I need to copy paste stuff from the console. (debugging scripts)

Edit:

I figured it out. If it was named srcds it wouldn't work. I just renamed it to something else.

Edited by CapsAdmin

Share this post


Link to post
Share on other sites

That can easily be done, by enabling the Quick Edit feature for console windows(windows setting), then you can select the text you want with just one click and drag.

Also, for automation purposes, the console is easier to work with.

Anyways, whatever floats your boat. muttley

Share this post


Link to post
Share on other sites

That can easily be done, by enabling the Quick Edit feature for console windows(windows setting), then you can select the text you want with just one click and drag.

Also, for automation purposes, the console is easier to work with.

Anyways, whatever floats your boat. muttley

The server freezes up when you're in edit mode.

It also freezes up when you scroll.

Share this post


Link to post
Share on other sites

It freezes when you scroll? I never noticed that.. hmm. Though it's unfortunate that it freezes when you select text, but if you're in quick select mode, it only freezes from the point where you start to select, and to the point you copy, which is usually not very long.

But as said, whatever floats the boat for you. muttley I personally prefer the console over the bulky gui though.

Share this post


Link to post
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
Sign in to follow this  
Followers 0