Mit AutoIt (exp *) multiplizieren etc.

  • Hallo Mitglieder.

    Vorweg, mir ist kein besserer Titel eingefallen.

    Nun zum Thema.

    Ich habe folgendes Dokument, welches so aufgebaut ist.

    Spoiler anzeigen

    (monster (name 1) (index 1) (country 2) (race 0) (level 1) (ai 1) (range 20) (sight 160 240) (exp 2) (itemgroup 1 2)
    (str 21) (hth 1) (int 10) (wis 10) (dex 2) (hp 1) (mp 70) (aspeed 2400) (hit 0) (dodge 0)
    (attack 0 7 7) (magic 0 0) (defense 0 0) (absorb 0) (mspeed 1600 800)
    (quest (2 1 901 1) (3 1 902 1) (54 1 1025 1) (8001 1 933 1)))

    (monster (name 2) (index 2) (country 2) (race 0) (level 3) (ai 1) (range 16) (sight 160 240) (exp 4) (itemgroup 2 2)
    (str 27) (hth 2) (int 10) (wis 10) (dex 4) (hp 1) (mp 70) (aspeed 2400) (hit 0) (dodge 0)
    (attack 0 8 8) (magic 0 0) (defense 1 1) (absorb 0) (mspeed 1600 800) (resist 0 0 1 1 1)
    (quest (2 1 901 1) (3 1 902 1) (55 1 1026 1) (8001 1 933 1)))

    Ich möchte nun ein Script schreiben, welches dieses Dokument öffnet, den Wert in (exp *) nimmt und diesen mit dem angegeben Wert multipliziert, dividiert etc.

    Die GUI würde folgendermaßen aussehen.
    Als erstes ist eine Inputbox, dort neben ein *, /, +, - und dort neben ein Button mit der Aufschrift "Change".
    Danach soll er diese Veränderungen speichern.

    Nun wollte ich fragen, ob dies mit AutoIt möglich ist.

    Mit freundlichem Gruß
    Aldeos

    Einmal editiert, zuletzt von Kazuto (29. März 2011 um 14:50)

  • Eine GUI habe ich nun geschrieben.

    Spoiler anzeigen
    [autoit]

    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #Region ### START Koda GUI section ### Form=c:\users\kazu\desktop\gui.kxf
    $GUI = GUICreate("Kal Online EXP Changer", 390, 90, 281, 206)
    $VALUE = GUICtrlCreateInput("", 96, 56, 105, 21)
    $PLUS = GUICtrlCreateButton("+", 208, 56, 25, 25, $WS_GROUP)
    $MINUS = GUICtrlCreateButton("-", 240, 56, 25, 25, $WS_GROUP)
    $DIV = GUICtrlCreateButton("/", 304, 56, 25, 25, $WS_GROUP)
    $MULTI = GUICtrlCreateButton("*", 272, 56, 25, 25, $WS_GROUP)
    $FILE = GUICtrlCreateInput("", 72, 16, 217, 21)
    $OPEN = GUICtrlCreateButton("Open", 296, 16, 57, 25, $WS_GROUP)
    $FILE_LAB = GUICtrlCreateLabel("File:", 40, 16, 23, 17)
    $VALUE_LAB = GUICtrlCreateLabel("Change by:", 32, 56, 58, 17)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $OPEN
    FileOpenDialog("Search for initmonster.txt", @ScriptDir & "\", "(initmonster.txt)", 1 + 4 )
    Case $PLUS

    [/autoit] [autoit][/autoit] [autoit]

    Case $MINUS

    [/autoit] [autoit][/autoit] [autoit]

    Case $MULTI

    [/autoit] [autoit][/autoit] [autoit]

    Case $DIV

    [/autoit] [autoit][/autoit] [autoit]

    EndSwitch
    WEnd

    [/autoit]

    3 Mal editiert, zuletzt von Kazuto (29. März 2011 um 14:21)

  • Ein FileOpenDialog habe ich bereits.
    Wie kann ich FileRead mit dem Dialog verknüpfen?
    StringRegExp verstehe ich nicht ganz, das Beispiel in der Hilfe ist mir zu unverständlich.

  • Hier mal ein Beispiel:

    Spoiler anzeigen
    [autoit]

    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <array.au3>
    #include <WindowsConstants.au3>
    #region ### START Koda GUI section ### Form=c:\users\kazu\desktop\gui.kxf
    $GUI = GUICreate("Kal Online EXP Changer", 390, 90, 281, 206)
    $VALUE = GUICtrlCreateInput("", 96, 56, 105, 21)
    $PLUS = GUICtrlCreateButton("+", 208, 56, 25, 25, $WS_GROUP)
    $MINUS = GUICtrlCreateButton("-", 240, 56, 25, 25, $WS_GROUP)
    $DIV = GUICtrlCreateButton("/", 304, 56, 25, 25, $WS_GROUP)
    $MULTI = GUICtrlCreateButton("*", 272, 56, 25, 25, $WS_GROUP)
    $FILE = GUICtrlCreateInput("", 72, 16, 217, 21)
    $OPEN = GUICtrlCreateButton("Open", 296, 16, 57, 25, $WS_GROUP)
    $FILE_LAB = GUICtrlCreateLabel("File:", 40, 16, 23, 17)
    $VALUE_LAB = GUICtrlCreateLabel("Change by:", 32, 56, 58, 17)
    GUISetState(@SW_SHOW)
    #endregion ### END Koda GUI section ###

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $OPEN
    $sFile = FileOpenDialog("Search for initmonster.txt", @ScriptDir & "\", "(initmonster.txt)", 1 + 4)
    If @error Then ContinueLoop
    GUICtrlSetData($FILE, $sFile)
    Case $PLUS, $MINUS, $MULTI, $DIV
    $sSign = "+"
    If $nMsg = $MINUS Then $sSign = "-"
    If $nMsg = $MULTI Then $sSign = "*"
    If $nMsg = $DIV Then $sSign = "/"
    $sRead = FileRead(GUICtrlRead($FILE))
    $aVal = StringRegExp($sRead, "\(exp (\d*)\)", 3)
    For $i = 0 To UBound($aVal) - 1
    $sRead = StringReplace($sRead, "(exp " & $aVal[$i] & ")", "(exp " & Execute($aVal[$i] & $sSign & GUICtrlRead($VALUE)) & "--)")
    Next
    $sRead = StringReplace($sRead, "--) ", ") ")
    FileDelete($sFile)
    FileWrite($sFile, $sRead)
    MsgBox(262144, "blubb", "geändert :)")
    EndSwitch
    WEnd

    [/autoit]
  • Vielen Dank blubbstar.

    Der Support hier ist einfach grandios. ^^

    *EDIT*

    Ich habe nun eine Progressbar eingefügt, da es sonst den Anschein hat, als wäre das Programm stehen geblieben.
    Ich würde diese Progressbar nun gerne mit dem aktuellen Code verbinden.

    Spoiler anzeigen
    [autoit]

    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <array.au3>
    #include <WindowsConstants.au3>
    $GUI = GUICreate("Kal Online EXP Changer", 390, 113, 281, 206)
    $VALUE = GUICtrlCreateInput("", 96, 56, 105, 21)
    $PLUS = GUICtrlCreateButton("+", 208, 56, 25, 25, $WS_GROUP)
    $MINUS = GUICtrlCreateButton("-", 240, 56, 25, 25, $WS_GROUP)
    $DIV = GUICtrlCreateButton("/", 304, 56, 25, 25, $WS_GROUP)
    $MULTI = GUICtrlCreateButton("*", 272, 56, 25, 25, $WS_GROUP)
    $FILE = GUICtrlCreateInput("", 72, 16, 217, 21)
    $OPEN = GUICtrlCreateButton("Open", 296, 16, 57, 25, $WS_GROUP)
    $FILE_LAB = GUICtrlCreateLabel("File:", 40, 16, 23, 17)
    $VALUE_LAB = GUICtrlCreateLabel("Change by:", 32, 56, 58, 17)
    $PROG = GUICtrlCreateProgress(16, 96, 353, 9)
    GUISetState(@SW_SHOW)

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $OPEN
    $sFile = FileOpenDialog("Search for initmonster.txt", @ScriptDir & "\", "(initmonster.txt)", 1 + 4)
    If @error Then ContinueLoop
    GUICtrlSetData($FILE, $sFile)
    Case $PLUS, $MINUS, $MULTI, $DIV
    $sSign = "+"
    If $nMsg = $MINUS Then $sSign = "-"
    If $nMsg = $MULTI Then $sSign = "*"
    If $nMsg = $DIV Then $sSign = "/"
    $sRead = FileRead(GUICtrlRead($FILE))
    $aVal = StringRegExp($sRead, "\(exp (\d*)\)", 3)
    For $i = 0 To UBound($aVal) - 1
    $sRead = StringReplace($sRead, "(exp " & $aVal[$i] & ")", "(exp " & Execute($aVal[$i] & $sSign & GUICtrlRead($VALUE)) & "--)")
    Next
    $sRead = StringReplace($sRead, "--) ", ") ")
    FileDelete($sFile)
    FileWrite($sFile, $sRead)
    MsgBox(262144, "Successfully", "The Experience was successfully changed.")
    EndSwitch
    WEnd

    [/autoit]

    *EDIT*
    Wäre es auch möglich, das gleiche Tool für solche Zeilen zu schreiben?

    Spoiler anzeigen

    (group (index 101) (money (920 200)) (item (960 443 0) (1000 47 0)))
    (group (index 102) (money (860 300)) (item (900 443 0) (920 2 0) (940 23 0) (960 91 0) (1000 47 0)))

    In dieser Zeile sollte (money * *) geändert werden.
    Jedoch nur der 2. Wert, daher kann ich den oben genannten Script nicht so einfach umschreiben.

    2 Mal editiert, zuletzt von Kazuto (29. März 2011 um 15:07)

  • Spoiler anzeigen
    [autoit]

    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <array.au3>
    #include <WindowsConstants.au3>
    $GUI = GUICreate("Kal Online EXP Changer", 390, 113, 281, 206)
    $VALUE = GUICtrlCreateInput("", 96, 56, 105, 21)
    $PLUS = GUICtrlCreateButton("+", 208, 56, 25, 25, $WS_GROUP)
    $MINUS = GUICtrlCreateButton("-", 240, 56, 25, 25, $WS_GROUP)
    $DIV = GUICtrlCreateButton("/", 304, 56, 25, 25, $WS_GROUP)
    $MULTI = GUICtrlCreateButton("*", 272, 56, 25, 25, $WS_GROUP)
    $FILE = GUICtrlCreateInput("", 72, 16, 217, 21)
    $OPEN = GUICtrlCreateButton("Open", 296, 16, 57, 25, $WS_GROUP)
    $FILE_LAB = GUICtrlCreateLabel("File:", 40, 16, 23, 17)
    $VALUE_LAB = GUICtrlCreateLabel("Change by:", 32, 56, 58, 17)
    DllCall('uxtheme.dll', 'none', 'SetThemeAppProperties', 'int', 0); BugFix
    $PROG = GUICtrlCreateProgress(16, 96, 353, 9)
    GUICtrlSetBkColor(-1, 0x000000)
    GUICtrlSetColor(-1, 0x99FF99)
    DllCall('uxtheme.dll', 'none', 'SetThemeAppProperties', 'int', 7)
    GUISetState(@SW_SHOW)

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $OPEN
    $sFile = FileOpenDialog("Search for initmonster.txt", @ScriptDir & "\", "(initmonster.txt)", 1 + 4)
    If @error Then ContinueLoop
    GUICtrlSetData($FILE, $sFile)
    Case $PLUS, $MINUS, $MULTI, $DIV
    If GUICtrlRead($VALUE) = '' Then ContinueLoop MsgBox(262144, "Error", "Invalid value.")
    $sSign = "+"
    If $nMsg = $MINUS Then $sSign = "-"
    If $nMsg = $MULTI Then $sSign = "*"
    If $nMsg = $DIV Then $sSign = "/"
    $sFile = GUICtrlRead($FILE)
    $sRead = FileRead($sFile)
    $aVal = StringRegExp($sRead, "\(exp (.+?)\)", 3)
    For $i = 0 To UBound($aVal) - 1
    GUICtrlSetData($PROG, (100 / UBound($aVal)) * ($i + 1))
    $sRead = StringReplace($sRead, "(exp " & $aVal[$i] & ")", "(exp " & Execute($aVal[$i] & $sSign & GUICtrlRead($VALUE)) & "--)")
    Sleep(20); Je nachdem wie viele Einträge so ne File hat kannste den anpassen. Ohne Sleep ist es halt sofort fertig und sieht demensprechend schlecht aus.
    Next
    $sRead = StringReplace($sRead, "--)", ")")
    FileDelete($sFile)
    FileWrite($sFile, $sRead)
    MsgBox(262144, "Successfully", "The Experience was successfully changed.")
    EndSwitch
    WEnd

    [/autoit]

    Hier noch mit Progressbar. Für das die money value brauchst du vorher ne andere GUI :). Hab den Oldstyle vom Progressbar gewählt, da der Vista immer so nachhängt mit dem animieren und nicht instant springt. Das sieht nicht gut aus, wenn der Progressbar bei 20% hängt und das Script fertig is :( Allerdings kannst du dadurch Farben setzen.

  • Spoiler anzeigen
    [autoit]

    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <array.au3>
    #include <WindowsConstants.au3>
    $GUI = GUICreate("Kal Online Money Changer", 390, 113, 281, 206)
    $VALUE = GUICtrlCreateInput("", 96, 56, 105, 21)
    $PLUS = GUICtrlCreateButton("+", 208, 56, 25, 25, $WS_GROUP)
    $MINUS = GUICtrlCreateButton("-", 240, 56, 25, 25, $WS_GROUP)
    $DIV = GUICtrlCreateButton("/", 304, 56, 25, 25, $WS_GROUP)
    $MULTI = GUICtrlCreateButton("*", 272, 56, 25, 25, $WS_GROUP)
    $FILE = GUICtrlCreateInput("", 72, 16, 217, 21)
    $OPEN = GUICtrlCreateButton("Open", 296, 16, 57, 25, $WS_GROUP)
    $FILE_LAB = GUICtrlCreateLabel("File:", 40, 16, 23, 17)
    $VALUE_LAB = GUICtrlCreateLabel("Change by:", 32, 56, 58, 17)
    DllCall('uxtheme.dll', 'none', 'SetThemeAppProperties', 'int', 0)
    $PROG = GUICtrlCreateProgress(16, 96, 353, 9)
    GUICtrlSetBkColor(-1, 0x000000)
    GUICtrlSetColor(-1, 0x99FF99)
    DllCall('uxtheme.dll', 'none', 'SetThemeAppProperties', 'int', 7)
    GUISetState(@SW_SHOW)

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $OPEN
    $sFile = FileOpenDialog("Search for initmonster.txt", @ScriptDir & "\", "(initmonster.txt)", 1 + 4)
    If @error Then ContinueLoop
    GUICtrlSetData($FILE, $sFile)
    Case $PLUS, $MINUS, $MULTI, $DIV
    If GUICtrlRead($VALUE) = '' Then ContinueLoop MsgBox(262144, "Error", "Invalid value.")
    $sSign = "+"
    If $nMsg = $MINUS Then $sSign = "-"
    If $nMsg = $MULTI Then $sSign = "*"
    If $nMsg = $DIV Then $sSign = "/"
    $sFile = GUICtrlRead($FILE)
    $sRead = FileRead($sFile)
    $aVal = StringRegExp($sRead, "\(money \((.+?) (.+?)\)\)", 3)
    For $i = 0 To UBound($aVal) - 1 Step +2
    GUICtrlSetData($PROG, (100 / UBound($aVal)) * ($i + 2))
    $sRead = StringReplace($sRead, "(money (" & $aVal[$i] & " " & $aVal[$i + 1] & ")", _
    "(money (" & $aVal[$i] & " " & Execute($aVal[$i + 1] & $sSign & GUICtrlRead($VALUE)) & "--)")
    Sleep(20)
    Next
    $sRead = StringReplace($sRead, "--)", ")")
    FileDelete($sFile)
    FileWrite($sFile, $sRead)
    MsgBox(262144, "Successfully", "The money was successfully changed.")
    EndSwitch
    WEnd

    [/autoit]

    Hier noch fürs Geld. Vllt. auch beide male nochn Round reinsetzen, weil wenn du teilst kann es manchmal nen paar Nachkommastellen geben ;).