jmyeom

dice roller module

Mar 29th, 2012
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. save as inc/modules/dice.php
  2. paste the text below into it, all of it, and then call it using the email field of: #dice25d6
  3. that will roll 25 dice, each dice having six sides,
  4. it can be anything!
  5. #dice100d23 will roll 100 dice, each with 23 sides!
  6.  
  7.  
  8. paste below here into dice.php
  9.  
  10.  
  11.  
  12. <?php
  13.  
  14. function dice_init() {
  15. global $hooks;
  16.  
  17. $hooks['posting'][] = 'dice';
  18. }
  19.  
  20. function dice_authorized($board) {
  21. return true;
  22. }
  23.  
  24. function dice_info() {
  25. $info = array();
  26. $info['type']['board-specific'] = false;
  27.  
  28. return $info;
  29. }
  30.  
  31. function dice_settings() {
  32. $settings = array();
  33. }
  34.  
  35. function dice_help() {
  36. $output = '#dice8d5: roles 8,5 sided dice';
  37. return $output;
  38. }
  39.  
  40. function dice_process_posting($post) {
  41. $magicWord = 'dice';
  42. $activationFieldText = $post['email'];
  43. $trigger = '/^#' . $magicWord . '([0-9]+)d([0-9]+)$/';
  44. preg_match_all($trigger, $activationFieldText, $regs);
  45. if ($regs[0] == null) {
  46. return $post;
  47. }
  48. $faces = $regs[2][0]; // Number of faces of the dice
  49. $dices = $regs[1][0]; // Number of dices
  50.  
  51. $result = 0;
  52. $count = 0;
  53. while ($dices != $count) {
  54. $value = mt_rand(1, $faces);
  55. $result = $result + $value;
  56. $count++;
  57. }
  58. $message = "<br><b style=\"border-style: solid; margin:0 3px; border-width: 2px; color: rgb(48, 115, 237); background: none repeat scroll 0% 0% rgb(0, 0, 0); padding: 0px;\"> &nbsp; Rolled $dices dice with $faces faces: $result &nbsp;&nbsp; </b></div><br>";
  59. $post['message'] .= '<span style="color: red; background-color: black;"> </span> ' . $message . '<br><br>' .
  60. $post['email'] = '';
  61. $post['email_save'] = false;
  62.  
  63. return $post;
  64. }
  65.  
  66. ?>
Advertisement
Add Comment
Please, Sign In to add comment