TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

May 01, 2024, 09:39:06 PM

Login with username, password and session length
Members
  • Total Members: 3,885
  • Latest: Growner
Stats
  • Total Posts: 195,175
  • Total Topics: 21,220
  • Online today: 177
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 0
  • Guests: 131
  • Total: 131

Simple Dice Roller block

Started by pjr, March 15, 2006, 02:34:47 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

pjr

just create a javascript block and add the code below

SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var die = 6;
var dice = 3;
function dice_roll(die, dice) {
var roll = 0;
for (loop=0; loop < dice; loop++) {
roll = roll + Math.round(Math.random() * die) % die + 1;
}
document.roller.drtext.value = roll;
}
// End -->
</script>

<center>
<form name=roller>
<table border=2 cellpadding=1>
<tr>
<td colspan=1 align=middle>Type?</td>
<td colspan=1 align=middle>Number?</td>
</tr>
<tr>
<td valign=top align=middle>
<p><input type=radio name=sides onclick="die = 2">2
<p><input type=radio name=sides onclick="die = 4">4
<p><input type=radio checked name=sides onclick="die = 6">6
<p><input type=radio name=sides onclick="die = 8">8
<p><input type=radio name=sides onclick="die = 10">10
<p><input type=radio name=sides onclick="die = 12">12
<p><input type=radio name=sides onclick="die = 20">20
<p><input type=radio name=sides onclick="die = 100">100
</td>
<td valign=top align=middle>
<p><input type=radio name=number onclick="dice = 1">1
<p><input type=radio name=number onclick="dice = 2">2
<p><input type=radio checked name=number onclick="dice = 3">3
<p><input type=radio name=number onclick="dice = 4">4
<p><input type=radio name=number onclick="dice = 5">5
<p><input type=radio name=number onclick="dice = 6">6
<p><input type=radio name=number onclick="dice = 8">8
<p><input type=radio name=number onclick="dice = 10">10
</td>
</tr>
<tr>
<td align=middle colspan=2>
<input type=button value="Roll Dice" name=button onclick="dice_roll(die, dice)">
<input type=text size=10 name=drtext>
</td>
</tr>
</table>
</form>
</center>


I may work on a more sophisicated one later...

Xarcell


pjr

#2
checkout this thread for a screen shot http://www.tinyportal.net/smf/index.php?topic=3371.0 and my site for a demo www.ourplacetoplay.com/forum.

slightly tweeked code

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var die = 6;
var dice = 3;
function dice_roll(die, dice) {
var roll = 0;
for (loop=0; loop < dice; loop++) {
roll = roll + Math.round(Math.random() * die) % die + 1;
}
document.roller.drtext.value = roll;
}
// End -->
</script>

<center>
<form name=roller>
<table border=1 cellpadding=2>
<tr>
<td colspan=1 align=center><small>Type of Dice</small></td>
<td colspan=1 align=center><small>Number of Dice</small></td>
</tr>
<tr>
<td valign=top align=left>
<p><input type=radio name=sides onclick="die = 2">2
<p><input type=radio name=sides onclick="die = 4">4
<p><input type=radio checked name=sides onclick="die = 6">6
<p><input type=radio name=sides onclick="die = 8">8
<p><input type=radio name=sides onclick="die = 10">10
<p><input type=radio name=sides onclick="die = 12">12
<p><input type=radio name=sides onclick="die = 20">20
<p><input type=radio name=sides onclick="die = 100">100
</td>
<td valign=top align=left>
<p><input type=radio name=number onclick="dice = 1">1
<p><input type=radio name=number onclick="dice = 2">2
<p><input type=radio checked name=number onclick="dice = 3">3
<p><input type=radio name=number onclick="dice = 4">4
<p><input type=radio name=number onclick="dice = 5">5
<p><input type=radio name=number onclick="dice = 6">6
<p><input type=radio name=number onclick="dice = 8">8
<p><input type=radio name=number onclick="dice = 10">10
</td>
</tr>
<tr>
<td align=center colspan=2>
<input type=button value="Roll Dice" name=button onclick="dice_roll(die, dice)">
<input type=text size=10 name=drtext>
</td>
</tr>
</table>
</form>
</center>


Mitch

You took my name for it. :P
Anywho you obviously didnt like the small

pjr

well Mitch as Pablo Picasso said

