darkshadow791 Posted December 12, 2006 Posted December 12, 2006 (edited) Hi, I am trying to make a note-pad like program but with one feature - to randomize all aliases for half-life scripts. Half life scripts basically look like this: alias <name of command> <do something here> example: alias "shoot" "+attack" or alias shoot "+attack" or alias +shoot "+attack" or alias -shoot "+attack" (the +/- can have quotes around it also) What I want to achieve: Whenever I click on Edit>Randomize, it will search for all alias names and add a set of random number/chars to the beginning. Now, it's 99% done, however, if someone has an alias named, say, +alias1 and -alias1 they need to both have the SAME random on them, and keep the +/- in the beginning, but not have the same random as something named alias1 (without +/-) Not really sure how to go about this. Any support on it will be very appreciated. Entire script to date: expandcollapse popup#compiler_icon = C:\Program Files\AutoIt3\Icons\filetype-blank.ico #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!", 0, 0, 400, 300) $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") $B_Rand = GUICtrlCreateMenuitem("Randomize!", $M_Edit) GUICtrlCreateMenuitem("", $M_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) GUICtrlCreateMenuitem("", $M_Edit) $M_Find = GUICtrlCreateMenuitem("Find", $M_Edit) $M_Replace = GUICtrlCreateMenuitem("Replace", $M_Edit) GUICtrlCreateMenuitem("", $M_Edit) $M_SelectAll = GUICtrlCreateMenuitem("Select All", $M_Edit) GUICtrlCreateMenuitem("", $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 GuiSetState() While 1 $msg = GuiGetMsg() Switch $msg Case $GUI_EVENT_CLOSE _Exit() Case $B_Rand Randomize() 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(10) Send(_Now(), 1) Case $M_Undo ;Sleep(100) _GUICtrlEditUndo($Edit_1) Case Else ;;; EndSwitch WEnd Exit Func Randomize() $num = 0 ;$file = FileOpen("file.txt", 2) ;$lines = _GUICtrlEditGetLineCount($Edit_1) $script = StringSplit(GUICtrlRead($Edit_1),Chr(10)) Dim $newscript[$script[0]] For $i = 0 To $script[0] Step 1 If StringInStr($script[$i],"alias") Then $replace = StringSplit($script[$i]," ") Local $s_ReadEditData $s_ReadEditData = GUICtrlRead($Edit_1) If StringInStr($replace[2],"_") Then ;do nothing! Else If StringInStr($replace[2],'"') Then $s_searchstring = StringTrimRight(StringTrimLeft($replace[2],1),1) If StringInStr($replace[2],"+") Then $s_replacestring = String(("+" & Chr(Random(Asc("a"), Asc("z"), 1))) & Random(0, 9, 1) & Chr(Random(Asc("a"), Asc("z"), 1)) & Random(0, 9, 1) & "_" & StringTrimLeft($s_searchstring, 1)) ElseIf StringInStr($replace[2],"-") Then $s_replacestring = String(("-" & Chr(Random(Asc("a"), Asc("z"), 1))) & Random(0, 9, 1) & Chr(Random(Asc("a"), Asc("z"), 1)) & Random(0, 9, 1) & "_" & StringTrimLeft($s_searchstring, 1)) Else $s_replacestring = String(( Chr(Random(Asc("a"), Asc("z"), 1))) & Random(0, 9, 1) & Chr(Random(Asc("a"), Asc("z"), 1)) & Random(0, 9, 1) & "_" & $s_searchstring) EndIf Else $s_searchstring = $replace[2] If StringInStr($replace[2],"+") Then $s_replacestring = String(("+" & Chr(Random(Asc("a"), Asc("z"), 1))) & Random(0, 9, 1) & Chr(Random(Asc("a"), Asc("z"), 1)) & Random(0, 9, 1) & "_" & StringTrimLeft($s_searchstring, 1)) ElseIf StringInStr($replace[2],"-") Then $s_replacestring = String(("+" & Chr(Random(Asc("a"), Asc("z"), 1))) & Random(0, 9, 1) & Chr(Random(Asc("a"), Asc("z"), 1)) & Random(0, 9, 1) & "_" & StringTrimLeft($s_searchstring, 1)) Else $s_replacestring = String(( Chr(Random(Asc("a"), Asc("z"), 1))) & Random(0, 9, 1) & Chr(Random(Asc("a"), Asc("z"), 1)) & Random(0, 9, 1) & "_" & $s_searchstring) EndIf EndIf ;$s_replacestring = String(( Chr(Random(Asc("a"), Asc("z"), 1))) & Random(0, 9, 1) & Chr(Random(Asc("a"), Asc("z"), 1)) & Random(0, 9, 1) & "_" & $replace[2]) ;String($replace & (Chr(Random(Asc("a"), Asc("z"),1) ) ) & Random(0, 9, 1) & GUICtrlSetData($Edit_1,StringReplace($s_ReadEditData,$s_searchstring,$s_replacestring)) EndIf 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") If $save_file == "" Then $savesure = MsgBox(4,"Error!","Invalid save! Do you wish to save?") If $savesure == 6 Then Save() EndIf EndIf $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 ExitLoop EndIf Next Return False EndFunc Func About() MsgBox(0,"Random Scripter v1.0","Random Scripter v1.0" & @CRLF & "Made by DarkShadow" & @CRLF & @CRLF & @CRLF & "Visit www.vacdisabled.net") EndFunc Func Help() MsgBox(0,"Help","This works a lot like Notepad." & @CRLF & "Just type in your script and when you are done," & @CRLF & "Go to edit>Randomize" & @CRLF & "And all your aliases will be randomized!" & @CRLF & @CRLF & @CRLF & @CRLF & "NOTE!: This is a beta version" & @CRLF & "There may be bugs" & @CRLF & "Also, I don't suggest randomizing your script after" & @CRLF & "you have already randomized it") EndFunc Func _Exit() $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) Exit ElseIf $savefirst = 7 Then Exit EndIf EndFunc Func Pause() Sleep(10) EndFunc (Ignore the Checkcustom func, it isn't used yet) Thanks. (The Randomize() function is the one that needs fixing, everything else works) Edited December 12, 2006 by darkshadow791 Note Taker Lite - a note taking / converting tool.
darkshadow791 Posted December 13, 2006 Author Posted December 13, 2006 *Bump* Nothing? Note Taker Lite - a note taking / converting tool.
Stumpii Posted December 13, 2006 Posted December 13, 2006 *Bump*Nothing?Sounds like you could create load the file into an array say 'LinesArray' and create an array of processed aliases 'ProcessedItems'.Step through each item in LinesArray and see if the alias exists in ProcessedItems. If it does, skip to the next line of LinesArray. If it does not, create the random part and go through the original file line by line, changing the alias to the new random one. Once finished, go to the next item in LinesArray.This will change all aliases to be the same. Give a man a script; you have helped him for today. Teach a man to script; and you will not have to hear him whine for help.AutoIt4UE - Custom AutoIt toolbar and wordfile for UltraEdit/UEStudio users.AutoIt Graphical Debugger - A graphical debugger for AutoIt.SimMetrics COM Wrapper - Calculate string similarity.
darkshadow791 Posted December 13, 2006 Author Posted December 13, 2006 Erm thanks for the help but I wound up finding another way to do it. Problem solved... Note Taker Lite - a note taking / converting tool.
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