mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Apr 2011
Posts: 8
Y
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
Y
Joined: Apr 2011
Posts: 8
I am running a World of Darkness game on irc, but need a better dice roller. What I need it to do is the following:

If a user types roll X then it needs to roll X ten-sided dice, and display each roll.

Eg:
Code:
<User> I try and shoot him.
<@Me> Ok. His defence is 2, your Dex+Firearms is 7 and his defence applies as it is point blank.
<@Me> 5 dice then.
<User> roll 5
* @Me User rolls 5 dice: 1, 3, 10, 7, 8


If possible it should give the output with mIRC color codes, so the text should be 0,1 (White on Black) except for:
10 : Bright Green on Black
8 & 9 : Dark Green on Black
2 to 7: White on Black
1 : Red on Black.

Please post the code snippet both here and in the code snippet section of this site...
You can check out the basic rules of World of Darkness on www.white-wolf.com, there are several "demo" games, but the one for Vampire: the Requiem is both a small download and informative about the mechanics.

I know I could use another dice script, but they are inefficient for my purpose.

Thanks,
Yuki.
[/i]

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Considering how easy a dice script is, you'd be better off learning how to write it yourself so that you can edit it later to suit your needs.

/help on text
/help while
/help $rand

Either way, here's a script.

Code:
on *:text:roll &:#: {
  if ($2 !isnum) { msg $chan Invalid number of dice. | return }
  var %c = $2
  while (%c) {
    var %roll = $rand(1,10)
    if (%roll = 1) { var %roll = 04,01 $+ %roll }
    elseif (%roll isnum 2-7) { var %roll = 00,01 $+ %roll }
    elseif (%roll isnum 8-9) { var %roll = 03,01 $+ %roll }
    else { var %roll = 09,01 $+ %roll }
    var %dice = %dice $+ $iif(%dice, $+ $chr(44)) %roll
    dec %c
  }
  describe $chan $nick rolls $2 dice: $replace(%dice,$chr(46), $+ $chr(44) $+ $chr(32))
}


Invision Support
#Invision on irc.irchighway.net
Joined: Apr 2011
Posts: 8
Y
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
Y
Joined: Apr 2011
Posts: 8
Thanks. Works perfectly!
Cheers!

Joined: Apr 2011
Posts: 8
Y
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
Y
Joined: Apr 2011
Posts: 8
Ok, so I modified it slightly to prevent more than 30 dice, but what I'm now trying (unsucessfully) to do is to get it to generate the roll, and then count how many 10's are rolled, and automatically reroll that many dice.

Eg if the roll comes up:
8, 4, 9, 9, 1, 2, 10, 3, 6, 6, 3, 9, 4, 10, 3, 3, 6, 4, 5, 6
then it must see that there are two tens and reroll two dice.

It needs to do this again and again, until no more 10's come up in the roll, so if in the above example the reroll came up:
10, 10
it would reroll two dice, and if they came up:
10, 8
then it would reroll one dice, and if that came up:
10
then it would reroll again, and so on until there are no more tens. THEN it needs to:
Code:
msg $chan No more rerolls


If possible it should keep track of all successes (8,9,10) throughout and then display a message Sucesses: X, whre X is the number of successes rolled, once all rerolls are done.

Is this even possible?

Code:
on *:text:roll &:#: {
  if ($2 !isnum) { msg $chan Invalid number of dice. | return }
  var %c = $2
  if (%c > 30) {
    msg # No way, That's too many dice!
    halt
  }
  while (%c) {
    var %roll = $rand(1,10)
    if (%roll = 1) { var %roll = 00,01 $+ %roll }
    elseif (%roll isnum 2-7) { var %roll = 00,01 $+ %roll }
    elseif (%roll isnum 8-9) { var %roll = 11,01 $+ %roll }
    else { var %roll = 09,01 $+ %roll }
    var %dice = %dice $+ $iif(%dice, $+ $chr(44)) %roll
    dec %c
  }
  msg $chan $nick rolls: $replace(%dice,$chr(46), $+ $chr(44) $+ $chr(32))
}


Assistance would be greatly valued!

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
If you search the forum, someone requested a similar script a year or two ago. I'm sure it's still on the forum. Try searching for dice or roll or re-roll or the name of the game or whatever.


Invision Support
#Invision on irc.irchighway.net
Joined: Apr 2011
Posts: 8
Y
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
Y
Joined: Apr 2011
Posts: 8
Thanks, I found a few, but they are greek to me. smile
The guy who wrote the script was also a bit of a noob programmer like me so he wrote a bit of spagetti...
My online time is limited, so one final question:
Would my scripts run on an OfficeIRC server on a local network for testing?

