AutoHotkey Community

It is currently May 26th, 2012, 3:41 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 15 posts ] 
Author Message
PostPosted: March 18th, 2009, 12:27 am 
Offline

Joined: March 5th, 2009, 2:21 am
Posts: 68
Location: Chuckey, Tn.
I have written a script to interface with a dos command window that I call the Halo server window. This server window allows you to enter dos commands to change or display values in a Halo dedicated server game play. The default commands to start the server window are stored in the init.txt file located in the Halo Server directory.
This is the contents of the init.txt file. The sv_commands on the left are the actual commands the server window uses to change the values to the right of the sv_command. For instance the sv_name(Server Name) command in the first line has a value of Halo_DS.
Code:
sv_name Halo_DS
sv_public 1
sv_maxplayers 12
sv_password halo
sv_mapcycle_add bloodgulch "Done Slayer"
sv_mapcycle_add timberland "team king"
sv_mapcycle_add damnation "team slayer"
sv_mapcycle_add dangercanyon ctf
sv_mapcycle_add carousel slayer
sv_mapcycle_add gephyrophobia slayer
sv_mapcycle_add infinity "classic rockets"
sv_mapcycle_begin
sv_rcon_password test

These sv_commands are entered by typing the text in the dos command prompt in the server window. By clicking on the buttons from my Gui window in my script the sv_command is entered in for me. All that is left then is to enter the actual value you wish to change and pressing enter to finish the command. After I click on one of my buttons to enter the sv_command and enter the command value the server window tells me it has accepted the value correctly.
Example: I click on the Server Name button from my Gui window to change the name of my server and it displays the change correctly.
My problem is this. The sv_command values I enter are not save in the init.txt file. So the next time I want to run the server it displays the old value of the server name - sv_name Halo_DS as shown above in the init.txt file.

This is my script to interface with the server window.
Code:
#NoEnv
#InstallKeybdHook
#InstallMouseHook

SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

#usehook

DetectHiddenWindows, On

Run Haloded.exe

Gui, Default
Menu, FileMenu, Add, &Edit Init File, MenuFileEdit  ; See remarks below about Ctrl+O.
Menu, FileMenu, Add, E&xit, MenuHandler
Menu, HelpMenu, Add, &About, MenuHandler
Menu, MyMenuBar, Add, &File, :FileMenu  ; Attach the two sub-menus that were created above.
Menu, MyMenuBar, Add, &Help, :HelpMenu
Gui, Menu, MyMenuBar
Gui, Font, S14 CBlue Bold, Verdana
Gui, Add, Text, x16 y10 w210 h30 +Center, Halo GUI Server
Gui, Font, S9 Cmaroon Bold, Verdana
Gui, Add, GroupBox, x6 y40 w110 h190 vServerControl, Server Control
Gui, Add, Groupbox, x121 y40 w110 h190 vMapControl, Map Control
Gui, Add, GroupBox, x6 y235 w225 h150 vPlayerControl, Player Control
Gui, Font
Gui, Add, Button, Group x11 y65 w100 h20 gClearScreen, Clear Screen
Gui, Add, Button, x11 y85 w100 h20 gServerName vServerName, Server Name
Gui, Add, Button, x11 y105 w100 h20 gServerPassword vServerPassword, Server Password
Gui, Add, Button, x11 y125 w100 h20 gPublicServer vPublicServer, Public Server
Gui, Add, Button, x11 y145 w100 h20 gRconPassword vRconPassword, Rcon Password
Gui, Add, Button, x11 y165 w100 h20 gServerStatus, Server Status
Gui, Add, Button, x11 y185 w100 h20 gEndGame, End Game
Gui, Add, Button, x11 y205 w100 h20 gQuit, Quit
Gui, Add, Button, Group x126 y65 w100 h20 gStartMapcycle, Start Mapcycle
Gui, Add, Button, x126 y85 w100 h20 gCurrentMaps, Current Maps
Gui, Add, Button, x126 y105 w100 h20 gAddMap vAddMap, Add Map
Gui, Add, Button, x126 y125 w100 h20 gDeleteMap, Delete Map
Gui, Add, Button, x126 y145 w100 h20 gNextMap, Next Map
Gui, Add, Button, x126 y165 w100 h20 gChooseMap, Choose Map
Gui, Add, Button, x126 y185 w100 h20 gResetMap, Restart Map
Gui, Add, Button, x126 y205 w100 h20 gMapcycleTime vMapcycleTime, Mapcycle Timeout
Gui, Add, Button, Group x11 y260 w100 h20 gShowPlayers, Show Players
Gui, Add, Button, x11 y280 w100 h20 gKickPlayer, Kick Player
Gui, Add, Button, x11 y300 w100 h20 gBanPlayer, Ban player
Gui, Add, Button, x11 y320 w100 h20 gUnbanPlayer, Unban Player
Gui, Add, Button, x11 y340 w100 h20 gBanList, Ban List
Gui, Add, Button, x11 y360 w100 h20 gBanlistFile, Ban List File
Gui, Add, Button, x126 y260 w100 h20 gMaxPlayers vMaxPlayers, Maximum Players
Gui, Add, Button, x126 y280 w100 h20 gTeamKillingPoint vTeamKillingPoint, Team Kill Point
Gui, Add, Button, x126 y300 w100 h20 gTeamKillPentalty vTeamKillPentalty, Team Kill Pentalty
Gui, Add, Button, x126 y320 w100 h20 gTeamKillGrace vTeamKillGrace, Team Kill Grace
Gui, Add, Button, x126 y340 w100 h20 gTeamKillCooldown vTeamKillCooldown, Team Kill Cooldown
Gui, Show, x770 h390 w235, Dedicated Server
Return

MenuFileEdit:
Return

MenuHandler:
Return

ClearScreen:
Sleep 200
WinActivate Halo Console
Sleep 200
SendPlay, cls
Sleep 500
SendPlay, {Enter}
Gui, Show, Dedicated Server
Return

ServerName:
Sleep 200
WinActivate Halo Console
Sleep 200
SendPlay, sv{SHIFTDOWN}-{SHIFTUP}name{Space}
Sleep 500
KeyWait, Enter,d
Gui, Show, Dedicated Server
Return

ServerPassword:
Sleep 200
WinActivate Halo Console
Sleep 200
SendPlay, sv{SHIFTDOWN}-{SHIFTUP}password{Space}
Sleep 500
KeyWait, Enter,d
Gui, Show, Dedicated Server
Return

PublicServer:
Sleep 200
WinActivate Halo Console
Sleep 200
SendPlay, sv{SHIFTDOWN}-{SHIFTUP}public{Space}
Sleep 500
KeyWait, Enter,d
Gui, Show, Dedicated Server
Return

RconPassword:
Sleep 200
WinActivate Halo Console
Sleep 200
SendPlay, sv{SHIFTDOWN}-{SHIFTUP}rcon{SHIFTDOWN}-{SHIFTUP}password{Space}
Sleep 500
KeyWait, Enter,d
Gui, Show, Dedicated Server
Return

ServerStatus:
Sleep 200
WinActivate Halo Console
Sleep 200
SendPlay, sv{SHIFTDOWN}-{SHIFTUP}status{Space}
Sleep 500
KeyWait, Enter,d
Gui, Show, Dedicated Server
Return

EndGame:
Sleep 200
WinActivate Halo Console
Sleep 200
SendPlay, sv{SHIFTDOWN}-{SHIFTUP}end{SHIFTDOWN}-{SHIFTUP}game{Enter}
Sleep 500
Gui, Show, Dedicated Server
Return

Quit:
Sleep 200
WinActivate Halo Console
Sleep 200
SendPlay, quit{Enter}
WinWaitClose Halo Console
ExitApp
Return

StartMapcycle:
Sleep 200
WinActivate Halo Console
Sleep 200
SendPlay, sv{SHIFTDOWN}-{SHIFTUP}mapcycle_begin
Sleep 500
SendPlay, {Enter}
Gui, Show, Dedicated Server
Return

CurrentMaps:
Sleep 200
WinActivate Halo Console
Sleep 200
SendPlay, sv{SHIFTDOWN}-{SHIFTUP}mapcycle
Sleep 500
SendPlay, {Enter}
Gui, Show, Dedicated Server
Return

AddMap:
Sleep 200
WinActivate Halo Console
Sleep 200
SendPlay, sv{SHIFTDOWN}-{SHIFTUP}maplist
Sleep 500
SendPlay, {Enter}
Sleep 500
SendPlay, sv{SHIFTDOWN}-{SHIFTUP}mapcycle_add{Space}
KeyWait, Enter,d
Gui, Show, Dedicated Server
Return

DeleteMap:
Sleep 200
WinActivate Halo Console
Sleep 200
SendPlay, sv{SHIFTDOWN}-{SHIFTUP}mapcycle
Sleep 500
SendPlay, {Enter}
Sleep 500
SendPlay, sv{SHIFTDOWN}-{SHIFTUP}mapcycle_del{Space}
KeyWait, Enter,d
Gui, Show, Dedicated Server
Return

