[ home / board list / faq / random / create / bans / search / manage / irc ] [ ]

/d20/ - Traditional Games

Roll a Will Save vs Insanity

Catalog

8chan Bitcoin address: 1NpQaXqmCBji6gfX8UgaQEmEstvVY7U32C
The next generation of Infinity is here (discussion) (contribute)
A message from @CodeMonkeyZ, 2ch lead developer: "How Hiroyuki Nishimura will sell 4chan data"
Name
Email
Subject
Comment *
File
* = required field[▶ Show post options & limits]
Confused? See the FAQ.
Options
dicesidesmodifier
Password (For file and post deletion.)

Allowed file types:jpg, jpeg, gif, png, webm, mp4, pdf
Max filesize is 8 MB.
Max image dimensions are 10000 x 10000.
You may upload 4 per post.


QUESTS: /qu/ | CYOAS: /cyoa/ | RULES

File: 1440309602932.png (Spoiler Image, 452.89 KB, 900x999, 100:111, 1439695356630.png)

 No.391

Rolling d20

Post last edited at

 No.397

I guess this is technically /tg/ then


 No.403

Dice rollRolled 5 (1d20)

roland


 No.405

>editing posts removes their roll

For what purpose?


 No.438

Dice rollRolled 4 (1d20)

bretty good


 No.443

Dice rollRolled 6 (1d6)

>>438

I'm so glad to have email field dice back


 No.462

Dice rollRolled 17 (1d20)

>>391


 No.469

Am I doing this right?


 No.470

>>469

Nope, clearly not.


 No.472

>>470

I think you just put the dice in the email field


 No.473

Dice rollRolled 11, 19 = 30 (2d20)

>>472

nope, I have been trolled. it's under post options & limits though


 No.475

Dice rollRolled 3 (1d100)

>>473

Ah, thank you, kind anon.


 No.476

Dice rollRolled 13 - 1 (1d20)

>>391

Rolling a DC 15 Charisma check to see if OP is a faggot.


 No.477

no m8, it's a script

put this in the User JS section in [Options], and hit save custom javascript

then type 1d20 in the email field, or whatever you want


$(document).on('click', 'input[name="post"]', function() { //when the New Topic/New Reply button is clicked
if (!isNaN(parseInt($('input[name="email"]').val()[0])) && !isNaN(parseInt($('input[name="email"]').val().slice(-1))) && $('input[name="email"]').val().match(/\d*d\d*/)) { //if the first character in the email field is a number, the last character is a number, and it matches a regex for [0-9]*d[0-9]*, then
$('.dx').val($('input[name="email"]').val().split('d')[0]); //set dx, the number of dice, to everything before d
$('.dy').val($('input[name="email"]').val().split('d')[1]); //set dy, the number of sides on the dice, to everything after d
}
});


 No.478

>>477

for >>473

no troll


 No.479

>>477

Can this be added to the board settings so everyone can do it without modifying their theme?


 No.480

File: 1440318510076.jpg (171.13 KB, 850x1200, 17:24, 1438914973112.jpg)

>>476

Tough shit OP


 No.482

>>479

unfortunately, no

It's javascript, not CSS. It's not a theme. It can't be done.

If board owners could just run whatever javascript they wanted, it'd be a security nightmare.


 No.484

>>482

True, true. Maybe it can be added to the board FAQ.


 No.485

this doesn't do anything yet


 No.486

Dice rollRolled 16 (1d20)

now it does


 No.487

File: 1440318692820.jpg (41.97 KB, 411x381, 137:127, 1392000192185.jpg)


 No.488

File: 1440318684685.mp4 (831.07 KB, 1348x672, 337:168, ephqythbpo[1].mp4)

Dice rollRolled 20 (1d20)

>>485

>>486


 No.489

>>488

I appreciate your thoroughness but a webm is kinda spergy anon, we believe you

also get some adblock on there, son, damn


 No.491

