All pastes #1273086 Raw Edit

mIRC Script for D6 System

public text v1 · immutable
#1273086 ·published 2008-12-02 04:54 UTC
rendered paste body
/*
********************************************************************************
mIRC Script for the D6 System
by Jeremy T. Gibson
********************************************************************************

This script is designed to provide a simple "!d6" function which takes a
sentence and reads any and all dice codes and pips from that statement.  It
then converts all of the numbers into a single dice throw, which it rolls
automatically.

The dice thrower deliberately does not roll any dice other than six-sided dice.
This is because the snippet is designed for West End Games' D6 System, which has
very specific rules on how dice work.

If the first die (the wild die, marked with an asterisk) comes up as a 6, it
automatically adds the bonus throws to the total.

It also uses the standard complication rule for throwing a 1 on the wild die: if
throwing a 6 on 1D, a complication occurs -- otherwise a standard penalty occurs
equal to subtracting the wild die (1) and the highest die already thrown.

It matches all strings of the following formats:

1 - adds one pip
+1 - adds one pip
-1 - subtracts one pip

1D - adds three pips (1D)
+1D - adds three pips (1D)
-1D - subtracts three pips (1D)
(D can be uppercase or lowercase, and can be followed by a 6 (which is ignored))

1D+1 - adds four pips (1D+1)
1D-1 - adds two pips (0D+2)
+1D+1 - adds four pips (1D+1)
+1D-1 - adds two pips (0D+2)
-1D+1 - subtracts four pips (1D+1)
-1D-1 - subtracts two pips (0D+2)

Each die is worth three pips, and pips are always converted into dice if it is
possible to do so.  Adding 1D+1 plus 2D+2 actually comes to a total of 4D!

********************************************************************************

Here is a mock sample of the script's use and output:

#OOC <Plae-Yer> !d6 Okay, I'm shooting my blaster at him. I have 5D+1 to hit...
#OOC <D6Bot> (Plae-Yer) Your 5D+1 roll comes to: 21 [3*,6,5,1,5]+1
#OOC <Djee-Em> That's good enough for me, and he wasn't dodging, either... Roll
         for damage!
#OOC <Plae-Yer> !d6 Smack that bugger with 5D!
#OOC <D6Bot> (Plae-Yer) Your 5D roll comes to: 17 [3*,5,6,2,1]
#OOC <Djee-Em> Even with armour, that guy doesn't have a chance, so I'm not
         gonna bother rolling.
#RP <Djee-Em> ACTION: The blaster strikes the bounty hunter square in the chest.
         He slumps over pathetically, a smoking ruin where his internal organs
         should be.
#RP <Plae-Yer> May the Force be with you. ::spits in the bounty hunter's eye::
#OOC <Djee-Em> LOL!  Should that count as a Dark Side Point? ;-)

********************************************************************************

Here are all of the functions you can use:

(In a public channel)
!d6 [sentence]
    Totals all of the dice codes in the sentence and causes the bot/script owner
    to say them out loud.
!privd6 [sentence]
    Totals all of the dice codes in the sentence and obviously shares the
    sentence itself in the channel, but sends the results to you via a notice.
    Generally only the gamemaster should use this command.

(In a query window to the bot/script owner -- even if you are the script owner!)
!d6 [sentence]
    Totals all of the dice codes in the sentence and returns the results in the
    private window, with no redundant echoing if talking to yourself!

********************************************************************************
*/

alias d6 {
  if ( $0 == 0 ) {
    return
  }

  var %i = 0
  %piptotal = 0

  var %matches = 0

  :d6loopstart
  inc %i
  var %param = $gettok($1-, %i, 32)

  var %match = $regex(%param, ^([\+|\-])?(\d+)([d|D])?(\d*)([\+|\-])?(\d*)$ )
  if ( %match == 1 ) {
    var %pips = $pipsgained(%param)
    ;/msg $chan DBG: matched %param with value of %pips
    if ( %pips != 0 ) %piptotal = $calc(%piptotal + %pips)
    inc %matches
  }
  if ( %i < $0 ) goto d6loopstart

  if ( %matches == 0 ) {
    $reportmsg( ( $+ $nick $+ ) Um... there were no dice there. )
    halt
  }

  if ( %piptotal <= 0 ) {
    $reportmsg( ( $+ $nick $+ ) Total is less than 0D!  Automatic failure! )
    halt
  }

  $rolld6( %piptotal )

  $reportmsg( ( $+ $nick $+ ) Your %d6.string roll comes to: %d6.total $&
      %d6.results $+ %d6.bonus )

  var %complication = 0

  if ( %d6.wild == 6 ) {
    $rollwild()
    %d6.total = %d6.total + %d6.wildtotal
    $reportmsg( ( $+ $nick $+ ) The wild die gives you a bonus of $&
        %d6.wildtotal %d6.wildresults $+ !  Final score is %d6.total $+ ! )
  }
  elseif ( %d6.wild == 1 ) {
    if ( $rollforcomplication() ) {
      $reportmsg( ( $+ $nick $+ ) Uh oh!  There's a complication! )
    }
    else {
      var %penalty
      %penalty = $calc(%d6.highroll + 1)
      if ( %penalty <= 1 ) halt
      %d6.total = %d6.total - %penalty
      $reportmsg( ( $+ $nick $+ ) Uh oh!  There's a %penalty point penalty! $&
          ...Final score is %d6.total $+ ! )
    }
  }
}

alias pipsgained {
  ;Check as a positive pip bonus:
  var %match = $regex(bonus, $1, ^\+?(\d+)$ )
  if ( %match == 1 ) {
    ;/msg $chan DBG: $1 matched a positive bonus
    return $regml(bonus, 1)
  }

  ;Check as a negative pip penalty:
  %match = $regex(penalty, $1, ^\-(\d+)$ )
  if ( %match == 1 ) {
    ;/msg $chan DBG: $1 matched a negative penalty
    return $calc( 0 - $regml(penalty, 1) )
  }

  ;Check as a positive dice bonus:
  var %match = $regex(posdice, $1, ^\+?(\d+)[d|D]6?$ )
  if ( %match == 1 ) {
    ;/msg $chan DBG: $1 matched a positive number of dice
    return $calc($regml(posdice, 1) * 3)
  }

  ;Check as a negative dice penalty:
  var %match = $regex(negdice, $1, ^\-(\d+)[d|D]6?$ )
  if ( %match == 1 ) {
    ;/msg $chan DBG: $1 matched a negative number of dice
    return $calc($regml(negdice, 1) * -3)
  }

  ;Check as a positive dice bonus with additional pips:
  var %match = $regex(posdicewithpips, $1, ^\+?(\d+)[d|D]6?([\+|\-])(\d+)$ )
  if ( %match == 1 ) {
    ;/msg $chan DBG: $1 matched a positive number of dice with a bonus/penalty
    var %dice = $regml(posdicewithpips, 1)
    var %operand = $regml(posdicewithpips, 2)
    var %pips = $regml(posdicewithpips, 3)

    ;Operand is a plus symbol?
    if ( %operand == $chr(43) ) {
      var %piptotal = $calc( [ %dice * 3 ] + %pips)
      return %piptotal
    }
    else {
      var %piptotal = $calc( [ %dice * 3 ] - %pips)
      return %piptotal
    }
  } ;end if %match != 0

  ;Check as a negative dice bonus with additional pips:
  var %match = $regex(negdicewithpips, $1, ^\-(\d+)[d|D]6?([\+|\-])(\d+)$ )
  if ( %match == 1 ) {
    ;/msg $chan DBG: $1 matched a negative number of dice with a bonus/penalty
    var %dice = $regml(negdicewithpips, 1)
    var %operand = $regml(negdicewithpips, 2)
    var %pips = $regml(negdicewithpips, 3)

    ;Operand is a plus symbol?
    if ( %operand == $chr(43) ) {
      var %piptotal = $calc( [ %dice * -3 ] - %pips)
      return %piptotal
    }
    else {
      var %piptotal = $calc( [ %dice * -3 ] + %pips)
      return %piptotal
    }
  } ;end if %match != 0

  /msg $chan DBG: No match found for $1!
  return 0
}

alias rolld6 {
  var %fp = $1 / 3
  var %dice = $int(%fp)
  var %bonus = $1 % 3

  %d6.string = %dice $+ D
  if ( %bonus != 0 ) { %d6.string = %d6.string $+ $chr(43) $+ %bonus }

  unset %d6.total
  unset %d6.results
  unset %d6.wildtotal
  unset %d6.bonus

  %d6.highroll = 0
  %d6.wild = 0
  %d6.results = $chr(91)

  if ( %dice > 0 ) {
    ;/msg $chan DBG: rolling wild die
    %d6.wild = $rand(1,6)
    %d6.results = %d6.results $+ %d6.wild $+ $chr(42)
    %d6.total = %d6.wild

    ;/msg $chan DBG: finished wild die with ( %d6.wild %d6.results %d6.total %i )

    var %i = 1

    if ( %dice < 2 ) goto cancel
    :nextd6
    inc %i ;i should be 2 now

    ;/msg $chan DBG: rolling die %i

    var %roll = $rand(1,6)
    if ( %roll > %d6.highroll ) {
      %d6.highroll = %roll
    }

    %d6.results = %d6.results $+ $chr(44)
    %d6.results = %d6.results $+ %roll
    %d6.total = %d6.total + %roll

    if ( %i < %dice ) goto nextd6
    
    :cancel

    ;/msg $chan DBG: completed goto loop with %i (of %dice $+ )

  } ;end if %dice > 0

  %d6.results = %d6.results $+ $chr(93)

  if ( %bonus > 0 ) {
    %d6.bonus = $chr(43) $+ %bonus
    %d6.total = %d6.total + %bonus
  }
}

alias rollwild {
  var %roll = $rand(1,6)
  %d6.wildresults = $chr(91) $+ %roll
  %d6.wildtotal = %roll

  while ( %roll == 6 ) {
    %roll = $rand(1,6)

    %d6.wildresults = %d6.wildresults $+ $chr(44) $+ %roll
    %d6.wildtotal = %d6.wildtotal + %roll
  }

  %d6.wildresults = %d6.wildresults $+ $chr(93)

  return
}

alias rollforcomplication {
  if ( $rand(1,6) == 6 ) {
    return 1
  }
  return 0
}

alias reportmsg {
    if ( %d6.private == 2 ) /echo -t # %p $1-
    elseif ( %d6.private == 1 ) /notice $nick $1-
    else /msg $chan $1-
} 

on *:TEXT:!d6 *:#:{
  if ( %d6.enabled != 1 ) {
    /halt
  }
  %d6.private = 0
  /d6 $2-
  %unset %d6.private
}
on *:TEXT:!privd6 *:#:{
  if ( %d6.enabled != 1 ) {
    /halt
  }
  %d6.private = 1
  /d6 $2-
  %unset %d6.private
}
on *:TEXT:!d6 *:?:{
  if ( %d6.enabled != 1 ) {
    /halt
  }
  %d6.private = 1
  /d6 $2-
  %unset %d6.private
}
on *:INPUT:#:{
  if ($1 == !d6) {
    /say !d6 $2-
    /d6 $2-
    /halt
  }
}
on *:INPUT:?:{
  if ($1 == !d6) {
    %d6.private = 2
    $reportmsg( ( $+ $nick $+ ) !d6 $2- )
    /d6 $2-
    unset %d6.private
    /halt
  }
}