NextMap:
Sleep 200
WinActivate Halo Console
Sleep 200
SendPlay, sv{SHIFTDOWN}-{SHIFTUP}map_next
Sleep 500
SendPlay, {Enter}
Gui, Show, Dedicated Server
Return

ChooseMap:
Sleep 200
WinActivate Halo Console
Sleep 200
SendPlay, sv{SHIFTDOWN}-{SHIFTUP}mapcycle
Sleep 500
SendPlay, {Enter}
Sleep 500
SendPlay, sv{SHIFTDOWN}-{SHIFTUP}map{Space}
KeyWait, Enter,d
Gui, Show, Dedicated Server
Return

ResetMap:
Sleep 200
WinActivate Halo Console
Sleep 200
SendPlay, sv{SHIFTDOWN}-{SHIFTUP}map_reset
Sleep 500
SendPlay, {Enter}
Gui, Show, Dedicated Server
Return

MapcycleTime:
Sleep 200
WinActivate Halo Console
Sleep 200
SendPlay, sv{SHIFTDOWN}-{SHIFTUP}mapcycle_timeout{Space}
Sleep 500
KeyWait, Enter,d
Gui, Show, Dedicated Server
Return

ShowPlayers:
Sleep 200
WinActivate Halo Console
Sleep 200
SendPlay, sv{SHIFTDOWN}-{SHIFTUP}players
Sleep 500
SendPlay {Enter}
Gui, Show, Dedicated Server
Return

KickPlayer:
Sleep 200
WinActivate Halo Console
Sleep 200
SendPlay, sv{SHIFTDOWN}-{SHIFTUP}players
Sleep 200
SendPlay {Enter}
Sleep 200
SendPlay, sv{SHIFTDOWN}-{SHIFTUP}kick{Space}
KeyWait, Enter,d
Gui, Show, Dedicated Server
Return

BanPlayer:
Sleep 200
WinActivate Halo Console
Sleep 200
SendPlay, sv{SHIFTDOWN}-{SHIFTUP}players
Sleep 200
SendPlay {Enter}
Sleep 200
SendPlay, sv{SHIFTDOWN}-{SHIFTUP}ban{Space}
KeyWait, Enter,d
Gui, Show, Dedicated Server
Return

UnbanPlayer:
Sleep 200
WinActivate Halo Console
Sleep 200
SendPlay, sv{SHIFTDOWN}-{SHIFTUP}banlist
Sleep 200
SendPlay {Enter}
Sleep 200
SendPlay, sv{SHIFTDOWN}-{SHIFTUP}unban{Space}
KeyWait, Enter,d
Gui, Show, Dedicated Server
Return

BanList:
Sleep 200
WinActivate Halo Console
Sleep 200
SendPlay, sv{SHIFTDOWN}-{SHIFTUP}banlist
Sleep 200
SendPlay {Enter}
Gui, Show, Dedicated Server
Return

BanlistFile:
Sleep 200
WinActivate Halo Console
Sleep 200
SendPlay, sv{SHIFTDOWN}-{SHIFTUP}banlist{SHIFTDOWN}-{SHIFTUP}File{Space}
Sleep 200
KeyWait, Enter,d
Gui, Show, Dedicated Server
Return

MaxPlayers:
Sleep 200
WinActivate Halo Console
Sleep 200
SendPlay, sv{SHIFTDOWN}-{SHIFTUP}maxplayers{Space}
Sleep 200
KeyWait, Enter,d
Gui, Show, Dedicated Server
Return

TeamKillingPoint:
Sleep 200
WinActivate Halo Console
Sleep 200
SendPlay, sv{SHIFTDOWN}-{SHIFTUP}tk{SHIFTDOWN}-{SHIFTUP}ban{Space}
KeyWait, Enter,d
Gui, Show, Dedicated Server
Return

TeamKillPentalty:
Sleep 200
WinActivate Halo Console
Sleep 200
SendPlay, sv{SHIFTDOWN}-{SHIFTUP}tk{SHIFTDOWN}-{SHIFTUP}penalty{Space}
KeyWait, Enter,d
Gui, Show, Dedicated Server
Return

TeamKillGrace:
Sleep 200
WinActivate Halo Console
Sleep 200
SendPlay, sv{SHIFTDOWN}-{SHIFTUP}tk{SHIFTDOWN}-{SHIFTUP}grace{Space}
KeyWait, Enter,d
Gui, Show, Dedicated Server
Return

TeamKillCooldown:
Sleep 200
WinActivate Halo Console
Sleep 200
SendPlay, sv{SHIFTDOWN}-{SHIFTUP}tk{SHIFTDOWN}-{SHIFTUP}cooldown{Space}
KeyWait, Enter,d
Gui, Show, Dedicated Server
Return

