Roll four, drop the lowest

I wanted to add some functionality that would replicate "Roll 4d6, drop the lowest" and make it good and generic. Here's what I came up with:
Table: Roller
Set: dice={$1}
Set: reps=[when]{$2}>0[do]{$2}[else]0[end]
Set: droplow=[when]{reps}=0[do]{droplow}[else][when]{$3}>0[do][{{$3}*10+1} >> trim][else]1[end][end]
Set: drophigh=[when]{reps}=0[do]{drophigh}[else][when]{$4}>0[do][{{$4}*10+1} >> trim][else]1[end][end]
Set: extraplus=[when]{reps}=0[do]{extraplus}[else][when]{$5}>0[do][{$5} >> trim][else]0[end][end]
[when]{reps}>0&
[do]{[[[@{reps} SubRoller with {dice} >> each Pad >> sort >> implode + ] >> reverse >> substr {drophigh} 0 >> reverse] >> substr {droplow} 0]+{extraplus}}&
[else]{{dice}}&
[end]

Table: SubRoller
{{dice}}


Table: Pad
[[000000000{$1} >> reverse] >> substr 1 9 >> reverse]


The parameters in order are:
dice - could be "1d6" or "2d8+1" or whatever; note that this is a change from an older version of Roller posted in another thread.
reps - how many times to roll the dice specified in the first parameter
droplow - number of low results to drop before totalling
drophigh - number of high results to drop before totalling
extraplus - amount to add (or possibly subtract) to the final after-dropping total

To get the results I originally wanted:
"Roll 1d6 four times, and drop the single lowest result before adding"

[@Roller with 1d6, 4, 1]

15
16
7
10
10

Something crazy:
"Roll 2d8+1 ten times, drop the two lowest and three highest results and subtract 3 from the total -- and do all that five times"

[@5 Roller with 2d8+1, 10, 2, 3, -3 >> implode]

42, 48, 53, 47, 46
53, 48, 40, 44, 47
37, 55, 55, 44, 48
55, 64, 43, 48, 57
42, 54, 39, 38, 64


More simple:
"Roll 1d10 20 times"

[@10 Roller with 1d10 >> implode]

6, 3, 10, 5, 4, 1, 4, 9, 8, 1
1, 5, 8, 4, 9, 6, 5, 4, 10, 6
5, 9, 5, 8, 5, 6, 8, 3, 10, 4
8, 7, 4, 10, 5, 2, 7, 4, 8, 7

One minor limitation -- if the result of {dice} might be a trillion or more (like 1000d9999999999) the dropper won't produce correct results.

Give it a try, and if you have any questions post it here!

Comments

  • That is really cool :-)
  • Is this the complete roller code? I copied and pasted into a generator and get (Invalid expression: ) as the result.
  • Hi chuqa,

    Sorry, I guess I skipped a step in my original description. If you just want to see Roller work, add this above all the other code:
    Table: RollerTest
    [@Roller with 1d6, 4, 1] 
    
  • good post but i want some change ......
  • Hi ashan, welcome to the forums!

    What change would you like to see?
  • Very, very nice!
    So if you need to roll up a D20 / D&D character it works like this:

    Table: D20Attributes
    [@6 Roller with 1d6, 4, 1 >> implode]
  • Alternon wrote:
    Very, very nice!
    So if you need to roll up a D20 / D&D character it works like this:

    Table: D20Attributes
    [@6 Roller with 1d6, 4, 1 >> implode]
    You got it! Glad you like it!

Leave a Comment