View difference between Paste ID: SyAPRQqW and yGfZXXUy
SHOW: | | - or go back to the newest paste.
1
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
2
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
3
4-
#1..8 | ForEach {Get-Random -Minimum 1 -Maximum 20}
4+
5
#$Items = Roll-Dice
6
7
# Roll 4 6-Sided Dice, drop the lowest and add together.
8
Function Roll-Dice()
9
    {
10
    $Top3 = 1..4 | foreach {Get-Random -min 1 -max 7} | Sort -Descending | Select -First 3
11
    $TOPROLL = $Top3[0] + $Top3[1] + $Top3[2]
12
    Invoke-Expression -command $TOPROLL
13-
$Items = Roll-Dice
13+
14
15
Function Roll-Dice8times()
16
    {
17-
$objForm.Size = New-Object System.Drawing.Size(380,300)
17+
    Invoke-Expression -command "1..8 | foreach {Get-Random -Minimum 3 -Maximum 18}"
18
    }
19
20
21
22
#Build the Window
23
$objForm = New-Object System.Windows.Forms.Form
24
$objForm.Text = "Take Hitpoints"
25
$objForm.Size = New-Object System.Drawing.Size(380,400)
26
$objForm.StartPosition = "CenterScreen"
27
$objForm.KeyPreview = $True
28
29
# Dice Roll Labels
30
    $objStrRollLabel = New-Object System.Windows.Forms.Label
31
    $objStrRollLabel.Location = New-Object System.Drawing.Size(50,15)
32
    $objStrRollLabel.Size = New-Object System.Drawing.Size(30,15)
33
    $objStrRollLabel.Text = "Str"
34
    $objForm.Controls.Add($objStrRollLabel)
35
36
    $objConRollLabel = New-Object System.Windows.Forms.Label
37
    $objConRollLabel.Location = New-Object System.Drawing.Size(100,15)
38
    $objConRollLabel.Size = New-Object System.Drawing.Size(30,15)
39
    $objConRollLabel.Text = "Con"
40
    $objForm.Controls.Add($objConRollLabel)
41
42
    $objIntRollLabel = New-Object System.Windows.Forms.Label
43
    $objIntRollLabel.Location = New-Object System.Drawing.Size(150,15)
44
    $objIntRollLabel.Size = New-Object System.Drawing.Size(30,15)
45
    $objIntRollLabel.Text = "Int"
46
    $objForm.Controls.Add($objIntRollLabel)
47
48
    $objWisRollLabel = New-Object System.Windows.Forms.Label
49
    $objWisRollLabel.Location = New-Object System.Drawing.Size(200,15)
50
    $objWisRollLabel.Size = New-Object System.Drawing.Size(30,15)
51
    $objWisRollLabel.Text = "Wis"
52
    $objForm.Controls.Add($objWisRollLabel)
53
    
54
    $objChaRollLabel = New-Object System.Windows.Forms.Label
55
    $objChaRollLabel.Location = New-Object System.Drawing.Size(250,15)
56
    $objChaRollLabel.Size = New-Object System.Drawing.Size(30,15)
57
    $objChaRollLabel.Text = "Cha"
58
    $objForm.Controls.Add($objChaRollLabel)
59
    
60
    $objDexRollLabel = New-Object System.Windows.Forms.Label
61-
    $objStrRoll.Size = New-Object System.Drawing.Size(30,20)
61+
62
    $objDexRollLabel.Size = New-Object System.Drawing.Size(30,15)
63
    $objDexRollLabel.Text = "Dex"
64
    $objForm.Controls.Add($objDexRollLabel)
65
    
66-
    $objConRoll.Size = New-Object System.Drawing.Size(30,20)
66+
67
    $objStrRoll = New-Object System.Windows.Forms.Listbox
68
    $objStrRoll.Location = New-Object System.Drawing.Size(50,40)
69
    $objStrRoll.Size = New-Object System.Drawing.Size(30,120)
70
    $objForm.Controls.Add($objStrRoll)
71-
    $objIntRoll.Size = New-Object System.Drawing.Size(30,20)
71+
72
    $objConRoll = New-Object System.Windows.Forms.Listbox
73
    $objConRoll.Location = New-Object System.Drawing.Size(100,40)
74
    $objConRoll.Size = New-Object System.Drawing.Size(30,120)
75
    $objForm.Controls.Add($objConRoll)
76-
    $objWisRoll.Size = New-Object System.Drawing.Size(30,20)
76+
77
    $objIntRoll = New-Object System.Windows.Forms.Listbox
78
    $objIntRoll.Location = New-Object System.Drawing.Size(150,40)
79
    $objIntRoll.Size = New-Object System.Drawing.Size(30,120)
80
    $objForm.Controls.Add($objIntRoll)
81-
    $objChaRoll.Size = New-Object System.Drawing.Size(30,20)
81+
82
    $objWisRoll = New-Object System.Windows.Forms.Listbox
83
    $objWisRoll.Location = New-Object System.Drawing.Size(200,40)
84
    $objWisRoll.Size = New-Object System.Drawing.Size(30,120)
85
    $objForm.Controls.Add($objWisRoll)
86-
    $objDexRoll.Size = New-Object System.Drawing.Size(30,20)
86+
87
    $objChaRoll = New-Object System.Windows.Forms.Listbox
88
    $objChaRoll.Location = New-Object System.Drawing.Size(250,40)
89
    $objChaRoll.Size = New-Object System.Drawing.Size(30,120)
90
    $objForm.Controls.Add($objChaRoll)
91
    
92
    $objDexRoll = New-Object System.Windows.Forms.Listbox
93
    $objDexRoll.Location = New-Object System.Drawing.Size(300,40)
94
    $objDexRoll.Size = New-Object System.Drawing.Size(30,120)
95
    $objForm.Controls.Add($objDexRoll)
96
97
# Dice Roll Clicks
98
# These will clear what was selected before and then input the new selection.
99
    #Str
100
    $objStrRoll.Add_Click(
101
        {
102
        $cmdlet = $objStrRoll.SelectedItem
103
        $objStatStr.Items.Clear()
104
        
105
        If ($cmdlet –ne $Null){[void] $objStatStr.Items.Add($cmdlet)}
106
        })
107
    #Con
108
    $objConRoll.Add_Click(
109
        {
110
        $cmdlet = $objConRoll.SelectedItem
111
        $objStatCon.Items.Clear()
112
        
113
        If ($cmdlet –ne $Null){[void] $objStatCon.Items.Add($cmdlet)}
114
        })
115
    #Int
116
    $objIntRoll.Add_Click(
117
        {
118
        $cmdlet = $objIntRoll.SelectedItem
119
        $objStatInt.Items.Clear()
120
        
121
        If ($cmdlet –ne $Null){[void] $objStatInt.Items.Add($cmdlet)}
122
        })
123
    #Wis
124
    $objWisRoll.Add_Click(
125
        {
126
        $cmdlet = $objWisRoll.SelectedItem
127
        $objStatWis.Items.Clear()
128
        
129
        If ($cmdlet –ne $Null){[void] $objStatWis.Items.Add($cmdlet)}
130
        })
131
    #Cha
132
    $objChaRoll.Add_Click(
133
        {
134
        $cmdlet = $objChaRoll.SelectedItem
135
        $objStatCha.Items.Clear()
136
        
137
        If ($cmdlet –ne $Null){[void] $objStatCha.Items.Add($cmdlet)}
138
        })
139-
    $DiceRollButton = New-Object System.Windows.Forms.Button
139+
    #Dex    
140-
    $DiceRollButton.Location = New-Object System.Drawing.Size(280,80)
140+
141-
    $DiceRollButton.Size = New-Object System.Drawing.Size(50,23)
141+
142-
    $DiceRollButton.Text = "Roll All"
142+
143-
    $DiceRollButton.Add_Click(
143+
144
        
145
        If ($cmdlet –ne $Null){[void] $objStatDex.Items.Add($cmdlet)}
146
        })
147
    
148
# Buttons
149
    #Button 1
150-
        foreach ($item in Roll-Dice){[void] $objStrRoll.Items.Add($item)}
150+
    $StatRollButton = New-Object System.Windows.Forms.Button
151-
        foreach ($item in Roll-Dice){[void] $objConRoll.Items.Add($item)}
151+
    $StatRollButton.Location = New-Object System.Drawing.Size(200,210)
152-
        foreach ($item in Roll-Dice){[void] $objIntRoll.Items.Add($item)}
152+
    $StatRollButton.Size = New-Object System.Drawing.Size(100,20)
153-
        foreach ($item in Roll-Dice){[void] $objWisRoll.Items.Add($item)}
153+
    $StatRollButton.Text = "Clear and Roll"
154-
        foreach ($item in Roll-Dice){[void] $objChaRoll.Items.Add($item)}
154+
    $StatRollButton.Add_Click(
155-
        ForEach ($item in Roll-Dice){[void] $objDexRoll.Items.Add($item)}
155+
156
        #Clear Selected Stats
157-
    $objForm.Controls.Add($DiceRollButton)
157+
158
        #Clear all current rolls
159
        $objStrRoll.Items.Clear();$objConRoll.Items.Clear();$objIntRoll.Items.Clear();$objWisRoll.Items.Clear();$objChaRoll.Items.Clear();$objDexRoll.Items.Clear()
160
        #Populate new rolls for all stat roll fields
161
        foreach ($item in Roll-Dice){[void] $objStatStr.Items.Add($item)}
162-
    $objStatStrLabel.Location = New-Object System.Drawing.Size(20,90)
162+
        foreach ($item in Roll-Dice){[void] $objStatCon.Items.Add($item)}
163
        foreach ($item in Roll-Dice){[void] $objStatInt.Items.Add($item)}
164
        foreach ($item in Roll-Dice){[void] $objStatWis.Items.Add($item)}
165
        foreach ($item in Roll-Dice){[void] $objStatCha.Items.Add($item)}
166
        foreach ($item in Roll-Dice){[void] $objStatDex.Items.Add($item)}
167
        })
168-
    $objStatConLabel.Location = New-Object System.Drawing.Size(20,120)
168+
    $objForm.Controls.Add($StatRollButton)
169
170
    #Button 2
171
    $StatRoll8Button = New-Object System.Windows.Forms.Button
172
    $StatRoll8Button.Location = New-Object System.Drawing.Size(200,180)
173
    $StatRoll8Button.Size = New-Object System.Drawing.Size(140,20)
174-
    $objStatIntLabel.Location = New-Object System.Drawing.Size(20,150)
174+
    $StatRoll8Button.Text = "Clear and Roll 8 times"
175
    $StatRoll8Button.Add_Click(
176
        {
177
        #Clear Selected Stats
178
        $objStatStr.Items.Clear();$objStatCon.Items.Clear();$objStatInt.Items.Clear();$objStatWis.Items.Clear();$objStatCha.Items.Clear();$objStatDex.Items.Clear()  
179
        #Clear all current rolls
180-
    $objStatWisLabel.Location = New-Object System.Drawing.Size(20,180)
180+
181
        #Populate new rolls for all stat roll fields
182
        foreach ($item in Roll-Dice8times){[void] $objStrRoll.Items.Add($item)}
183
        foreach ($item in Roll-Dice8times){[void] $objConRoll.Items.Add($item)}
184
        foreach ($item in Roll-Dice8times){[void] $objIntRoll.Items.Add($item)}
185
        foreach ($item in Roll-Dice8times){[void] $objWisRoll.Items.Add($item)}
186-
    $objStatChaLabel.Location = New-Object System.Drawing.Size(20,210)
186+
        foreach ($item in Roll-Dice8times){[void] $objChaRoll.Items.Add($item)}
187
        ForEach ($item in Roll-Dice8times){[void] $objDexRoll.Items.Add($item)}
188
        })
189
    $objForm.Controls.Add($StatRoll8Button)
190
191
# Stat Labels
192-
    $objStatDexLabel.Location = New-Object System.Drawing.Size(20,240)
192+
193
    $objStatStrLabel = New-Object System.Windows.Forms.Label
194
    $objStatStrLabel.Location = New-Object System.Drawing.Size(20,170)
195
    $objStatStrLabel.Size = New-Object System.Drawing.Size(25,20)
196
    $objStatStrLabel.Text = "Str"
197
    $objForm.Controls.Add($objStatStrLabel)
198
199
    $objStatConLabel = New-Object System.Windows.Forms.Label
200-
    $objStatStr.Location = New-Object System.Drawing.Size(50,90)
200+
    $objStatConLabel.Location = New-Object System.Drawing.Size(20,200)
201
    $objStatConLabel.Size = New-Object System.Drawing.Size(25,20)
202
    $objStatConLabel.Text = "Con"
203
    $objForm.Controls.Add($objStatConLabel)
204
    
205-
    $objStatCon.Location = New-Object System.Drawing.Size(50,120)
205+
206
    $objStatIntLabel.Location = New-Object System.Drawing.Size(20,230)
207
    $objStatIntLabel.Size = New-Object System.Drawing.Size(25,20)
208
    $objStatIntLabel.Text = "Int"
209
    $objForm.Controls.Add($objStatIntLabel)
210-
    $objStatInt.Location = New-Object System.Drawing.Size(50,150)
210+
211
    $objStatWisLabel = New-Object System.Windows.Forms.Label
212
    $objStatWisLabel.Location = New-Object System.Drawing.Size(20,260)
213
    $objStatWisLabel.Size = New-Object System.Drawing.Size(25,20)
214
    $objStatWisLabel.Text = "Wis"
215-
    $objStatWis.Location = New-Object System.Drawing.Size(50,180)
215+
216
217
    $objStatChaLabel = New-Object System.Windows.Forms.Label
218
    $objStatChaLabel.Location = New-Object System.Drawing.Size(20,290)
219
    $objStatChaLabel.Size = New-Object System.Drawing.Size(25,20)
220-
    $objStatCha.Location = New-Object System.Drawing.Size(50,210)
220+
221
    $objForm.Controls.Add($objStatChaLabel)
222
    
223
    $objStatDexLabel = New-Object System.Windows.Forms.Label
224
    $objStatDexLabel.Location = New-Object System.Drawing.Size(20,320)
225-
    $objStatDex.Location = New-Object System.Drawing.Size(50,240)
225+
226
    $objStatDexLabel.Text = "Dex"
227
    $objForm.Controls.Add($objStatDexLabel)
228
    
229
# Stat Fields
230
# This sites to the right of the Stat Label
231
    $objStatStr = New-Object System.Windows.Forms.Listbox
232
    $objStatStr.Location = New-Object System.Drawing.Size(50,170)
233
    $objStatStr.Size = New-Object System.Drawing.Size(40,20)
234
    $objForm.Controls.Add($objStatStr) 
235
236
    $objStatCon = New-Object System.Windows.Forms.Listbox
237
    $objStatCon.Location = New-Object System.Drawing.Size(50,200)
238
    $objStatCon.Size = New-Object System.Drawing.Size(40,20)
239
    $objForm.Controls.Add($objStatCon) 
240
241
    $objStatInt = New-Object System.Windows.Forms.Listbox
242
    $objStatInt.Location = New-Object System.Drawing.Size(50,230)
243
    $objStatInt.Size = New-Object System.Drawing.Size(40,20)
244
    $objForm.Controls.Add($objStatInt) 
245
246
    $objStatWis = New-Object System.Windows.Forms.Listbox
247
    $objStatWis.Location = New-Object System.Drawing.Size(50,260)
248
    $objStatWis.Size = New-Object System.Drawing.Size(40,20)
249
    $objForm.Controls.Add($objStatWis) 
250
    
251
    $objStatCha = New-Object System.Windows.Forms.Listbox
252
    $objStatCha.Location = New-Object System.Drawing.Size(50,290)
253
    $objStatCha.Size = New-Object System.Drawing.Size(40,20)
254
    $objForm.Controls.Add($objStatCha) 
255
    
256
    $objStatDex = New-Object System.Windows.Forms.Listbox
257
    $objStatDex.Location = New-Object System.Drawing.Size(50,320)
258
    $objStatDex.Size = New-Object System.Drawing.Size(40,20)
259
    $objForm.Controls.Add($objStatDex) 
260
261
$objForm.Add_Shown({$objForm.Activate()})
262
[void] $objForm.ShowDialog()