GuiClose:
ExitApp

I have tried FileAppend, InStr, and others but can't seem to get it working correctly so I changed my script back to the way it was. I need the values only to be changed for the sv_command in the init.txt file. The only sv_command used more than once is the sv_mapcycle_add command to add new maps. Not all of the buttons need to change a variable. Some sv_commands only display values like the Current Maps button which does not need a variable. I have placed a variable for each button that needs one. Also if a sv_command is not stored in the init.txt file, it will need to be added when used.
I have dealt with this for a while now but cannot get it to work. Any help would be greatly appreciated.

_________________
USAFged
Get Er Done


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 18th, 2009, 5:18 pm 
Offline

Joined: February 11th, 2009, 2:23 pm
Posts: 142
Location: India
How do you interact your script with the INI file?
I don't see any iniread or iniwrite commands? in your script?

edit

use settings.INI file like this
Code:
[server_settings]
maxplayers=12

now your GUI script

suppose some
Code:
IniRead, numberofmultiplayers,%A_Workingdir%/settings.ini, server_settings,maxplayers

...
...
gui lines..
...

multiplayer:
...some more lines...
send, Sv_multiplayer_%numberofmultiplayers%


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 18th, 2009, 7:58 pm 
Offline

Joined: March 5th, 2009, 2:21 am
Posts: 68
Location: Chuckey, Tn.
Montu wrote:
How do you interact your script with the INI file?
I don't see any iniread or iniwrite commands? in your script?

edit

use settings.INI file like this
Code (Copy):

[server_settings]
maxplayers=12


now your GUI script


The Halo Dedicated Server loads the sv_command values from the init.txt file. This is controlled by the server program and I cannot change the file it uses to an INI file. My intentions are to update the init.txt file when a sv_command button is clicked on from my Gui window. For example the server name is saved with the sv_name command. As you can see in the init.txt file the sv_name has a value of Halo_DS. Lets say I want to change the server name to Montu. I would click on the Server Name button from my Gui window, it will type sv_name{Space} and then wait for me to enter Montu and press the Enter key. The server command window will inform me that it has accepted the new server name as Montu. After I press the Enter key to tell the server to accept the new server name, I need my script to search for the sv_name command in the init.txt file and replace the Halo_DS value with the new Montu value. I have tried it several different ways but the only thing I have come up with is to add an extra sv_name command at the end of the init.txt file. I cannot figure out how to locate the sv_name command in the init.txt file and than replace the old value with the new.

_________________
USAFged
Get Er Done


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 19th, 2009, 10:29 am 
Offline

Joined: March 17th, 2008, 10:02 pm
Posts: 21
Location: Netherlands
Maybe i'm dum and don't understand the problem,
but why don't U use loop read for parsing the txt file and stringreplace to replace the servername ?

_________________
your eyes are like bright stars in the sea,
you clean the dishes and I watch tv...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 19th, 2009, 4:03 pm 
Offline

Joined: March 5th, 2009, 2:21 am
Posts: 68
Location: Chuckey, Tn.
Statdust wrote:
Maybe i'm dum and don't understand the problem,
but why don't U use loop read for parsing the txt file and stringreplace to replace the servername ?

I have tried using FileRead, Loop, Parse, StringReplace, and FileAppend but I either got errors or it could not find the contents of the sv_name command. As shown in the init.txt file below I can write the correct variable to the sv_name command, but it adds it to the end of the file instead of replacing the sv_command in the first line.

init.txt File
Code:
sv_name Halo_DS
sv_public 1
sv_maxplayers 12
sv_password halo
sv_mapcycle_add bloodgulch "Done Slayer"
sv_mapcycle_add timberland "team king"
sv_mapcycle_add damnation "team slayer"
sv_mapcycle_add dangercanyon ctf
sv_mapcycle_add carousel slayer
sv_mapcycle_add gephyrophobia slayer
sv_mapcycle_add infinity "classic rockets"
sv_mapcycle_begin
sv_rcon_password test
sv_name test

I know how write the results to the init.txt file, but I just can't figure out how to replace what is already there. I cannot have more then 1 sv_name command in the file. The only sv_command that can have more than 1 entry is the sv_mapcycle_add command to play different maps. Here is the code I am using for the Server Name button.

