Created
October 2, 2019 19:06
-
-
Save FriedrichWeinmann/6598691086eba074408588693643c854 to your computer and use it in GitHub Desktop.
The one command a P&P RPG player needs from PowerShell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ExecutionContext.InvokeCommand.CommandNotFoundAction = { | |
param ( | |
[string] | |
$CommandName, | |
[System.Management.Automation.CommandLookupEventArgs] | |
$Lookup | |
) | |
if ($CommandName -match '^(\d+)[WD](\d+)$') | |
{ | |
$Lookup.StopSearch = $true | |
$Lookup.Command = (Get-Command Invoke-DiceRoll) | |
$Lookup.CommandScriptBlock = [scriptblock]::Create("Invoke-DiceRoll -Count $($matches[1]) -Size $($matches[2])") | |
} | |
} | |
function Invoke-DiceRoll | |
{ | |
[CmdletBinding()] | |
param ( | |
[int] | |
$Count = 1, | |
[int] | |
$Size = 20 | |
) | |
$results = foreach ($number in (1 .. $Count)) | |
{ | |
1..$Size | Get-Random | |
} | |
($results | Measure-Object -Sum).Sum | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment