Компьютерный форум OSzone.net  

Компьютерный форум OSzone.net (http://forum.oszone.net/index.php)
-   Скриптовые языки администрирования Windows (http://forum.oszone.net/forumdisplay.php?f=102)
-   -   [решено] Изменение строки файла при запуске скрипта (http://forum.oszone.net/showthread.php?t=295593)

kot318 16-02-2015 10:12 2471825

Изменение строки файла при запуске скрипта
 
Здравствуйте, имеется текстовый файл G:\css\cstrike\config.cfg
необходимо каждый раз при запуске скрипта изменять строку 149
name "grey"
На строки: name "grey",name "silver",name "blue",name "red",name "yellow"
В произвольном порядке

Подскажите пожалуйста как сделать

Код:

// This file is overwritten whenever you change your user settings in the game.
// Add custom configurations to the file "userconfig.cfg".

unbindall
bind "TAB" "+showscores"
bind "ENTER" "+attack"
bind "ESCAPE" "cancelselect"
bind "SPACE" "+jump"
bind "'" "+moveup"
bind "+" "sizeup"
bind "," "buyammo1"
bind "-" "sizedown"
bind "." "buyammo2"
bind "/" "+movedown"
bind "0" "slot10"
bind "1" "slot1"
bind "2" "slot2"
bind "3" "slot3"
bind "4" "slot4"
bind "5" "slot5"
bind "6" "slot6"
bind "7" "slot7"
bind "8" "slot8"
bind "9" "slot9"
bind ";" "+mlook"
bind "=" "sizeup"
bind "[" "invprev"
bind "]" "invnext"
bind "`" "toggleconsole"
bind "a" "+moveleft"
bind "b" "buy"
bind "c" "radio3"
bind "d" "+moveright"
bind "e" "+use"
bind "f" "impulse 100"
bind "g" "drop"
bind "h" "+commandmenu"
bind "i" "showbriefing"
bind "j" "cheer"
bind "k" "+voicerecord"
bind "l" "+duck"
bind "m" "chooseteam"
bind "n" "nightvision"
bind "o" "buyequip"
bind "q" "slot4"
bind "r" "+reload"
bind "s" "+back"
bind "t" "impulse 201"
bind "u" "messagemode2"
bind "w" "+forward"
bind "x" "radio2"
bind "y" "messagemode"
bind "z" "radio1"
bind "~" "toggleconsole"
bind "UPARROW" "+forward"
bind "DOWNARROW" "+back"
bind "LEFTARROW" "+left"
bind "RIGHTARROW" "+right"
bind "ALT" "+strafe"
bind "CTRL" "+duck"
bind "SHIFT" "+speed"
bind "F1" "vesthelm;d3au1;primammo;hegren;flash;flash"
bind "F2" "vesthelm;ak47;primammo;hegren;flash;flash"
bind "F5" "snapshot"
bind "F6" "save quick"
bind "F7" "load quick"
bind "F9" "mhjzvkazdlF9"
bind "F10" "mhjzvkazdlF10"
bind "F11" "mhjzvkazdlF11"
bind "F12" "mhjzvkazdlF12"
bind "INS" "mhjzvkazdlINS"
bind "DEL" "mhjzvkazdlDEL"
bind "PGDN" "+lookdown"
bind "PGUP" "+lookup"
bind "HOME" "mhjzvkazdlHOME"
bind "END" "mhjzvkazdlEND"
bind "MWHEELDOWN" "invnext"
bind "MWHEELUP" "invprev"
bind "MOUSE1" "+attack;vmodenable"
bind "MOUSE2" "+attack2"
bind "PAUSE" "pause"
_cl_autowepswitch "1"
_snd_mixahead "0.1"
ati_npatch "1.0"
ati_subdiv "2.0"
bgmvolume "1.000000"
bottomcolor "6"
brightness "2"
cl_allowdownload "1"
cl_allowupload "1"
cl_backspeed "400"
cl_cmdbackup "2"
cl_cmdrate "40"
cl_corpsestay "600.000000"
cl_crosshair_color "50 250 50"
cl_crosshair_size "large"
cl_crosshair_translucent "0"
cl_dlmax "128"
cl_download_ingame "1"
cl_dynamiccrosshair "1"
cl_forwardspeed "400"
cl_himodels "0"
cl_idealpitchscale "0.8"
cl_lc "1"
cl_logocolor "#Valve_Brown"
cl_logofile "splatt"
cl_lw "1"
cl_minmodels "0"
cl_radartype "0"
cl_righthand "1"
cl_shadows "1"
cl_timeout "300"
cl_updaterate "30"
cl_vsmoothing "0.05"
cl_weather "1"
con_color "255 180 30"
console "1.000000"
crosshair "1.000000"
fastsprites "0"
fps_max "100"
fps_modem "0.0"
gamma "2.800000"
gl_dither "1"
gl_flipmatrix "0"
gl_fog "1"
gl_monolights "0"
gl_overbright "1"
gl_polyoffset "-0.001"
hisound "0"
hpk_maxsize "4"
hud_capturemouse "1"
hud_centerid "1"
hud_draw "1"
hud_fastswitch "1"
hud_saytext_internal "1"
hud_takesshots "0"
joystick "0"
lookspring "0.000000"
lookstrafe "0.000000"
m_filter "1"
m_forward "1"
m_pitch "0.022"
m_side "0.8"
m_yaw "0.022"
model "gordon"
MP3FadeTime "2.0"
MP3Volume "0"
mp_decals "300.000000"
name "grey"
net_graph "0"
net_graphpos "1"
net_scale "5"
r_bmodelhighfrac "5.0"
r_detailtextures "0"
s_a3d "0"
s_automax_distance "30.0"
s_automin_distance "2.0"
s_bloat "2.0"
s_distance "60"
s_doppler "0.0"
s_eax "0"
s_leafnum "0"
s_max_distance "1000.0"
s_min_distance "8.0"
s_numpolys "200"
s_polykeep "1000000000"
s_polysize "10000000"
s_refdelay "4"
s_refgain "0.4"
s_rolloff "1.0"
s_verbwet "0.25"
sensitivity "3.000000"
skin ""
spec_autodirector_internal "1"
spec_drawcone_internal "1"
spec_drawnames_internal "1"
spec_drawstatus_internal "1"
spec_mode_internal "3"
spec_pip "0"
suitvolume "0.250000"
sv_aim "0"
sv_voiceenable "1"
team ""
topcolor "30"
viewsize "120.000000"
voice_enable "1"
voice_forcemicrecord "1"
voice_modenable "1"
voice_scale "0.750000"
volume "0.980000"
setinfo "_vgui_menus" "1"
setinfo "_ah" "1"
setinfo "timepass" "nsvbmolmhm"
+mlook
exec userconfig.cfg


Iska 16-02-2015 10:48 2471838

Пробуйте:
Скрытый текст
Код:

Option Explicit

Dim strSourceFile
Dim arrNames
Dim strContent


strSourceFile = "G:\css\cstrike\config.cfg"

arrNames = Array("grey", "silver", "blue", "red", "yellow")

With WScript.CreateObject("Scripting.FileSystemObject")
        If .FileExists(strSourceFile) Then
                With .OpenTextFile(strSourceFile)
                        strContent = .ReadAll()
                        .Close
                End With
               
                With WScript.CreateObject("VBScript.RegExp")
                        .MultiLine = True
                        .IgnoreCase = True
                        .Pattern = "^(name +)(.*)$"
               
                        If .Test(strContent) Then
                                Randomize Timer
                               
                                strContent = .Replace(strContent, "$1""" & arrNames(Int((UBound(arrNames) - LBound(arrNames) + 1) * Rnd + LBound(arrNames))) & """")
                        Else
                                WScript.Echo "Can't find pattern [" & .Pattern & "] in source file [" & strSourceFile & "]."
                                WScript.Quit 2
                        End If
                End With
               
                With .CreateTextFile(strSourceFile, True)
                        strContent = .Write(strContent)
                        .Close
                End With
        Else
                WScript.Echo "Can't find source file [" & strSourceFile & "]."
                WScript.Quit 1
        End If
End With

WScript.Quit 0


kot318 16-02-2015 13:54 2471953

Спасибо, теперь имя автоматически меняется перед входом в Контр страйк, вот пример, может кому нибудь ещё пригодится.
Спасибо!!!!
А то не интересно под одним ником вечно играть.

1) Запускаем: start.bat
Код:

start /w wscript.exe "G:\css\start.vbs"
G:\css\hl.exe -game cstrike -steam -noforcemparms -noforcemaccel

2) start.vbs
Код:

Option Explicit

Dim strSourceFile
Dim arrNames
Dim strContent

strSourceFile = "G:\css\cstrike\config.cfg"

arrNames = Array(".mQ!", "coffee", "FasTiK", "oNe", "Sk1pe", "zEfN", "fromJkeee", "O_o", "LomaL cTek", "whOo", "aimbat", "QweRez", "icemaN", "Qqoffe", "Donjkeee", "Don1", "GaZ", "BeJIuKuu", "okeeey", "funny", "cerber", "efes", "R@MZE$$", "Arhangel", "maN1aK x_O", "furyy", "VeNoM1K", "Zoom^eR", "X-Team", "Z(o_O)M", "GamEOveR", "SurpriSe", "6y6JIuk", "4ekHyTbIu", "M@$ter Bit", "Quattro", "STRELOK", "Serial killer", "YAMAHA", "Loxnes", "Fatherv", "@RTEMK@", "BOND 007", "TauRus", "easy frag", "CuCe4Ka", "coco", "Pro100i", "~B@ND!T~", "6yM_6yM", "Inkognito", "BONGO", "Iguana", "3aHo3a", "policeman", "+Alucard+", "ANTILOL", "Dark", "Painkiller", "nTu4ko", "Fallen AngeL", "MiNi_ZLoB", "SPONGE BOB", "AnGeL", "S.T.A.L.K.E.R", "Сherry" )

With WScript.CreateObject("Scripting.FileSystemObject")
        If .FileExists(strSourceFile) Then
                With .OpenTextFile(strSourceFile)
                        strContent = .ReadAll()
                        .Close
                End With
               
                With WScript.CreateObject("VBScript.RegExp")
                        .MultiLine = True
                        .IgnoreCase = True
                        .Pattern = "^(name +)(.*)$"
               
                        If .Test(strContent) Then
                                Randomize Timer
                               
                                strContent = .Replace(strContent, "$1""" & arrNames(Int((UBound(arrNames) - LBound(arrNames) + 1) * Rnd + LBound(arrNames))) & """")
                        Else
                                WScript.Echo "Can't find pattern [" & .Pattern & "] in source file [" & strSourceFile & "]."
                                WScript.Quit 2
                        End If
                End With
               
                With .CreateTextFile(strSourceFile, True)
                        strContent = .Write(strContent)
                        .Close
                End With
        Else
                WScript.Echo "Can't find source file [" & strSourceFile & "]."
                WScript.Quit 1
        End If
End With

WScript.Quit 0


Iska 16-02-2015 22:24 2472193

kot318, старайтесь не использовать имён пакетных файлов и скриптов, совпадающих с внутренними или внешними командами. Замените «start» в «start.bat» и «start.vbs» на что-либо иное.


Время: 00:44.

Время: 00:44.
© OSzone.net 2001-