Guest User

Untitled

a guest
Sep 23rd, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.24 KB | None | 0 0
  1. <?php
  2.  
  3. function dice_init() {
  4.    global $hooks;
  5.  
  6.    $hooks['posting'][] = 'dice';
  7. }
  8.  
  9. function dice_authorized($board) {
  10.    return true;
  11. }
  12.  
  13. function dice_info() {
  14.    $info = array();
  15.    $info['type']['board-specific'] = false;
  16.  
  17.    return $info;
  18. }
  19.  
  20. function dice_settings() {
  21.    $settings = array();
  22. }
  23.  
  24. function dice_help() {
  25.    $output = '#dice8d5: roles 8,5 sided dice';
  26.    return $output;
  27. }
  28.  
  29. function dice_process_posting($post) {
  30.    $magicWord = '#';
  31.    $activationFieldText = $post['email'];
  32.    $trigger = '/^#' . $magicWord . '([0-9]+)d([0-9]+)##$/';
  33.    preg_match_all($trigger, $activationFieldText, $regs);
  34.    if ($regs[0] == null) {
  35.        return $post;
  36.    }
  37.    $faces = $regs[2][0]; // Number of faces of the dice
  38.    $dices = $regs[1][0]; // Number of dices
  39. $d = 'd';
  40.  
  41.    $result = 0;
  42.    $count = 0;
  43.    while ($dices != $count) {
  44.        $value = mt_rand(1, $faces);
  45.        $result = $result + $value;
  46.        $count++;
  47.    }
  48.    $message = "<br><b>$dices$d$faces Результат: $result &nbsp;&nbsp; </b></div><br>";
  49.     $post['message'] .= '<span class="dice">' . $message . '</span>' .
  50.             $post['email'] = '';
  51.     $post['email_save'] = false;
  52.  
  53.     return $post;
  54. }
  55.  
  56. ?>
Add Comment
Please, Sign In to add comment