The Wakaba and Kareha support thread, part 3 (535)

51 Name: Anonymous : 2011-03-03 00:59 ID:Ef7z+kRC [Del]

I'm trying to cobble together something similar to 4chan/tg/'s dice rolling function. If "dice XdY+Z" is in the email field when the post is submitted, the script will randomly generate numbers to simulate rolling X-number of Y-sided dice, add modifier Z, and put the result into the posted post. So "2d6+5" would result in something like

Rolled 4, 3 + 5 = 12
Rest of post derp herp blahblah etc

The perl script I've found is different in that it can process negative modifiers instead of just adding, but the basic idea is the same.

#!/usr/bin/perl -wl
use strict;
$_ = shift or die 'Invalid argument passed';
/^(\d+)[dD](\d+)([+-]\d+)?$/ or die 'Invalid argument passed';
my $sum = 0;
$sum += 1 + int rand $2 for 1..$1;
$sum += $3 if defined $3;
print $sum;

The problem is I don't know anything about perl or coding aside from some basic concepts like variables and subroutines, so I don't know how to integrate the rolling script with Kareha.
I started off looking through to see where it called (banner image randomizer), so I could modify the function for my own purposes, and have had no luck. I'm probably looking for the wrong thing, or in the wrong place, or have seen exactly what I need but didn't recognize it...

Any help at all is appreciated.

Name: Link:
Leave these fields empty (spam trap):
More options...