darkshadow791 Posted December 9, 2006 Share Posted December 9, 2006 (edited) Hi, I've been trying to write a script that is like a script writer for half-life based games. I'm trying to make it so that it has all (most) of the features of notepad or something similar but with one extra option - to randomize alias names. If you don't play this game then let me explain: While writing scripts for these games you use a basic format, so if i were to write a script that attacked and then jumped, it would look like: alias "jumpattack" "+attack; wait; -attack; wait; +jump; wait; -jump" bind Mouse1 "jumpattack" However, there are many formats, some example formats would be this: alias jumpattack "+attack; wait; -attack; wait; +jump; wait; -jump" bind Mouse1 jumpattack alias "jumpattack" "+attack; wait; -attack; wait; +jump; wait; -jump" bind Mouse1 jumpattack Etc. Basically, quotes are optional for everything except for things with spaces. The basic format is: alias <alias name, no spaces allowed, quotes optional> <space> <actions to perform, always with quotes around it, and can contain multiple command if; is used> bind <key name, quotes are optional> <alias name> So what I'm trying to achieve is have someone be able to write a script(s) with this app and then hit a button which goes through the script and: For every line with "alias" in it, take the name of the alias and add some random numbers and/or letters to the end of it. Then, go through the entire script and search for the name of the alias and add the SAME random numbers/letters to the end of EVERY instance of it. However, you are able to do things like this: alias attackit "+attack; wait; -attack" alias jumpit "+jump; wait; -jump" alias jumpattack "attackit; wait; jumpit" bind Mouse1 jumpattack So they can use names of aliases in other commands, which might cause problems if you forget a space or " or ; So the search and replace must be able to replace the command without modifying anything around the command. Also, another problem is that you can have things like this in scripts: alias "toggle" "toggleon" alias "toggleon" "do something here; alias toggle toggleoff" alias "toggleoff" "do something else; alias toggle toggleon" So if I were to search JUST for alias it would return things like this that I do not want, since it would add random things to it twice or possibly glitch and not do it at all. Now, that's the easy part. I believe I can do most of that. HOWEVER! I have no clue how I would POSSIBLY be able to go through EVERY line and see if it has "alias" in it, then change the name of the alias for every other line, then go through the next line and repeat over and over for every line, and still be able to put the entirely new script back into the edit keeping everything the same except for alias names. Here is the code I have so far: expandcollapse popup#include <GuiConstants.au3> #Include <GuiEdit.au3> GuiCreate("Script Randomizer", 400, 300,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) $Edit_1 = GuiCtrlCreateEdit("Write your script here!", 50, 40, 290, 220) $Button_2 = GuiCtrlCreateButton("Randomize!", 100, 270, 170, 20) GuiSetState() While 1 $msg = GuiGetMsg() Switch $msg Case $GUI_EVENT_CLOSE ExitLoop Case $Button_2 $script = StringSplit(GUICtrlRead($Edit_1),Chr(10)) MsgBox(0,"test",$script[2]) Exit Case Else ;;; EndSwitch WEnd Exit Func Randomize($s_var = 0) $file = FileOpen("file.txt", 2) ;$lines = _GUICtrlEditGetLineCount($Edit_1) $script = StringSplit(GUICtrlRead($Edit_1),Chr(10)) Dim $newscript[$script[0] - 1] For $i = 0 To $script[0] - 1 If StringInStr($script[$i],"alias") Then $replace = StringSplit($script[$i]," ") ;$replace[2] is the alias name ;FileWriteLine($file,$newline) ;find every instance of $replace[2] in $Edit_1 and append a random ;set of numbers or characters to the front of it, keeping the same ;random numbers/chars for each thing, so that for example every ;instance of $replace[2] being "lol" would make everything in the ;edit replace "lol" to "12415lol" with or without the quotes $newscript = $newscript & $replace[2] Else EndIf Next EndFunc I know this can be really confusing if you don't know how scripting for Half Life works so if anyone wants to ask a question and get something cleared up about what I want/need then just post and I will do my best to explain it. *Note: This isn't anything illegal, wrong, against EULA's, hacking, or something other-wise not good. Valve fully permits this. Edit: Here is my notes I threw down into notepad trying to figure out the best way to do this. expandcollapse popupperson enters script: alias code1 "code2" alias code2 "wait" person presses button searches for the use of "alias" finds the thing after it would be code1 or "code1" should put a random thing after it i.e. alias code12bas324 "code2" alias code2 "wait" find all lines with code1 in it then change it from code1 to code12bas324 then find next line with "alias" in it take the second part (with or without ""s again) then find ALL instances of it and replace with random thing. repeat for every line of the script code outline: for lineofscript 0 to last line if has alias split the string take the string[2] and find all instances of it in edit else do nothing? next setdata for edit = new replaced strings into the original script **************** EDIT2: **************** Ok now I just need a simple way to find/replace items in a GUICtrlCreateEdit, I just figured out how to do the rest. Edited December 9, 2006 by darkshadow791 Note Taker Lite - a note taking / converting tool. Link to comment Share on other sites More sharing options...
JSThePatriot Posted December 9, 2006 Share Posted December 9, 2006 **************** EDIT2: **************** Ok now I just need a simple way to find/replace items in a GUICtrlCreateEdit, I just figured out how to do the rest.Use the following... $editTxt = GUICtrlRead($Edit_1) To get the text into a variable that can be searched through. Then I would start studying StringInStr or StringRegEx. (I would recommend StringRegEx) I hope this helps, JS AutoIt Links File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out. ComputerGetInfo UDF's Updated! 11-23-2006 External Links Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more) Link to comment Share on other sites More sharing options...
The Kandie Man Posted December 9, 2006 Share Posted December 9, 2006 (edited) $h_edit = GUICtrlCreateEdit();whatever it is you want to do in the parameters Note: I didn't test the code, but that should get you pointed in the right direction. Edited December 9, 2006 by The Kandie Man "So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire Link to comment Share on other sites More sharing options...
darkshadow791 Posted December 9, 2006 Author Share Posted December 9, 2006 (edited) expandcollapse popupLocal $s_ReadEditData $s_ReadEditData =GUICtrlRead($h_edit) GUICtrlSetData($h_edit,StringReplace($s_ReadEditData,$s_searchstring,$s_replacestring)) oÝ÷ Ûú®¢×jxq©÷öÖÞ'¯xbv}ý¶ØbJ¶²'z¼(ÀÞzZÞjYrvé«Þm~)â²¢»^²×nëHßÙ½ÒË«zØb³¥ +8ZK7Ý8b²+0«H§`¢)àjëh×6#include <GuiConstants.au3> #include <GuiEdit.au3> #include <Date.au3> #include <File.au3> $GUI = GuiCreate("Script Randomizer", 400, 300,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) $Edit_1 = GuiCtrlCreateEdit("Write your script here!", 50, 10, 290, 220) $B_Rand = GuiCtrlCreateButton("Randomize!", 100, 250, 170, 20) $M_File = GUICtrlCreateMenu("File") ;$M_New ? $M_New = GUICtrlCreateMenuitem("New", $M_File) $M_Open = GUICtrlCreateMenuitem("Open", $M_File) $M_Save = GUICtrlCreateMenuitem("Save", $M_File) $M_Exit = GUICtrlCreateMenuitem("Exit", $M_File) $M_Edit = GUICtrlCreateMenu("Edit") $M_Undo = GUICtrlCreateMenuitem("Undo", $M_Edit) $M_Cut = GUICtrlCreateMenuitem("Cut", $M_Edit) $M_Copy = GUICtrlCreateMenuitem("Copy", $M_Edit) $M_Paste = GUICtrlCreateMenuitem("Paste", $M_Edit) $M_Find = GUICtrlCreateMenuitem("Find", $M_Edit) $M_Replace = GUICtrlCreateMenuitem("Replace", $M_Edit) $M_SelectAll = GUICtrlCreateMenuitem("Select All", $M_Edit) $M_TimeDate = GUICtrlCreateMenuitem("Time/Date", $M_Edit) $M_Help = GUICtrlCreateMenu("Help") $M_HelpOpen = GUICtrlCreateMenuitem("Help", $M_Help) $M_About = GUICtrlCreateMenuitem("About", $M_Help) $hlfol = RegRead("HKEY_CURRENT_USER\Software\Valve\Steam", "ModInstallPath") If $hlfol = "" Then $hlfol = @DesktopCommonDir $Custom = False ;option to randomize everything or only things with %r in front of them GuiSetState() While 1 $msg = GuiGetMsg() Switch $msg Case $GUI_EVENT_CLOSE ExitLoop Case $B_Rand ;still haven't changed this - was for testing purposes - this will be the randomize function $script = StringSplit(GUICtrlRead($Edit_1),Chr(10)) MsgBox(0,"test",$script[2]) Exit Case $M_Copy Sleep(100) Send("^{c}") Case $M_Cut Sleep(100) Send("^{x}") Case $M_Exit _Exit() Case $M_Find _GuiCtrlEditFind($GUI, $Edit_1) Case $M_Replace _GuiCtrlEditFind($GUI, $Edit_1, True) Case $M_About About() Case $M_HelpOpen Help() Case $M_New New() Case $M_Open $open_file = FileOpenDialog("Open a file...",$hlfol, "All (*.*)|Text Files (*.txt;*.cfg;*.ini;*.log)", 1) If Not $open_file = "" Then GUICtrlSetData($Edit_1, FileRead($open_file)) EndIf Case $M_Paste Sleep(100) Send("^{v}") Case $M_Save Save() Case $M_SelectAll _GUICtrlEditSetSel($Edit_1, 0, -1) Case $M_TimeDate Sleep(100) Send(_Now()) Case $M_Undo Sleep(100) _GUICtrlEditUndo($Edit_1) Case Else ;;; EndSwitch WEnd Exit Func Randomize($s_var = 0) $num = 0 $file = FileOpen("file.txt", 2) ;$lines = _GUICtrlEditGetLineCount($Edit_1) $script = StringSplit(GUICtrlRead($Edit_1),Chr(10)) Dim $newscript[$script[0] - 1] For $i = 0 To $script[0] - 1 Step 1 If (CheckCustom() == False) Then If StringInStr($script[$i],"alias") Then $replace = StringSplit($script[$i]," ") ;$replace[2] is the alias name ;FileWriteLine($file,$newline) ;find every instance of $replace[2] in $Edit_1 and append a random ;set of numbers or characters to the front of it, keeping the same ;random numbers/chars for each thing, so that for example every ;instance of $replace[2] being "lol" would make everything in the ;edit replace "lol" to "12415lol" with or without the quotes $append[$i] = $replace[2] + ( Chr(Random(Asc("a"), Asc("z"), 1)) + Random(0, 9, 1) + Chr(Random(Asc("a"), Asc("z"), 1)) + Random(0, 9, 1) ) ;change the value of ___ _GuiCtrlEditFindText($Edit_1, $replace[2], 0, 0, 0, -1) For $a = $script[$i] To 0 Step -1 $num = $num + _GUICtrlEditLineLength($Edit_1, $a) ;_GUICtrlEditSetSel( Next Else EndIf Else EndIf Next EndFunc Func New() $savefirst = MsgBox(3, "Save first?", "Would you like to save first?") If $savefirst = 2 Then ;do nothing ElseIf $savefirst = 6 Then ;save Save() Sleep(100) GUICtrlSetData($Edit_1, "") ElseIf $savefirst = 7 Then GUICtrlSetData($Edit_1, "") EndIf EndFunc Func Save() $save_file = FileSaveDialog("Save a file...",$hlfol,"All (*.*)", 16, "MyScript.cfg") $script = StringSplit(GUICtrlRead($Edit_1),Chr(10)) _FileWriteFromArray($save_file, $script, 1) EndFunc Func CheckCustom() $script = StringSplit(GUICtrlRead($Edit_1),Chr(10)) For $i = 0 To $script[0] Step 1 If StringInStr($script[$i],"%r") Then Global $Custom = 1 Return True EndIf Next EndFunc Edit: StringRegExp? Must be in the beta, never heard of this. Is it substantially better then StringinStr? For my purposes as far as I can see StringInStr will work fine unless maybe StringRegExp will make it easier? Haven't found any documentation on it via search though... It's not under undocumented and the online page for it is blank... Edited December 9, 2006 by darkshadow791 Note Taker Lite - a note taking / converting tool. Link to comment Share on other sites More sharing options...
The Kandie Man Posted December 9, 2006 Share Posted December 9, 2006 Edit: StringRegExp? Must be in the beta, never heard of this. Is it substantially better then StringinStr? For my purposes as far as I can see StringInStr will work fine unless maybe StringRegExp will make it easier? Haven't found any documentation on it via search though... It's not under undocumented and the online page for it is blank...StringRegExp is in the beta and it is different from StringinStr. StringRegExp uses an external library that was compiled into autoit. It searches for Expression Patterns and is much faster than StringinStr, but you have to use it to search for patterns. The syntax to make it work is quite difficult to get the hang of. For something like a editor that replaces text, StringinStr should be sufficient. You may learn more about it by looking in the beta help file. It is much faster if you can get it to work for what you need.-The Kandie Man "So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now