LOADING...

Preview

Pen ID
Unlock Campus Themeforest adv

 

Code

Dice roller

Simple dice roller based on www.jsdice.com. Enter any RPG style dice calculation and hit 'enter'. Maximum rolls shown green, minimums shown in red.

Output
CSS
body {
  padding: 1em;
  font-size: 2em;
}
p {
  font-size: 0.5em;
}
h4 {
  margin: 0 0 0.2em 0;
}
input {
  padding: 0.3em;
  width: 95%;
  color: #333;
  border-radius: 0.3em;
  border: solid 1px grey;
}
output {
  display: block;
  width: 95%;
  margin: 0.3em 0;
  padding: 0.3em;
  line-height: 1.2em;
  border-radius: 0.3em;
  background: #EEE;
}
.type {
  vertical-align: super;
  font-size: 60%;
  color: grey;
}
.placeholder {
  color: #CCC;
}
.crit {
  color: #006700;
}
.fum {
  color: #cc0000;
}
.total {
  color: black;
  font-weight: bold;
}
JS
// Dice rolling function from: http://www.jsdice.com/roller/ 

function roll(dice){
  dice = dice.replace(/- */,'+ -');
  dice = dice.replace(/D/,'d');
  var re = / *\+ */;
  var items = dice.split(re);
  var res = [];
  var type = [];
  for ( var i=0; i0) {
        var special = ""; 
        if (i) str = str + ((data.res[i])>=0?" + ":" - ");
        if (data.type[i]) {
          str = str + "d"+data.type[i]+"";
          if( data.type[i] == data.res[i] ) special = "crit";
          if( data.res[i] == 1 ) special = "fum";
        }
        str = str + "" + Math.abs(data.res[i]) + "";
      }
    }
    str = str + " = " + total + "";
    return str;
  }
  else {
    return "Error in roll formula";
  }
}

$('#dice-demo-form').submit(function() {
  $("output").html( rollDice($("input").val()) );
  return false;
});

Description

Simple dice roller based on www.jsdice.com. Enter any RPG style dice calculation and hit 'enter'. Maximum rolls shown green, minimums shown in red.
Term
Sat, 01/13/2018 - 16:14

Related Codes

Pen ID
Pen ID
Pen ID
Square Adv