Quote"Bad artists copy. Great artists steal."

;D ;D ;D

Mitch

hehe its cool it was your code that I stole and just mad it more mitchish.

pjr

thats the cool thing about these sites we can all work together... thinking about doing a flash based one in the future with rolling dice for grins and giggles.... or one that can parse things like 2D6 + 1

Mitch

That would be cool let me knwo how that goes.

guvenck

What about using dice images? black-white 2 color gifs or pngs would do fine :)

akulion

Here is a lil something for u guys

A dice roller made in Shockwave - its flash basically

Dice Roller Demo

You require macromedia Shockwave player to view this, get it from macromedia.com if you dont have it



Download from here

akulion

well well lookie here found another one....

Its a flash dice roller game

Screenshot


download it here

i hope u know how to embed flash files properly

if not then ask down at kirupa.com

URPG

I'd like one that can be configured a bit more...
Type of Dice and Number of dice (maybe even different dice at once)
Add dice/substract dice or take each dice as single result
Check Result(s) against target number (above or below)

That should be able to deal with almost any Game in existance that uses dice.

Maybe calculator style? You select dice / number of them, then you can click * or / or + or - and add another dice/number of dice item, click again.... until you hit = and a re-roll button that does the last input again?

pjr

I actually have added a second die roller to my site one that works with the White wolf rule system. You can see it at www.ourplacetoplay.com

URPG

Jup, i've seen it, it's a step towards what would be universal...

Will try to look into it in the middle of next week when i got more time, maybe i can copy+paste somethign together...

Syndel

Any codes to roll and have results between 1-300?

URPG

I had the time to do something as universal as possible... want to have a look at the syntax, then I will post it here...

Syndel

I have manouvered to find a very simple java script for the dice I needed:

Quote<script LANGUAGE="JavaScript"><!-- Begin
var die = 6;
var dice = 3;
function dice_roll(die, dice) {
var roll = 0;
for (loop=0; loop < dice; loop++) {
// random number fix by George Johnston (cali_scripter@yahoo.com)
roll = roll + Math.round(Math.random() * die) % die + 1;
}
document.form.text.value = roll;
}
// End -->
</script>
<!-- STEP TWO: Add the last coding into the BODY of your HTML document  --></p>
<center>
<form name="form">
  <table border="2" cellpadding="5" height="147">
    <tr>
      <td height="49" align="center">What dice type?</td>
      <td height="49" align="center">How many dice to roll?</td>
    </tr>
    <tr>
      <td height="49" align="center">
      <input type="radio" name="sides" onclick="die = 300">300 Sided </td>
      <td height="49" align="center">
      <input type="radio" name="number" onclick="dice = 1">1 </td>
    </tr>
    <tr>
      <td colspan="2" height="49">
      <p align="center">
      <input type="button" value="Roll Dice" name="button" onclick="dice_roll(die, dice)">
      <input type="text" size="10" name="text"> </td>
    </tr>
  </table>
</form>
</center>
<p></p>

But I am interested, yes! :)

alecoddly

#17
sorry but how to you add a java block, cant see it as an option ?

worked it out  :-X

how did you get the separate numbers to output on your ww die roller pjr?

URPG

#18
Here is a copy+paste of a project that died because the programming guy was not ... interested enough. It's an attemp to make a universal dice roller, not only for boards but for character generators, etc. once it would be done it could be used anywhere and - as i am sure - do anything that you can do with real dice... besides building a stack of them  :uglystupid2:

It's basically 3 parts:


  • Reading and interpreting the input string
  • doing all the random numbers of the dice and executing the commands
  • output in a string that can further be modified by whatever send the request




Because it's stupid to have a different dice module for every application and every game system and every plattform i'd like to try and unify a dice rolling syntax working for most, if not all dice based systems. Here are my thoughts:




Goal:
Universal, short and easy to use Snytax that can be used to formulate any dice roll needed without special commands for each kind of roll. There are bots out there that use another command for each roll - that's unnessecary and starts to make a universal bot bloated and complicated to use! It's also stupid to re-programm a dice bot for every application and computer plattform...
This idea should finally lead to a dice rolling module with an input and output syntax that can be used by any application on any plattform: PHP or Java based Chat for online Sessions, character generators of all kind, rolling dice in a bulletin board if playing in a board...