Last edited by YukiSokudo; 05/04/11 09:32 PM.
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
I don't want to say the scripts will or will not work on an Office IRC server, however, I doubt that they will, since they are mIRC scripts, not Eggdrop, which is the most common type of scripting for a server.

Additionally, if you do try to run these on the office IRC server, make sure that you have permission or (worst case scenario that I can think of) you could be looking for a new job.

Joined: Apr 2011
Posts: 8
Y
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
Y
Joined: Apr 2011
Posts: 8
I read some scripting tutorials, and I though I had it figured out, but I get a weird problem. Everything works, but it seems to lose the color codes in the original part of the script.

Here is the code as it stands:
Code:
on *:text:roll &:#: {
  if ($2 !isnum) { msg $chan Invalid input. | return }
  var %totsucs = 0
  var %c = $2
  if (%c > 30) {
    msg # No way, That's too many dice!
    halt
  } 
:reroll
  var %dice = %blank
  var %rers = %blank
  var %s10s = %blank
  var %s9s = %blank
  var %s8s = %blank
  var %sucs = %blank
while (%c > 0) { 
    var %roll = $rand(1,10) 
	if (%roll = 1) { var %roll = 00,01 $+ %roll } 
    elseif (%roll isnum 2-7) { var %roll = 00,01 $+ %roll } 
    elseif (%roll isnum 8-9) { var %roll = 11,01 $+ %roll } 
    else { var %roll = 09,01 $+ %roll } 
    var %dice = %dice $+ $iif(%dice, $+ $chr(44)) %roll 
    dec %c
  }
  msg $chan $nick gets: $replace(%dice,$chr(46), $+ $chr(44) $+ $chr(32))
  var %s10 = 10
  var %s9 = 9
  var %s8 = 8
  var %c = $count(%dice,%s10)
  var %s10s = $count(%dice,%s10)
  var %s9s = $count(%dice,%s9)
  var %s8s = $count(%dice,%s8) 
  var %sucs = $calc(%s10s + %s9s + %s8s)
  var %temp = %sucs
  var %runtot = $calc(%runtot + %sucs)
  var %sucs = %blank
  msg $chan $nick has11,01 %temp 00,01sucesses and needs to reroll11,01 %c  00,01dice.
  var %temp = %blank
  if (%c > 0) {
  goto reroll }
msg $chan <---------------------------------------->
msg $chan $nick has a grand total of04,01 %runtot  00,01sucesses.
msg $chan <---------------------------------------->
}


Last edited by YukiSokudo; 06/04/11 12:04 AM.
Joined: Apr 2011
Posts: 8
Y
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
Y
Joined: Apr 2011
Posts: 8
guess the final question wasn't that final...
blush

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
This rerolls and shows all rolls. You can adjust the output to suit your needs.

Code:
on *:text:roll &:#: {
  if ($2 !isnum) { msg $chan Invalid number of dice. | return }
  var %c = $2, %tens = 0
  while (%c) {
    var %roll = $rand(1,10)
    if (%roll = 1) { var %roll = 04,01 $+ %roll }
    elseif (%roll isnum 2-7) { var %roll = 00,01 $+ %roll }
    elseif (%roll isnum 8-9) { var %roll = 03,01 $+ %roll }
    else { var %roll = 09,01 $+ %roll | inc %c | inc %tens }
    var %dice = %dice $+ $iif(%dice, $+ $chr(44)) %roll
    dec %c
  }
  describe $chan $nick rolls $2 dice (with %tens re-roll $+ $iif(%tens != 1,s) $+ ): $replace(%dice,$chr(46), $+ $chr(44) $+ $chr(32))
}


Notice that the only change it to increment the counter when a 10 is rolled so that it rolls an extra time and also increment a variable to count the number of tens rolled. The only other change is the output shows the number of re-rolls. The $iif() in that just changes whether re-rolls is plural or not based on the number of tens.


Invision Support
#Invision on irc.irchighway.net
Joined: Apr 2011
Posts: 8
Y
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
Y
Joined: Apr 2011
Posts: 8
thanks, but i got it to work. I just edited the above post... Now it's just giving me color issues...

Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
Hum, I did some modifications to an old dice snippet I posted on these boards long ago. It should allow you to reroll without flooding. Maybe it's of use to you smile

Code:
/*
Dice snippet

$dice(<parameters>).<properties>
Syntax: $dice(R [,DN] [,SN] [,CN] [,A<reroll rules>]) [.sum|success|failed|critical|botch|rerolls|string|rerollstring|r|d|s|c]


----- Parameters -----

All parameters are optional.

R      = number of rolls (number of dice). If used, R has to be a positive integer and the first parameter.

All other parameters (D, S, C and A) don't have to be in order.

The D, S and C parameters consist of the indicating letter, followed by a positive integer N. 
D      = number of sides of the dice (type of dice)
S      = lowest side of the dice to be regarded a "successful" roll
C      = lowest side of the dice to be regarded a "critical" roll

A      = matching dice will be rolled again (reroll).
The A paramter consists of the indicating letter "a/A", followed by either:
-- a string of integers, separated by dots
-- an integer N and "+": N and all higher sides will be rerolled
-- an integer N and "-": N and all lower sides will be rerolled
If you use "a" (lowercase), dice will be rerolled only once. If you use "A" (uppercase), dice will be rerolled till they don't match the reroll rule.

If you don't provide R, D, S, C, or A, the following defaults will be used:
-- if no R is given, a single dice is used (R = 1)
-- if no D is given, a 10-sided dice is used (D = 10)
-- if no S (with N <= D) is given, a roll is regarded successful if it's equal to or biger than [D / 2 + 1, rounded up to the next integer]
-- 	(the default S for D2 is 2, for D3-D4 it's 3, for D5-D6 it's 4 etc)
-- if no C (with N <= D) is given, a roll is regarded critical if it has the highest possible result (that is: D)
-- if no A is given, no reroll will occur

Examples: 
$dice() will return the sum of a 1D10
$dice(5) will return the sum of a 5D10
$dice(2,D3) will return the sum of a 2D3
$dice(4,A5.6,D7) will return the sum of a 4D7 while rerolling 5es and 6es
$dice(4,a3-) will return the sum of a 4D10 with one-time rerolls for 3, 2, and 1


----- Properties -----
All properties are optional. Properties don't have to be in order.

sum      = total of the rolls (same as using no property at all)

success      = number of successful rolls (after rerolls)
failed      = number of failed rolls (= total rolls - successful rolls)
critical      = number of critical rolls (after rerolls)
botch      = number of botch rolls (after rerolls)
rerolls      = number of rerolls

string      = space-delimited string of the individual dice results (after possible rerolls)
-- If you use STRING (uppercase), results will be zeropadded to the length of D.
-- Even though the script will calculate larger rolls, this string will hold no more than 50 dice.

rerollstring      = space-delimited string of the dice results INCLUDING all rerolls
-- If you use REROLLSTRING (uppercase), results will be zeropadded by the length of D.
-- Even though the script will calculate larger rolls, this string will hold no more than 50 dice.


r      = number of rolls performed (e.g. if no valid R specified). Note that it is NOT counting rerolls
d      = number of sides of the dice used (e.g. if no valid D specified)
s      = value used as success threshold (e.g. if no valid S specified)
c      = value used as success threshold (e.g. if no valid C specified)
The r,d,s and c properties are most of all for convenience

Examples:
$dice() = sum of a default roll with a default dice (a 1D10)
$dice(8,D5).success = number of successful rolls of a 8D5 (using default success value where a roll of 4+ is regarded "success")
$dice(8,D5,S5).success = number of successful rolls of a 8D5, where a roll of 5+ is regarded "success"
$dice(4).failed = number of failed rolls of a 4D10 (using default values for D and success, where for a D10 a roll of 5- is regarded "failure")
$dice(3,D3).critical = number of critical rolls of a 3D3 (using default critical value = 3)
$dice(10,D9,C7).critical = number of critical rolls of a 10D9, where a roll of 7+ is regarded "critical"
$dice(5).botch = number of botches of a 5D10
$dice(7,D7,A5+).rerolls = number of rerolls of a 7D7, rerolling 5,6 and 7
$dice(10,D6).string = a string of the individual results of a 10D6
$dice(10,D6,a4).rerollstring = a string of the individual results after non-recurring rerolls of a 10D6, rerolling 4s
$dice().d = default D value (10)
$dice().s = default S value for a default D roll (= 6 for a default D10)


NOTE: The snippet gets versatility by allowing you to use multiple properties, separated by comma. The results will be separated by comma.
Examples:
"$dice(7).success,critical" will for a 7D10 return: <successful rolls>,<critical rolls>
"$dice(8,S7,D8).sum,failed,botch" will for a 8D8 return: <sum of rolls>,<failed rolls, where 6- is regarded "failure">,<botch rolls>
"$dice(3,D9,C8).critical,success" will for a 3D9 return:
	<critical rolls, where 8+ is regarded "critical">,<successfull rolls, where for a D9  6+ is regarded "success")
"$dice(5,D12,a4-).STRING,rerolls,REROLLSTRING" will for a 5D12 return:
    <zero-padded results string (after rerolls)>,<number of non-recurring rerolls>,<zero-padded string with rerolls>
"$dice(D4,C6).c,critical" will for a 1D4 return:
	<default critical threshold of a D4 (as the invalid parameter "C6" is ignored for being bigger than D4)>,<critical rolls of the 1D4, using the 3+ threshold>
*/

alias dice {
  if ($isid) {
    var %sum = 0, %success = 0, %critical = 0, %botch = 0, %rerolls = 0, %loop, string, %rerollstring, %n = 1
    ; parse parameters
    var %r = $iif(($1 isnum 1-),$int($v1),1)
    var %d = $iif(($mid($wildtok($1-,D*,1,32),2-) isnum 1-),$int($v1),10)
    var %s = $iif((($mid($wildtok($1-,S*,1,32),2-) isnum 1-) && ($int($v1) <= %d)),$v1,$ceil($calc(%d / 2 $iif((%d > 1),+ 1))))
    var %c = $iif((($mid($wildtok($1-,C*,1,32),2-) isnum 1-) && ($int($v1) < %d)),$v1,%d)
    var %a = $wildtok($1-,A*,1,32), %ap = $mid(%a,2-), %repeat = $iif(%ap,$iif(($left(%a,1) isupper),1,0))
    if (%repeat != $null) {
      if ($right(%ap,1) isin +-) && ($left(%ap,-1) isnum 1-) { var %a = $int($v1), %ap = $iif(($right(%ap,1) == +),2,1) }
      else { var %a = %ap, %ap = 0 }
    }
    ; %repeat: 1=loop, 0=single;  %a = value; %ap: 2=and higher, 1=and lower, 0=tokens

    ; parse properties (1) - create (zeropadded) string of results?
    var %mkstring = $iif(($wildtok($prop,string,1,44)),$iif(($v1 isupper),$len(%d),1))
    var %mkrstring = $iif(($wildtok($prop,rerollstring,1,44)),$iif(($v1 isupper),$len(%d),1))


    ; roll the dice!
    while (%n <= %r) {
      :reroll
      var %x = $rand(1,%d)

      if (%repeat != $null) {
        if ((%ap == 2) && (%x >= %a)) || ((%ap == 1) && (%x <= %a)) || ($istok(%a,%x,46)) {
          if (!%loop) {
            if (!%repeat) var %loop 1
            if (%mkrstring) && ($numtok($replace(%rerollstring,-,$chr(32)),32) < 50) $&
              var %rerollstring = $+(%rerollstring,$iif(($right(%rerollstring,1) isnum),$chr(32)),$iif((%mkrstring < 2),%x,$base(%x,10,10,$v1)),->)
            inc %rerolls
            goto reroll
          }
        }
        unset %loop
      }

      if (%x == 1) inc %botch
      if (%x >= %s) inc %success
      if (%x >= %c) inc %critical
      inc %sum %x

      if (%mkstring) && ($numtok(%string,32) < 50) var %string = %string $iif((%mkstring < 2),%x,$base(%x,10,10,$v1))
      if (%mkrstring) && ($numtok($replace(%rerollstring,-,$chr(32)),32) < 50) $&
        var %rerollstring = $+(%rerollstring,$iif(($right(%rerollstring,1) isnum),$chr(32)),$iif((%mkrstring < 2),%x,$base(%x,10,10,$v1)))
      inc %n
    }
    var %failed = %r - %success

    ; parse properties (2)
    ; every valid property is replaced with the value of the variable which has the name of the property
    var %return = $regsubex($prop,/(?<=^|\54)(sum|success|failed|critical|botch|rerolls|string|rerollstring|r|d|s|c)(?=$|\54)/ig, $var(\1,1).value)

    ; return the result acc. to properties, or the sum if no property was used
    return $iif($regml(0),%return,%sum)
  }
}


Now inside a text event you could do something like:
Code:
on *:text:roll &:#: {
  if ($2 !isnum) { msg $chan Invalid number of dice. | return }
  ; you call the alias "dice" as an identifier, and tokenize the result to put it into $1 $2 $3 ...
  tokenize 44 $dice($2,D10,A10).r,sum,rerolls,string,rerollstring

  ; now you can do whatever you want to do with the result
  var %colored = $regsubex($4,/(\d+)/g,$+($chr(3),0,$iif((\1 isnum 2-7),0,$iif((\1 isnum 8-9),3,4)),$chr(44),01,\1,$chr(15)))

  describe $chan $nick rolls $1 dice... The result is %colored (or $2 in total)
  if ($3) { describe $chan ...this took $3 reroll(s) ( $5 ) }
}

Last edited by Horstl; 06/04/11 01:49 AM.

Link Copied to Clipboard