Advertisement
Guest User

Untitled

a guest
Jul 15th, 2016
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.44 KB | None | 0 0
  1. <?php
  2.  
  3. /*MyBB Dice Roller - Permenant Rolls, rolls created using this plugin cannot be edited.*/
  4.  
  5. if(!defined("IN_MYBB")) { die("Unauthorized"); }
  6.  
  7. $diceroll_salt = "";
  8. $diceroll_verificationvisible = true;
  9. $diceroll_enable = false;
  10.  
  11. function diceroll_info() {
  12. return array(
  13. "name" => "TJs Dice Roll Plugin",
  14. "Description" => "A plugin that creates a permenant dice-roll to attach to posts (Rolls CANNOT be edited/deleted)",
  15. "Website" => "http://101stdivision.net",
  16. "author" => "NINTHTJ",
  17. "authorsite" => "http://101stdivision.net",
  18. "version" => "1.1",
  19. "guid" => "",
  20. "compatibility" => "18*"
  21. );
  22. }
  23.  
  24. function diceroll_activate() {
  25. global $db;
  26. $diceroll_group = array(
  27. "gid" => "",
  28. "name" => "TJsDiceRollPlugin",
  29. "title" => "Dice Roller",
  30. "description" => "Dice Roll Settings",
  31. "disporder" => "1",
  32. "isdefault" => "0"
  33. );
  34.  
  35. $db -> insert_query("settinggroups",$diceroll_group);
  36. $gid = $db -> insert_id();
  37.  
  38. $diceroll_setting = array(
  39. 'sid' => 'NULL',
  40. "name" => "diceroll_enabled",
  41. "title" => "Dice roll system enabled?",
  42. "description" => "If you set this option to yes, dice rolls will be available on your board",
  43. "optionscode" => "yesno",
  44. "value" => "1",
  45. "disporder" => 1,
  46. "gid" => intval($gid)
  47. );
  48.  
  49. $db -> insert_query("settings",$diceroll_setting);
  50.  
  51. $diceroll_setting = array(
  52. 'sid' => 'NULL',
  53. "name" => "diceroll_salt",
  54. "title" => "Dice role salt (for verification)",
  55. "description" => "Set this value to be a string only your admins know. They can use it to verify the authenticity of roles.",
  56. "optionscode" => "text",
  57. "value" => "OJISndiujn91udndu9nasdu",
  58. "disporder" => 3,
  59. "gid" => intval($gid)
  60. );
  61.  
  62. $db -> insert_query("settings",$diceroll_setting);
  63.  
  64. $diceroll_setting = array(
  65. 'sid' => 'NULL',
  66. "name" => "diceroll_verificationvisible",
  67. "title" => "Is the verification code visible?",
  68. "description" => "If set to YES, the verification code will be visible on posts",
  69. "optionscode" => "yesno",
  70. "value" => "1",
  71. "disporder" => 2,
  72. "gid" => intval($gid)
  73. );
  74.  
  75. $db -> insert_query("settings",$diceroll_setting);
  76.  
  77. rebuild_settings();
  78.  
  79. $db -> add_column("posts","diceroll","text");
  80. }
  81.  
  82. function diceroll_deactivate() {
  83. global $db;
  84. $db -> query("DELETE FROM " . TABLE_PREFIX . "settings WHERE name IN ('diceroll_enabled')");
  85. $db -> query("DELETE FROM " . TABLE_PREFIX . "settings WHERE name IN ('diceroll_salt')");
  86. $db -> query("DELETE FROM " . TABLE_PREFIX . "settings WHERE name IN ('diceroll_verificationvisible')");
  87. $db -> query("DELETE FROM " . TABLE_PREFIX . "settinggroups WHERE name = 'TJsDiceRollPlugin'");
  88.  
  89. $db -> drop_column("posts","diceroll");
  90.  
  91. rebuild_settings();
  92. }
  93.  
  94. $plugins -> add_hook("global_start","diceroll_init");
  95. function diceroll_init() {
  96. global $db;
  97. global $diceroll_salt;
  98. global $diceroll_verificationvisible;
  99. global $diceroll_enable;
  100. global $plugins;
  101. $result = $db -> query("SELECT * FROM " . TABLE_PREFIX . "settings WHERE name IN ('diceroll_salt')");
  102. $diceroll_salt = $db -> fetch_field($result,"value");
  103. $result = $db -> query("SELECT * FROM " . TABLE_PREFIX . "settings WHERE name IN ('diceroll_verificationvisible')");
  104. $diceroll_verificationvisible = $db -> fetch_field($result,"value");
  105. $result = $db -> query("SELECT * FROM " . TABLE_PREFIX . "settings WHERE name IN ('diceroll_enabled')");
  106. $diceroll_enable = $db -> fetch_field($result,"value");
  107. if($diceroll_enable) {
  108. $plugins->add_hook("datahandler_post_insert_post", "diceroll_roll");
  109. $plugins->add_hook("datahandler_post_insert_thread_post", "diceroll_roll");
  110. $plugins -> add_hook("postbit","diceroll_appendrolls");
  111. }
  112. }
  113.  
  114. /**************************************************************************/
  115.  
  116. function diceroll_roll(&$post)
  117. {
  118. global $db;
  119. $msg = $post->post_insert_data['message'];
  120. $rollArray = array();
  121. $matches = array();
  122. preg_match_all("!\[roll ([A-z0-9]+) ([0-9]+)k([0-9]+)\]!i",$msg,$matches,PREG_SET_ORDER);
  123.  
  124. if($matches)
  125. {
  126. foreach($matches as $match)
  127. {
  128. $rollName = $match[1];
  129. $rolledDice = $match[2];
  130. $keptDice = $match[3];
  131. $bonus = 0;
  132. $rollType = "Skilled";
  133. $explodeOn = 10;
  134.  
  135. if( $rollName && $rolledDice > 0 && $keptDice > 0 )
  136. {
  137. while( $rolledDice > 10 )
  138. {
  139. if( $keptDice <= 10 )
  140. {
  141. $rolledDice -= $rolledDice % 2;
  142.  
  143. $olledDice -= 2;
  144. $keptDice ++;
  145. }
  146. else
  147. {
  148. $rolledDice--;
  149. $bonus += 2;
  150. }
  151. }
  152.  
  153. if( $keptDice >= $rolledDice )
  154. {
  155. if( $rolledDice == 10 )
  156. {
  157. $bonus += 2 * ( $keptDice - 10);
  158. }
  159.  
  160. $keptDice = $rolledDice;
  161. }
  162.  
  163. for($roll = 0; $roll < $rolledDice; $roll ++)
  164. {
  165. $rollArray[$rollName][$keptDice][$roll] = 0;
  166.  
  167. $num = rand(1,10);
  168.  
  169. if( $rollType == "Emphasis" && $num == 1 )
  170. {
  171. $num = rand(1,10);
  172. }
  173.  
  174. while( $rollType != "Unskilled" && $num >= $explodeOn )
  175. {
  176. $rollArray[$rollName][$keptDice][$roll] += $num;
  177. $num = rand(1,10);
  178. }
  179.  
  180. $rollArray[$rollName][$keptDice][$roll] += $num;
  181.  
  182. }
  183.  
  184. sort($rollArray[$rollName][$keptDice]);
  185. }
  186.  
  187. $post -> post_insert_data['message'] = str_replace($match[0],"",$post -> post_insert_data['message']);
  188. }
  189.  
  190. $saveString = serialize($rollArray);
  191. $post->post_insert_data['diceroll'] = $db -> escape_string($saveString);
  192. }
  193. }
  194.  
  195. function diceroll_appendrolls(&$post)
  196. {
  197. global $diceroll_salt;
  198. global $diceroll_verificationvisible;
  199.  
  200. if($post['diceroll'])
  201. {
  202. $rollArray = @unserialize($post['diceroll']);
  203.  
  204. if(is_array($rollArray))
  205. {
  206. if(count($rollArray) > 0)
  207. {
  208. $post['message'] .= '<br /><br /><span style="color:purple;"><i>Dice rolls attached to this post:</i><br />';
  209.  
  210. if($diceroll_verificationvisible)
  211. {
  212. $post['message'] .= 'Verification Code: ' . sha1($diceroll_salt . $post['pid']) . '<br />';
  213. }
  214.  
  215. foreach($rollArray as $rollName => $sidedDice)
  216. {
  217. foreach($sidedDice as $numberOfSides => $result)
  218. {
  219. $post['message'] .= '<br /><i>' . $rollName . ' (' . $numberOfSides . ' sided dice):';
  220. $appendRolls = '';
  221. $totalResult = 0;
  222. $count = 0;
  223.  
  224. foreach($result as $rollOffset => $rollResult)
  225. {
  226. if($count > 0)
  227. {
  228. $appendRolls .= ',';
  229. }
  230.  
  231. $appendRolls .= ($rollOffset + 1) . '=' . $rollResult;
  232. $totalResult += $rollResult;
  233. $count ++;
  234. }
  235.  
  236. if($count > 1)
  237. {
  238. $appendRolls .= ' = ' . $totalResult;
  239. }
  240. else
  241. {
  242. $appendRolls = $totalResult;
  243. }
  244.  
  245. $post['message'] .= $appendRolls;
  246. }
  247.  
  248. $post['message'] .= '</i>';
  249. }
  250.  
  251. $post['message'] .= '</span>';
  252. }
  253. }
  254. }
  255. }
  256.  
  257.  
  258. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement