Makaze

Dice_Concise Draft 1 for mIRC

Jan 15th, 2014
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 6.44 KB | None | 0 0
  1. ; dice_concise / Based on Marcel Kossin's 'dice' RP Dice Simulator for Irssi
  2. ;
  3. ; What is this?
  4. ;
  5. ; -- Marcel Kossin's notes: --
  6. ;
  7. ; I (mkossin) often Dungeon Master on our Neverwinternights Servers called 'Bund der
  8. ; alten Reiche' (eng. 'Alliance of the old realms') at bundderaltenreiche.de
  9. ; (German Site) Often idling in our Channel I thought it might be Fun to have
  10. ; a script to dice. Since I found nothing for irssi I wrote this little piece
  11. ; of script. The script assumes, that if a 'd' for english dice is given it
  12. ; should print the output in English. On the other hand if a 'w' for German
  13. ; 'Würfel' is given it prints the output in German.
  14. ;
  15. ; Usage.
  16. ;
  17. ; Anyone on the Channel kann ask '!roll' to toss the dice for him. He just has
  18. ; to say what dice he want to use. The notation should be well known from
  19. ; RP :-) Thus
  20. ;
  21. ; Write: !roll <quantity of dice>d[or w for german users]<sides on dice>
  22. ;
  23. ; Here are some examples
  24. ;
  25. ; !roll 2d20
  26. ; !roll 3d6
  27. ;
  28. ; OK, I think you got it already :-)
  29. ;
  30. ; Write: !roll version
  31. ; For Version Information
  32. ;
  33. ; Write: !roll help
  34. ; For Information about how to use it
  35. ;
  36. ; -- Makaze's notes: --
  37. ;
  38. ; [Changes in dice_concise:]
  39. ;
  40. ; Features added:
  41. ;
  42. ; [ ] Can add bonuses to the roll. e.g. "!roll 3d6+10"
  43. ; [ ] Output changed to one line only. e.g. "Makaze rolls the 3d6 and gets: 9 [4,
  44. ;     4, 1]"
  45. ; [ ] Corrected English grammar.
  46. ; [ ] Removed insults.
  47. ; [ ] Cleaner code with fewer nested if statements and true case switches.
  48. ; [ ] Errors call before the loop, saving clock cycles.
  49. ;
  50. ; Bugs fixed:
  51. ;
  52. ; [ ] Rolls within the correct range.*
  53. ;
  54. ; Edge cases added:
  55. ;
  56. ; [ ] Catch if rolling less than 1 dice.
  57. ; [ ] Catch if dice or sides are above 100 instead of 99.
  58. ;
  59. ; -----------------------------------------
  60. ;
  61. ; * [The original dice.pl rolled a number between 1 and (<number of sides> - 1)]
  62. ;   [instead of using the msg range. e.g. "!roll 1d6" would output 1 through   ]
  63. ;   [5, but never 6.                                                           ]
  64. ;
  65. ; -----------------------------------------
  66. ;
  67. ; Original script 'dice.pl' by mkossin.
  68. ;
  69. ; Ported and updated script 'dice_concise.mrc' by Makaze.
  70. ;
  71. ; Special thanks to SmartRutter for help with debugging.
  72. ;
  73. ; Licensed under GNU GPL v2 or later.
  74.  
  75. on $*:Text:/^!roll/i:#:{
  76.     if ($2 == $null) {
  77.         msg $chan "!roll help" - gives the English help
  78.         msg $chan "!roll hilfe" - zeigt die deutsche Hilfe an
  79.         halt
  80.     }
  81.  
  82.     var %VERSION = 0.1.0
  83.     var %msg = $$2
  84.  
  85.     if ($regex(roll, %msg, /(\d+)([dw])(\d+)/i)) {
  86.         var %forloop = 0
  87.         var %lang
  88.         var %case
  89.         var %dice = $regml(roll, 1)
  90.         var %sides = $regml(roll, 3)
  91.         var %main
  92.         var %value = 0
  93.         var %plus
  94.  
  95.         if ($regml(roll, 2) == w) {
  96.             %lang = DE
  97.         }
  98.         else {
  99.             %lang = EN
  100.         }
  101.  
  102.         if ($regex(%msg, /\+/i)) {
  103.             if ($regex(bonus, %msg, /\+(\d+)/i)) {
  104.                 %plus = $regml(bonus, 1)
  105.                 inc %value %plus
  106.             }
  107.             else {
  108.                 var %error.add = 1
  109.             }
  110.             %main = $gettok(%msg, 1, 43)
  111.         }
  112.         else {
  113.             %main = %msg
  114.         }
  115.  
  116.         if (%dice < 1) {
  117.             if (%lang == DE) {
  118.                 msg $chan $nick macht nichts... Würfeln funktioniert am besten mit Würfeln.
  119.             }
  120.             else {
  121.                 msg $chan $nick does nothing... Rolling dice works best with dice.
  122.             }
  123.             halt
  124.         }
  125.         elseif (%dice > 100) {
  126.             if (%lang == DE) {
  127.                 msg $chan $nick scheitert den %msg zu werfen... Versuch es mit weniger Würfeln.
  128.             }
  129.             else {
  130.                 msg $chan $nick fails to roll the %msg $+ ... Try fewer dice.
  131.             }
  132.             halt
  133.         }
  134.         elseif (%sides <= 1) {
  135.             if (%sides == 0) {
  136.                 if (%lang == DE) {
  137.                     msg $chan $nick verursacht ein Paradox... Oder hat jemand schon mal einen Würfel ohne Seiten gesehen?
  138.                 }
  139.                 else {
  140.                     msg $chan $nick causes a paradox... Or has anybody ever seen a die without sides?
  141.                 }
  142.                 halt
  143.             }
  144.             elseif (%sides == 1) {
  145.                 if (%lang == DE) {
  146.                     msg $chan $nick verursacht ein Paradox... Oder hat jemand schon mal einen Würfel mit nur einer Seite gesehen?
  147.                 }
  148.                 else {
  149.                     msg $chan $nick causes a paradox... Or has anybody ever seen a die with only one side?
  150.                 }
  151.                 halt
  152.             }
  153.         }
  154.         elseif (%sides > 100) {
  155.             if (%lang == DE) {
  156.                 msg $chan $nick scheitert den %msg zu werfen... Versuch es mit weniger Augen.
  157.             }
  158.             else {
  159.                 msg $chan $nick fails to roll the %msg $+ ... Try fewer sides.
  160.             }
  161.             halt
  162.         }
  163.  
  164.         var %rolls
  165.  
  166.         while (%forloop < %dice) {
  167.             var %rnd = $rand(1, %sides)
  168.             inc %value %rnd
  169.             if (%forloop == 0) {
  170.                 %rolls = %rnd
  171.             }
  172.             else {
  173.                 %rolls = %rolls $+ , %rnd
  174.             }
  175.             inc %forloop
  176.         }
  177.  
  178.         %rolls = [ $+ %rolls
  179.         %rolls = %rolls $+ ]
  180.  
  181.         if (%lang == DE) {
  182.             msg $chan $nick würfelt mit dem %msg und erhält: %value %rolls
  183.         }
  184.         else {
  185.             msg $chan $nick rolls the %msg and gets: %value %rolls
  186.         }
  187.  
  188.         if (%error.add) {
  189.             if (%lang == DE) {
  190.                 msg $chan $nick scheitert mehr zum Ergebnis hinzuzufügen. Versuch Zahlen zu addieren.
  191.             }
  192.             else {
  193.                 msg $chan $nick fails to add to their result. Try adding numbers.
  194.             }
  195.         }
  196.         halt
  197.     }
  198.     elseif (%msg == version) {
  199.         msg $chan dice_concise version %VERSION by Makaze
  200.         halt
  201.     }
  202.     elseif (%msg == help) {
  203.         msg $chan Syntax: "!roll <quantity of dice>d<sides on dice>" - e.g. "!roll 2d20"
  204.         halt
  205.     }
  206.     elseif (%msg == hilfe) {
  207.         msg $chan Syntax: "!roll <Anzahl der Würfel>w<Augen des Würfels>" - z.B. "!roll 2w20"
  208.         halt
  209.     }
  210.     else {
  211.         msg $chan "!roll help" - gives the English help
  212.         msg $chan "!roll hilfe" - zeigt die deutsche Hilfe an
  213.         halt
  214.     }
  215. }
Advertisement
Add Comment
Please, Sign In to add comment