Input Syntax:
(a)d(b) [A(c)] [O(+/-/0)] [S] [E(+/- and d)] [M(+/- and e)] [K(+/- and f)] [I] X(g) B

a = # of Dice
b = sides of dice (1-b)
A(c) = If parameter A is existant every dice is adjusted by c
O = if there is an O it's open rolls +: maximal rolls are rerolled and added or -: minimal rolls are rerolled and substracted 0: both of the above...
S = if there is an S all dice are summed up
E = if there is an E each dice (or if there is an S existant the end result) is compared to d. the + or - indicates if the dice has to be over or under d to be successful.
M = the same as E but for numbers that indicate a failure to be counted after comparing to e.
K = Indicates critical numbers + for critical or automatical success or - for critical or automatic failure.
I = if I is existant any dice showing the same number(s) as I is ignored and rerolled
X(f) = if there is an X each dice, each success (if there is an E specified) or the total sum (if there is an S) is multiplied with f.
B = a simpel string as description of the action intended to be simulated with the roll, is output unchanged together with the result.

In addition to those parameters the module should be able to understand the 4 basic caclulation signs.

Output Syntax:
Name of the one rolling + description of the full roll depending on the parameters + number each dice showed + total outcome + description inputted under B.


Examples:
5d6
Yazee (or whatever dice game variant) player rolls 5 dice and does look what he does get.

d100 K+01+11+22+33+44+55+66-77-88-99-100 E-70
Space Gothic Player tries to roll 1d100 trying to stay under his skill of 70 and checking if he got any doubles (criticals in SG)

8d6 O E+9
Shadowrunner (1-3rd Ed.) rolls 8 dice skill checking if he got any 9 or above that would count as success (re-rolling on a 6).

3d6 S K-17-18 E-14
Gurps Player rolls 3d6 that are added together. he is successful if the sum stays below his skill of 14 and a roll of 17 or 18 indicates critical failure.

3dd6 X10
Warhammer FRP player rolls 3d6 *100 for starting cash.

6d10 A-3 K-1+10 E5 X5
URPG player rolls 6w10, each -3 and compares to the TIT of 5. Each dice that is a success does count as 5 points.  A roll of 1 does indicate automatic failure and a roll of 10 automatic success for the roll.

8d10 E8 M1
The oWoD Player rolls 8d against a success number of 8, each 1 is counted as failure.

(3w6 S I-5) *6
The D&D player does roll 3d6 (ignoring any total that is 5 or less) a total of 6 times to generate stats for a new Char.

d20 E-12 and d10 E-14 and d20 E-12
The DSA player rolls his 3d20, each ahs to be under a certan number to be successful.

(d20 O) + (d10 O) + (d4 O) E+16 M3
The EarthDawn player rolls his d20+d10+d4 (each open rolls) to see if he can reach the target number of 16 (with critical failure on a 3).

Probleme:
The dice themself should be no problem at all (random number of  von 1-size of dice), E is just a query if the result is dice size and a reroll. M and S and I are similar easy operators. A real problem could be caused by the Pharser needed to understand complext calculations like 5d6 + 1d4 O -3.
Another difficulty is that we need good random numbers...

Realisation:
I'd sugest java or PHP so it can be used on- or offline and on most plattforms?


Syndel

alecoddly:
I dunno, but it worked *L*

www.khaotikdezirez.com

pjr

Quote from: alecoddly on September 06, 2006, 11:27:50 PM
sorry but how to you add a java block, cant see it as an option ?

worked it out  :-X

how did you get the separate numbers to output on your ww die roller pjr?

Which one I have two and I will post the code here

rebelminion

A cool option would be for the dice roller to post the results in a forum as "Secure" rolls.

So for instance, I have a sight where I want user to be able to play an RPG in a forum. This would let the player "Roll" his numbers, but make sure that the rolls are legitimate.

What would it take for something like that to work?

R

URPG

That's a cute one, but I'd rather like a more configurable one... like dice size / dice number / add or count alone...

JPDeni

QuoteWhat would it take for something like that to work?

It would take coding appropriate for the SMF forum, not the Tiny Portal forum.

technodragon73

Quote from: JPDeni on February 10, 2007, 02:00:06 PM
QuoteWhat would it take for something like that to work?

It would take coding appropriate for the SMF forum, not the Tiny Portal forum.

Of which there has been a mod for that, can't remember exactly which topic, though.