1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: Batch File - Changing code based on user imput

Discussion in 'Software Development' started by luckyg141, Apr 4, 2010.

Thread Status:
Not open for further replies.
Advertisement
  1. luckyg141

    luckyg141 Thread Starter

    Joined:
    Apr 4, 2010
    Messages:
    4
    Basically I'm creating a Team Fortress 2 batch file that I can use as an admin to view demos in wireframe mode to detect wallhackers,

    what i want to be able to do is set up a option where a user can type a file name in, which is then used after they hit enter,

    for instance,

    I choose the start a team fortress demo in wireframe mode,

    I am then given the option to type the demos files name,

    This file name is then used in the launch option of team fortress 2 and loads up,

    I have included my batch file in a .txt format for you too see what I mean, (the bits I require help on is the bits in < >)

    Sorry if this is confusing, I'm just a beginner at creating batch files :)
     

    Attached Files:

  2. TheOutcaste

    TheOutcaste

    Joined:
    Aug 7, 2007
    Messages:
    9,028
    Welcome to TSG!

    This assumes the Demo files are in the same folder as Steam.exe. If not, change the path for the _SteamDemoPath variable:

    Changes I added are in Red. On the dods and dodswire you have the file name test instead of <filename>, but still had the <User Types Filename> indicated, so I replaced it with the file name variable as well.

    Code:
    @echo off
    COLOR F1
    title GTFOGaming Admin Demo Playback
    [COLOR=Red]Set _SteamPath=C:\Program Files (x86)\Steam
    Set _SteamDemoPath=C:\Program Files (x86)\Steam[/COLOR]
    :menu
    echo.
    echo What would you like to do?
    echo.
    echo Options:
    echo.
    echo 1.Open Team Fortress 2 Demo
    echo 2.Open Team Fortress 2 Demo In Wire Frame Mode
    echo 3.Open Day Of Defeat Demo
    echo 4.Open Day Of Defeat Demo In Wire Frame Mode
    echo 5.Open Counter Strike Demo
    echo 6.Open Counter Strike Demo In Wire Frame Mode
    echo 7.Quit
    echo.
    
    :choicegame
    set /P C=Pick A Number And Hit Enter:
    [COLOR=Red]If "%C%" GTR "7" goto choicegame
    If "%C%" LEQ "0" goto choicegame[/COLOR]
    if "%C%"=="7" goto quit
    [COLOR=Red]:: Get file name
    :_EnterName
    set /P _FN=Enter a File Name and hit Enter:
    If "%_FN%"=="" Goto Quit
    If NOT Exist "%_SteamDemoPath%\%_FN%" Echo Unable to locate "%_SteamDemoPath%\%_FN%"&Goto :_EnterName[/COLOR]
    if "%C%"=="6" goto csswire
    if "%C%"=="5" goto css
    if "%C%"=="4" goto dodswire
    if "%C%"=="3" goto dods
    if "%C%"=="2" goto tf2wire
    if Not "%C%"=="1" goto choicegame
    
    :tf2
    start /d "%_SteamPath%" Steam.exe -applaunch 440 +playdemo [COLOR=Red]"%_FN%"[/COLOR] +r_drawothermodels 1
    goto menu
    
    :tf2wire
    start /d "%_SteamPath%" Steam.exe -applaunch 440 +playdemo [COLOR=Red]"%_FN%"[/COLOR] +r_drawothermodels 2
    goto menu
    
    :dods
    start /d "%_SteamPath%" Steam.exe -applaunch 300 +playdemo [COLOR=Red]"%_FN%"[/COLOR] +r_drawothermodels 1
    goto menu
    
    :dodswire
    start /d "%_SteamPath%" Steam.exe -applaunch 300 +playdemo [COLOR=Red]"%_FN%"[/COLOR] +r_drawothermodels 2
    goto menu
    
    :css
    start /d "%_SteamPath%" Steam.exe -applaunch 240 +playdemo [COLOR=Red]"%_FN%"[/COLOR] +r_drawothermodels 1
    goto menu
    
    :csswire
    start /d "%_SteamPath%" Steam.exe -applaunch 240 +playdemo [COLOR=Red]"%_FN%" [/COLOR]+r_drawothermodels 2
    goto menu
    
    :quit
    exit
    :end
     
  3. luckyg141

    luckyg141 Thread Starter

    Joined:
    Apr 4, 2010
    Messages:
    4
    thanks alot for that, it worked wonders :D
     
  4. luckyg141

    luckyg141 Thread Starter

    Joined:
    Apr 4, 2010
    Messages:
    4
    right im back again,

    i would like to change
    Code:
    Set _SteamPath=C:\Program Files (x86)\Steam
    Set _SteamDemoPath=C:\Program Files (x86)\Steam
    to a registry file, as currently this only works for other admins in my community that have steam installed in the same place

    however the reg key,
    Code:
    HKCU\Software\Valve\Steam\SteamPath
    changes based on where a user has steam installed,

    I was wondering how i could use this key instead of using what i have currently.
     
  5. TheOutcaste

    TheOutcaste

    Joined:
    Aug 7, 2007
    Messages:
    9,028
    Replace those two lines with this one:
    Code:
    For /F "Tokens=2* Skip= 2 Delims=" %%I In ('reg query "HKCU\Software\Valve\Steam" /v SteamPath') Do Set _SteamPath=%%J
    
    and replace _SteamDemoPath with _SteamPath
    Should end up with this:
    (I'm not sure if the line in red is needed. The path in the registry uses forward slashes, but Windows typically uses backslashes. It should work with either, but sometimes doesn't, so that line may be needed)
    Code:
    @echo off
    COLOR F1
    title GTFOGaming Admin Demo Playback
    For /F "Tokens=2* Skip=2" %%I In ('reg query "HKCU\Software\Valve\Steam" /v SteamPath') Do Set _SteamPath=%%J
    [COLOR=Red]Set _SteamPath=%_SteamPath:/=\%[/COLOR]
    :menu
    echo.
    echo What would you like to do?
    echo.
    echo Options:
    echo.
    echo 1.Open Team Fortress 2 Demo
    echo 2.Open Team Fortress 2 Demo In Wire Frame Mode
    echo 3.Open Day Of Defeat Demo
    echo 4.Open Day Of Defeat Demo In Wire Frame Mode
    echo 5.Open Counter Strike Demo
    echo 6.Open Counter Strike Demo In Wire Frame Mode
    echo 7.Quit
    echo.
    
    :choicegame
    set /P C=Pick A Number And Hit Enter:
    If "%C%" GTR "7" goto choicegame
    If "%C%" LEQ "0" goto choicegame
    if "%C%"=="7" goto quit
    :: Get file name
    :_EnterName
    set /P _FN=Enter a File Name and hit Enter:
    If "%_FN%"=="" Goto Quit
    If NOT Exist "%_SteamPath%\%_FN%" Echo Unable to locate "%_SteamPath%\%_FN%"&Goto :_EnterName
    if "%C%"=="6" goto csswire
    if "%C%"=="5" goto css
    if "%C%"=="4" goto dodswire
    if "%C%"=="3" goto dods
    if "%C%"=="2" goto tf2wire
    if Not "%C%"=="1" goto choicegame
    
    :tf2
    start /d "%_SteamPath%" Steam.exe -applaunch 440 +playdemo "%_FN%" +r_drawothermodels 1
    goto menu
    
    :tf2wire
    start /d "%_SteamPath%" Steam.exe -applaunch 440 +playdemo "%_FN%" +r_drawothermodels 2
    goto menu
    
    :dods
    start /d "%_SteamPath%" Steam.exe -applaunch 300 +playdemo "%_FN%" +r_drawothermodels 1
    goto menu
    
    :dodswire
    start /d "%_SteamPath%" Steam.exe -applaunch 300 +playdemo "%_FN%" +r_drawothermodels 2
    goto menu
    
    :css
    start /d "%_SteamPath%" Steam.exe -applaunch 240 +playdemo "%_FN%" +r_drawothermodels 1
    goto menu
    
    :csswire
    start /d "%_SteamPath%" Steam.exe -applaunch 240 +playdemo "%_FN%" +r_drawothermodels 2
    goto menu
    
    :quit
    exit
    :end
    
     
  6. luckyg141

    luckyg141 Thread Starter

    Joined:
    Apr 4, 2010
    Messages:
    4
    thanks for that,

    EDIT: nvm what i just posted, got it working, thanks :D
     
  7. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/914715

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice