|
Answer» I need to know if there is a command to use
i have
Code: [Select]:[email protected] echo %username% has joined >> %cd%\Rooms\C\Logs\log.txt :chat set in=0 CLS type %cd%\Rooms\C\Logs\log.txt set /p in=Say: :CmdIF
::No entry refresh if %in%==0 ( goto chat ) ::
::Change Username if %in%==Nick ( Call Nick.bat ) Thats only a snippit of code %in% will be like Nick Awash and Awash can change. Any help is accepted. If i dont reply right away im proably working on the code you gave me.Also i would like to know how to seperate Nick from the username they wanna change to
(this is not changing the windows %user% its changing a chat username
Nick.bat
Code: [Select]Set Username=%in%-Nick rename %user12%.bat "%username%.bat" User12 is used in other part of codeIf "Nick" is always at the beginning of the name, you can simply parse the VARIABLE and you should be ABLE to grab "Nick". An example would be:
Code: [Select]if /i "%in:~0,4%"=="Nick" (call Nick.bat) If it is not always at the beginning, then you can try to use the find command to see if a string contains "Nick". The FOR command would be how you would seperate the username. Examples:
Code: [Select]echo %in% | find "Nick" if errorlevel 0 call Nick.bat
Code: [Select]for /f "tokens=1*" %%A in ("%in%") do set Username=%%B ren "%user12%.bat" "%username%.bat"
Quote from: Raven19528 on January 10, 2012, 10:01:03 AM you can try to use the find command to see if a string contains "Nick".
You can pipe to find and CHECK the errorlevel all in one line with the && operator.
command1 && command2 (execute command1 and if the errorlevel is 0 execute command2. The opposite is a double pipe: command1 || command2 means execute command1 and if the errorlevel is not zero, execute command2)
Code: [Select]echo %in% | find "Nick" && call Nick.bat
Quote from: Raven19528 on January 10, 2012, 10:01:03 AMIf "Nick" is always at the beginning of the name, you can simply parse the variable and you should be able to grab "Nick". An example would be:
Code: [Select]if /i "%in:~0,4%"=="Nick" (call Nick.bat) If it is not always at the beginning, then you can try to use the find command to see if a string contains "Nick". The FOR command would be how you would seperate the username. Examples:
Code: [Select]echo %in% | find "Nick" if errorlevel 0 call Nick.bat
Code: [Select]for /f "tokens=1*" %%A in ("%in%") do set Username=%%B ren "%user12%.bat" "%username%.bat"
Okay i tried this but it sets the username to nick
I WANT to take nick out of the variable so Bob can say Nick Bobby and his name becomes bobby ( sets variable username to bobby )and not Nick BobbyYou did know that %username% is already used by Windows? Why don't you use a different variable name?
Try "%NoNick%", or something similar. The more creative you can become with your variables, the less of a chance you have of running into already taken variables.
Alternatively you can grab a list of all of the variables that already EXIST by typing set into your cmd prompt.
|