>>489

>blocking ads so the website can't get funded

also

>adblock

>not uBlock


 No.493

Dice rollRolled 17 + 10 (1d20)

>>491

There is literally nothing wrong with AdBlockPlus


 No.494

>>488

>Rolled 20 (1d20)

nice

good job me


 No.495

>>494

rolled a nat 20 on your Teach check


 No.496

File: 1440319280834.gif (940.08 KB, 627x502, 627:502, e4d.gif)


 No.497

File: 1440319407303.png (145.43 KB, 600x600, 1:1, crit the hay.png)

Dice rollRolled 14 (1d20)

rolling for sleep


 No.498

>>477

tiny update

I forgot to account for the modifier


$(document).on('click', 'input[name="post"]', function() { //when the New Topic/New Reply button is clicked
if (!isNaN(parseInt($('input[name="email"]').val()[0])) && !isNaN(parseInt($('input[name="email"]').val().slice(-1))) && $('input[name="email"]').val().match(/\d*d\d*/)) { //if the first character in the email field is a number, the last character is a number, and it matches a regex for [0-9]*d[0-9]*, then
$('.dx').val($('input[name="email"]').val().split(/[^\d]/)[0]); //set dx, the number of dice, to the first given numerical value given
$('.dy').val($('input[name="email"]').val().split(/[^\d]/)[1]); //set dy, the number of sides on the dice, to the second given numerical value
$('.dz').val($('input[name="email"]').val().split(/[^\d]/)[2]); //set dz, the modifier, to the third given numerical value, if there is one
}
});


 No.499

>>498

shouldn't it be +, not another d?


 No.503

>>499

I thought the comments were fairly descriptive, but I'll try to explain

this is we start with, right?


$('input[name="email"]').val().split(/[^\d]/)

let me break it down


$('input[name="email"]')

is a jQuery selector for the email field, so


$('input[name="email"]').val()

gets the value of whatever is in the email field

once we have the whatever was typed in the email field, we split it using


$('input[name="email"]').val().split(/[^\d]/)


/[^\d]/

is a regular expression that means anything that is NOT a digit, like d, or +

.split() puts things in to an array, so you have to use [0], [1], [2], etc to select something from it


'1d20'.split(/[^\d]/)
Array [ "1", "20" ]
'1d20'.split(/[^\d]/)[0]
"1"
'1d20'.split(/[^\d]/)[1]
"20"
'4d6+5'.split(/[^\d]/)
Array [ "4", "6", "5" ]
'4d6+5'.split(/[^\d]/)[0]
"4"
'4d6+5'.split(/[^\d]/)[1]
"6"
'4d6+5'.split(/[^\d]/)[2]
"5"

.val() can be used to get a value, but it can also be used to change a value

so:


$('.dx').val($('input[name="email"]').val().split(/[^\d]/)[0]);

changes the value of dx, the dice field under [▶ Show post options & limits], to whatever the first number is

while


$('.dy').val($('input[name="email"]').val().split(/[^\d]/)[1]);

changes the value of dy, the sides field [▶ Show post options & limits], to whatever the second number is

and

$
('.dz').val($('input[name="email"]').val().split(/[^\d]/)[2]);

changes the value of dz, the modifier field under [▶ Show post options & limits], to whatever the third number is

if there is no number, which is the case with


'1d20'.split(/[^\d]/)[2]
undefined

then it just returns undefined, so when the value of the modifier field is changed, it leaves it blank


 No.504

>>503

derp I forgot my regex again

I swear I'm a programmer


 No.947

>>476

Wouldn't it be a Wisdom check?


 No.1254

lets see here


 No.1255

aight how about this


 No.1264

Dice rollRolled 16 (1d20)

Gogogo




[Return][Go to top][Catalog][Post a Reply]
Delete Post [ ]
[]
[ home / board list / faq / random / create / bans / search / manage / irc ] [ ]