Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • Forum: Plugins
    In reply to: Dice Rolling Plugin

    😛

    until I get banned for using up bandwidth with useless code….

    (I actually have gotten some out-of-bounds values using this, so it is probably buggy – use in a campaign at your own risk…. beer drinking, club wielding barbarians might not think it’s funny to get a 2 when rolling 3d6 (with no modifers)…

    more user friendly:
    <?php
    // of the form 3d6+2
    function dice($arg){
    //var_dump($arg);
    $splitArg1 = preg_split("/d/", $arg);
    $num = $splitArg1[0];
    if(strstr($splitArg1[1], '+')){
    $splitArg2 = preg_split("/+/", $splitArg1[1]);
    $dice = $splitArg2[0];
    $mod = $splitArg2[1];
    } else if (strstr($splitArg1[1], '-')){
    $splitArg2 = preg_split("/-/", $splitArg1[1]);
    $dice = $splitArg2[0];
    $mod = - $splitArg2[1];
    } else {
    $dice = $splitArg1[1];
    $mod = 0;
    }
    $i=0;
    while ($i<$num){
    $roll[$i] = mt_rand(1, $dice);
    $i++;
    }
    $total=0;
    foreach($roll as $value){
    $total = $total + $value;
    }
    $total = $total + $mod;
    return $total;
    }
    echo(dice('3d6+4'));
    ?>

    Forum: Plugins
    In reply to: Dice Rolling Plugin

    in the post above, “twentyRolls” is just to give an idea of the variability.

    the function you would want would be dice();

    obviously, you could change the $_GET['variable'] to whatever you needed them to be, e.g.:
    dice(20, +5); //d20+5

    (equivalent to dice(20, 5);)

    of course, rereading your post, I see the requirement for multiple dice…

    here you go (bored and avioding work)

    <?php
    function dice($type, $modifier=0, $num=1){
    $i=0;
    while ($i<$num){
    $roll[$i] = mt_rand(1, $type) + $modifier;
    $i++;
    }
    $total=0;
    foreach($roll as $value){
    $total = $total + $value;
    }
    return $total;
    }
    echo(dice($_GET['d'], $_GET['mod'], $_GET['num']));
    ?>

    HTH,
    j.

    Forum: Plugins
    In reply to: Dice Rolling Plugin

    this should work:

    <?php
    function twentyRolls($type, $modifier=0){
    $i=1;
    while ($i <= 20){
    $output = mt_rand(1, $type) + $modifier;
    echo $i . ': ' . $output . '<br/>';
    $i++;
    }
    }
    twentyRolls($_GET['d'], $_GET['mod']);
    echo '<br/><br/>';
    function dice($type, $modifier=0){
    $output = mt_rand(1, $type) + $modifier;
    if ($modifier < 0){
    $modText = $modifier;
    } else {
    $modText = '+' . $modifier;
    }
    echo 'Die roll (d' . $type . ' ' . $modText . '): ' . $output . '<br/>';
    }
    dice($_GET['d'], $_GET['mod']);
    ?>

Viewing 3 replies - 1 through 3 (of 3 total)