Script for Server Name button.
Code:
ServerName:
Guicontrol, Show, Enter the new server name                   ;Show server name prompt text
GuiControl, Show%vEditServerName%, EditServerName             ;Show server name edit field
Gui, Show, x770 h440 w235, Dedicated Server                   ;Extend the length of window
GuiControl, Focus, EditServerName                             ;Selectthe server name edit field
KeyWait, Enter, d                                             ;Wait for Enter key to be pressed
Send ^a                                                       ;Select the text entered for the server name
Sleep 200                                                     ;Wait 200ms
Send ^c                                                       ;Copy the server name to the clipboard
ClipWait                                                      ;Wait for the clipboard to contain text.
Sleep 200                                                     ;Wait for 200ms
WinActivate Halo Console                                      ;Make Halo Console the active window
Sleep 200                                                     ;Wait 200ms
SendPlay, sv{SHIFTDOWN}-{SHIFTUP}name{Space}%Clipboard%       ;Send sv_name command plus the clipboard value
Sleep 500                                                     ;Wait 500ms
SendPlay, {Enter}                                             ;Wait for the Enter key to be pressed
Guicontrol, Hide, Enter the new server name                   ;Hide server name prompt text
GuiControl, Hide, EditServerName                              ;Hide server name edit field
Gui, Show, x770 h390 w235, Dedicated Server                   ;Reduce the length of window
FileAppend, sv_name%A_SPACE%%Clipboard%, init.txt             ;Write new server name to init.txt file
Return                                                        ;Return to the Gui Window

Thanks for any help you can give me.

_________________
USAFged
Get Er Done


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 20th, 2009, 4:25 am 
Offline

Joined: March 5th, 2009, 2:21 am
Posts: 68
Location: Chuckey, Tn.
I have made another change to the script for the Server Name label. The changes are in red. But this still does not work for me.
Code:
ServerName:
Guicontrol, Show, Enter the new server name                   ;Show server name prompt text
GuiControl, Show%vEditServerName%, EditServerName             ;Show server name edit field
Gui, Show, x770 h440 w235, Dedicated Server                   ;Extend the length of window
GuiControl, Focus, EditServerName                             ;Selectthe server name edit field
KeyWait, Enter, d                                             ;Wait for Enter key to be pressed
Send ^a                                                       ;Select the text entered for the server name
Sleep 200                                                     ;Wait 200ms
Send ^c                                                       ;Copy the server name to the clipboard
ClipWait                                                      ;Wait for the clipboard to contain text.
Sleep 200                                                     ;Wait for 200ms
WinActivate Halo Console                                      ;Make Halo Console the active window
Sleep 200                                                     ;Wait 200ms
SendPlay, sv{SHIFTDOWN}-{SHIFTUP}name{Space}%Clipboard%       ;Send sv_name command plus the clipboard value
Sleep 500                                                     ;Wait 500ms
SendPlay, {Enter}                                             ;Wait for the Enter key to be pressed
Guicontrol, Hide, Enter the new server name                   ;Hide server name prompt text
GuiControl, Hide, EditServerName                              ;Hide server name edit field
Gui, Show, x770 h390 w235, Dedicated Server                   ;Reduce the length of window
Loop, read, init.txt
{
  Loop, Parse,
  IfInString, A_LoopReadLine, sv_name
  {
    StringReplace, Contents, Contents, sv_name, sv_name%A_SPACE%%Clipboard%
  }
}

Return

Could someone please help me figure out how to solve my problem, After I click on the Server Name button to change the name of the server, I need the script to do the following.

Replace the sv_name command in the init.txt file from sv_name Halo_DS to sv_name <value saved to clipboard> by entering the new server name in the EditServerName entry field.

_________________
USAFged
Get Er Done


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 20th, 2009, 10:40 am 
Offline

Joined: March 17th, 2008, 10:02 pm
Posts: 21
Location: Netherlands
Code:
Loop, read, init.txt
{
  Loop, Parse, A_LoopReadLine, %A_Tab%%A_Space%
  IfInString, A_LoopReadLine, sv_name
  {
       msgbox, sv_name found
  }
}
Return


This works fine for me...
more tips (how to build a string) to be found in my post: http://www.autohotkey.com/forum/viewtop ... highlight=

succes

_________________
your eyes are like bright stars in the sea,
you clean the dishes and I watch tv...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 20th, 2009, 8:00 pm 
Offline

Joined: March 5th, 2009, 2:21 am
Posts: 68
Location: Chuckey, Tn.
stardust wrote:
Loop, read, init.txt
{
Loop, Parse, A_LoopReadLine, %A_Tab%%A_Space%
IfInString, A_LoopReadLine, sv_name
{
msgbox, sv_name found
}
}
Return


This works fine for me...

