Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- setlocal enableDelayedExpansion
- set /a prevRollCount=0
- set /a maxRolls=5
- set prevRoll[1]=
- :main
- cls
- set input=1d20
- echo ### D^&Dice ###
- echo.
- echo Type "p" to view previous rolls
- echo.
- echo Please type your dice ^(i.e. 3d8+5):
- echo Default is 1d20
- echo.
- set /p "input= "
- set dice=
- set sides=
- set add=
- if /i "%input%"=="p" goto previousRolls
- if /i "%input:~0,1%"=="d" set input=1%input%
- for /f "usebackq delims=d+ tokens=1,2,3*" %%a in ('%input%') do (
- set dice=%%a
- set sides=%%b
- set add=%%c
- )
- for /f "usebackq delims=- tokens=1,2*" %%a in ('%sides%') do (
- if NOT "%%b"=="" (
- set sides=%%a
- set /a add=%%b*-1
- )
- )
- set total=
- set str=
- set tempRollVal=
- if NOT "%dice%"=="" (
- if NOT "%sides%"=="" (
- call :roll "%dice%" "%sides%" "%add%" total str
- ) else (
- goto main
- )
- ) else (
- goto main
- )
- if NOT "%add%"=="" (
- set /a added=!total!+!add!
- if %dice% GTR 1 (
- echo ============= Roll Total
- echo !total!
- )
- if "%add:~0,1%"=="-" (
- echo ============= - %add:~1%
- set "str=!str! - !add:~1!"
- ) else (
- echo ============= + %add%
- set "str=!str! + !add!"
- )
- set "str=!str! = !added!"
- echo !added!
- ) else (
- if %dice% GTR 1 (
- echo ============= Roll Total
- echo !total!
- )
- set "str=!str! = !total!"
- )
- REM Let's add this to our previous roll list
- if %prevRollCount% LSS %maxRolls% (
- set /a prevRollCount+=1
- set "prevRoll[!prevRollCount!]=!str!"
- ) else (
- REM Iterate through the list, deleting the oldest
- for /l %%a in (1, 1, %maxRolls%-1) do (
- set /a nextRoll=%%a+1
- call :repRoll "%%a" "!nextRoll!"
- )
- set "prevRoll[%maxRolls%]=!str!"
- )
- echo.
- echo Press [enter] to return to the roll screen...
- pause > nul
- goto main
- :repRoll <num1> <num2>
- set "prevRoll[%~1]=!prevRoll[%~2]!"
- goto :EOF
- :roll <dice> <sides> <plus> <return> <string>
- setlocal enableDelayedExpansion
- set /a dice=%~1
- set /a sides=%~2
- set plus=
- if NOT "%~3"=="" (
- set test=%~3
- if "!test:~0,1!"=="-" (
- set "plus= - !test:~1!"
- ) else (
- set "plus= + %~3"
- )
- )
- set /a total=0
- set "str="
- if "%dice%"=="" set /a dice=1
- if "%sides%"=="" set /a sides=20
- set /a min=1
- cls
- echo ### Rolling %dice% %sides%-sided dice%plus% ###
- echo.
- for /l %%a in (1, 1, %dice%) do (
- call :random 1 %sides% return
- echo !return!
- if "!str!"=="" (
- set "str=[!return!"
- ) else (
- set "str=!str!, !return!"
- )
- set /a total+=!return!
- )
- set "str=!str!]"
- endlocal & (
- set total=%total%
- set str=%str%
- )
- set %~4=%total%
- set %~5=%str%
- exit /b
- :random <min> <max> <return>
- setlocal
- set /a rand=%RANDOM% * %~2 / 32768 + %~1
- endlocal & set %~3=%rand%
- exit /b
- :previousRolls
- cls
- echo ### Past Rolls ###
- echo.
- for /l %%a in (1, 1, %prevRollCount%) do (
- echo %%a. !prevRoll[%%a]!
- )
- echo.
- echo Press [enter] to return to the main menu...
- pause > nul
- goto main
Advertisement
Add Comment
Please, Sign In to add comment