Thanks again for your reply stardust. I have changed my script to reflect your suggestion and it now reads as follows.
Code:
ServerName:
Guicontrol, Show, Enter the new server name                   ;Show server name prompt text
GuiControl, Show%vEditServerName%, EditServerName             ;Show server name edit field
Gui, Show, x770 h440 w235, Dedicated Server                   ;Extend the length of window
Sleep 200
GuiControl, Focus, EditServerName                             ;Selectthe server name edit field
KeyWait, Enter, d                                             ;Wait for Enter key to be pressed
Send ^a                                                       ;Select the text entered for the server name
Sleep 200                                                     ;Wait 200ms
Send ^c                                                       ;Copy the server name to the clipboard
ClipWait                                                      ;Wait for the clipboard to contain text.
Sleep 200                                                     ;Wait for 200ms
WinActivate Halo Console                                      ;Make Halo Console the active window
Sleep 200                                                     ;Wait 200ms
SendPlay, sv{SHIFTDOWN}-{SHIFTUP}name{Space}%Clipboard%       ;Send sv_name command plus the clipboard value
Sleep 500                                                     ;Wait 500ms
SendPlay, {Enter}                                             ;Wait for the Enter key to be pressed
Guicontrol, Hide, Enter the new server name                   ;Hide server name prompt text
GuiControl, Hide, EditServerName                              ;Hide server name edit field
Gui, Show, x770 h390 w235, Dedicated Server                   ;Reduce the length of window
Loop, read, init.txt
{
  Loop, Parse, A_LoopReadLine, %A_Tab%%A_Space%
  IfInString, A_LoopReadLine, sv_name
  {
    StringReplace, EditServerName, EditServerName, %A_LoopReadLine%, sv_name%A_SPACE%%Clipboard%, All
    msgbox, The next line shows that the Loop is reading the correct line in the init.txt file.`n`n%A_LoopReadLine%.`n`nThe next  line shows that the clipbaord has saved the new value to be used`nfor the new server name.`n`n%Clipboard%.
  }
}
Return                                                        ;Return to the Gui Window

Notice also that I changed the MsgBox to read the actual variables received from the loop. When I click on the Server Name button and enter USAFged as the new server name, the MsgBox shows it has read the sv_name command correctly as sv_name Halo_DS and it also shows the clipboard has stored USAFged as the new server name.
I am trying to get the StringReplace function to replace the sv_name Halo_DS with sv_name USAFged in the init.txt file. This has to be replaced instead of just added because the init.txt file can only have one sv_name command. The only sv_command that is allowed multi entries is the sv_mapcycle_add command to allow the server to provide different maps to run in the order they are listed.
There are several Halo players that wish to play on their own dedicated servers but are afraid to make changes to the init.txt file. My script will not only load the Halo server to run and allow them to make changes for any sv_command using a single button click, but will also update the init.txt file. So the next time they run the script the Halo server will load the last changes they have made. This should have been taken care of by Microsoft in first place.

_________________
USAFged
Get Er Done


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 20th, 2009, 8:34 pm 
StringReplace is used to modify variables,not to edit files.
You must delete the original file and create a new one.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 21st, 2009, 3:31 am 
Offline

Joined: March 5th, 2009, 2:21 am
Posts: 68
Location: Chuckey, Tn.
Guest++ wrote:
StringReplace is used to modify variables,not to edit files.
You must delete the original file and create a new one.

Then how do I go about reading the init.txt file (maybe FileRead, Contents, init.txt), deleting the init.txt (maybe FileDelete, init.txt), changing the value of sv_name Halo_DS to sv_name USAFged (not a clue), and then writing/creating the init.txt file (maybe FileAppend, Contents, init.txt)? It can only have 1 sv_name command in the file.

_________________
USAFged
Get Er Done


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 21st, 2009, 11:45 am 
USAFged wrote:
Then how do I go about reading the init.txt file (maybe FileRead, Contents, init.txt)

Yes
Quote:
deleting the init.txt (maybe FileDelete, init.txt)

After reading,editing the var and if the result is what you expect,Yes(create a backup is a good idea)

Quote:
changing the value of sv_name Halo_DS to sv_name USAFged (not a clue)

???!!! here you can use StringReplace
Quote:
and then writing/creating the init.txt file (maybe FileAppend, Contents, init.txt)?

Yes


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 21st, 2009, 2:50 pm 
Offline

Joined: March 17th, 2008, 10:02 pm
Posts: 21
Location: Netherlands
good guest ++ :!:
of course you 1st have to delete old content - i was just considering the parsing loop, that didn't work... :oops:

_________________
your eyes are like bright stars in the sea,
you clean the dishes and I watch tv...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 21st, 2009, 5:16 pm 
Offline

Joined: March 5th, 2009, 2:21 am
Posts: 68
Location: Chuckey, Tn.
With much needed help from Stardust, and Guest++ who steered me in the right direction, I now have it working the way I need it too. Thanks guys.
stardust wrote:
good guest ++
of course you 1st have to delete old content - i was just considering the parsing loop, that didn't work...

Yes the parsing loop did work and I still have it in my code. The loop allows me to read the old server name and save the result as OldServerName. The new server name I enter is copied to the clipboard and is saved to NewServerName. I moved the StringReplace line from inside the loop and placed it after the FileRead lines that Guest++ suggested.
The resulting script code is now as follows and works correctly.
Code:
ServerName:                                                           ;Server name code
Guicontrol, Show, Enter the new server name                           ;Show server name prompt text
GuiControl, Show%vEditServerName%, EditServerName                     ;Show server name edit field
Gui, Show, x770 h440 w235, Dedicated Server                           ;Extend the length of window
Sleep 200                                                             ;Wait 200ms
GuiControl, Focus, EditServerName                                     ;Selectthe server name edit field
KeyWait, Enter, d                                                     ;Wait for Enter key to be pressed
Send ^a                                                               ;Select the text entered for the server name
Sleep 200                                                             ;Wait 200ms
Send ^c                                                               ;Copy the server name to the clipboard
ClipWait                                                              ;Wait for the clipboard to contain text.
Sleep 200                                                             ;Wait for 200ms
WinActivate Halo Console                                              ;Make Halo Console the active window
Sleep 200                                                             ;Wait 200ms
SendPlay, sv{SHIFTDOWN}-{SHIFTUP}name{Space}%Clipboard%               ;Send sv_name command plus the clipboard value
Sleep 500                                                             ;Wait 500ms
SendPlay, {Enter}                                                     ;Wait for the Enter key to be pressed
Guicontrol, Hide, Enter the new server name                           ;Hide server name prompt text
GuiControl, Hide, EditServerName                                      ;Hide server name edit field
Gui, Show, x770 h390 w235, Dedicated Server                           ;Reduce the length of window
Loop, read, init.txt                                                  ;Start Loop to read init.txt file
{
  Loop, Parse, A_LoopReadLine, %A_Tab%%A_Space%                       ;Start Parse to read value 
  IfInString, A_LoopReadLine, sv_name                                 ;Get the server name value
  {
    OldServerName = %A_LoopReadLine%                                  ;Save the old server name value
    NewServerName = sv_name%A_SPACE%%Clipboard%                       ;Save the new server name value
  }
}
If NewServerName <> OldServerName                                     ;Check to see if server name has changed
{
  FileRead, Contents, init.txt                                        ;Read the contents of the init.txt file
  StringReplace, Contents, Contents, %OldServerName%, %NewServerName% ;Replace old server name with new
  FileDelete, init.txt                                                ;Delete the init.txt file
  FileAppend, %Contents%, init.txt                                    ;Create new init.txt file with new values
}
Return                                                                ;Return to the Gui Window

I have one other part to figure out. As I stated in the previous posts, the only sv_command that is allowed to have multiple entries is the sv_mapcycle_add command that allows new maps to be added to the mapcycle. The first thing the script needs to do when started is to read the init.txt file and move all of the sv_mapcycle_add command values to the bottom of the init.txt file. This will insure the maps are all place after each other whenever another map is added. Any suggestions.

_________________
USAFged
Get Er Done


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 21st, 2009, 8:34 pm 
This line "If NewServerName <> OldServerName" should be:
If NewServerName <> %OldServerName%
or
If (NewServerName <> OldServerName)
The way it is, the "if" will always be "false".

The line "Loop, Parse, A_LoopReadLine, %A_Tab%%A_Space%" is not doing anything,is it?

To put the lines with sv_mapcycle_add after the others...
Try this code: not tested
Code:
ServerName:                                                           ;Server name code
Guicontrol, Show, Enter the new server name                           ;Show server name prompt text
GuiControl, Show%vEditServerName%, EditServerName                     ;Show server name edit field
Gui, Show, x770 h440 w235, Dedicated Server                           ;Extend the length of window
Sleep 200                                                             ;Wait 200ms
GuiControl, Focus, EditServerName                                     ;Selectthe server name edit field
KeyWait, Enter, d                                                     ;Wait for Enter key to be pressed

;read the topic "GuiControlGet" in the manual,it is better than using the clipboard

Send ^a                                                               ;Select the text entered for the server name
Sleep 200                                                             ;Wait 200ms
Send ^c                                                               ;Copy the server name to the clipboard
ClipWait                                                              ;Wait for the clipboard to contain text.
Sleep 200                                                             ;Wait for 200ms
WinActivate Halo Console                                              ;Make Halo Console the active window
Sleep 200                                                             ;Wait 200ms
SendPlay, sv{SHIFTDOWN}-{SHIFTUP}name{Space}%Clipboard%               ;Send sv_name command plus the clipboard value
Sleep 500                                                             ;Wait 500ms
SendPlay, {Enter}                                                     ;Wait for the Enter key to be pressed
Guicontrol, Hide, Enter the new server name                           ;Hide server name prompt text
GuiControl, Hide, EditServerName                                      ;Hide server name edit field
Gui, Show, x770 h390 w235, Dedicated Server                           ;Reduce the length of window

to_write = ;var to store the new content
var_maps = ;store the maps
;you can use the reading loop to do all the work
Loop, read, init.txt                                                  ;Start Loop to read init.txt file
{
  ;Loop, Parse, A_LoopReadLine, %A_Tab%%A_Space%  is it necessary   
  IfInString, A_LoopReadLine, sv_name                                 ;Get the server name value
  {
    OldServerName = %A_LoopReadLine%                                  ;Save the old server name value
    NewServerName = sv_name%A_SPACE%%Clipboard%                       ;Save the new server name value
    if OldServerName <> %NewServerName%
      to_write .= NewServerName "`r`n"
   ;if A_LoopReadLine <> sv_name%A_SPACE%%Clipboard% ;this way, OldServerName and NewServerName are not needed
      ;to_write .= "sv_name " Clipboard "`r`n"
    else
      to_write .= A_LoopReadLine "`r`n" ; .= concatenation
  }
  else ifinstring, A_LoopReadLine, sv_mapcycle_add
      var_maps .= A_LoopReadLine "`r`n"
  else ;if (A_LoopReadLine != "") ;uncomment if necessary
     to_write .= A_LoopReadLine "`r`n"
}
;StringTrimRight, var_maps, var_maps, 2 ;remove the last "`r`n" uncomment if necessary
FileAppend, %to_write%%var_maps%, testing.txt
;If NewServerName <> OldServerName                                     ;Check to see if server name has changed
;{
;  FileRead, Contents, init.txt                                        ;Read the contents of the init.txt file
;  StringReplace, Contents, Contents, %OldServerName%, %NewServerName% ;Replace old server name with new
;  FileDelete, init.txt                                                ;Delete the init.txt file
;  FileAppend, %Contents%, init.txt                                    ;Create new init.txt file with new values
;}
Return     


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 21st, 2009, 10:14 pm 
Offline

Joined: March 5th, 2009, 2:21 am
Posts: 68
Location: Chuckey, Tn.
Thank you Guest++. It works just as I said I needed in the post above as shown in the results below.

testing.txt wrote:
sv_name test
sv_password get
sv_public 1
sv_maxplayers 12
sv_rcon_password test

sv_mapcycle_begin
sv_mapcycle_add bloodgulch "Done Slayer"
sv_mapcycle_add timberland "team king"
sv_mapcycle_add damnation "team slayer"
sv_mapcycle_add dangercanyon ctf
sv_mapcycle_add carousel slayer
sv_mapcycle_add gephyrophobia slayer
sv_mapcycle_add infinity "classic rockets"

The only addition I had to make is shown in red to create a new testing.txt file to prevent it from adding to itself whenever it is run.
Code:
FileDelete, testing.txt
FileAppend, %to_write%%var_maps%, testing.txt

However I made a mistake in my previous post when I stated how my end results should be and I am very sorry for your trouble. When I opened the testing.txt file I instantly knew I had made a important mistake. When I said all of the sv_mapcycle_add commands had to go at the end of the file, I forget about one command. The sv_mapcycle_begin has to go on the last line after the maps are loaded or the server will start without any maps to play. The end results of the init.txt file should be displayed as below. Very sorry for this mistake.
init.txt wrote:
sv_name USAFged
sv_password get
sv_public 1
sv_maxplayers 12
sv_rcon_password test

sv_mapcycle_add bloodgulch "Done Slayer"
sv_mapcycle_add timberland "team king"
sv_mapcycle_add damnation "team slayer"
sv_mapcycle_add dangercanyon ctf
sv_mapcycle_add carousel slayer
sv_mapcycle_add gephyrophobia slayer
sv_mapcycle_add infinity "classic rockets"

sv_mapcycle_begin

_________________
USAFged
Get Er Done


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 12 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group