Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*MyBB Dice Roller - Permenant Rolls, rolls created using this plugin cannot be edited.*/
- if(!defined("IN_MYBB")) { die("Unauthorized"); }
- $diceroll_salt = "";
- $diceroll_verificationvisible = true;
- $diceroll_enable = false;
- function diceroll_info()
- {
- return array(
- "name" => "TJs Dice Roll Plugin",
- "Description" => "A plugin that creates a permenant dice-roll to attach to posts (Rolls CANNOT be edited/deleted)",
- "Website" => "http://101stdivision.net",
- "author" => "NINTHTJ",
- "authorsite" => "http://101stdivision.net",
- "version" => "1.1",
- "guid" => "",
- "compatibility" => "18*"
- );
- }
- function diceroll_activate()
- {
- global $db;
- $diceroll_group = array(
- "gid" => "",
- "name" => "TJsDiceRollPlugin",
- "title" => "Dice Roller",
- "description" => "Dice Roll Settings",
- "disporder" => "1",
- "isdefault" => "0"
- );
- $db -> insert_query("settinggroups",$diceroll_group);
- $gid = $db -> insert_id();
- $diceroll_setting = array(
- 'sid' => 'NULL',
- "name" => "diceroll_enabled",
- "title" => "Dice roll system enabled?",
- "description" => "If you set this option to yes, dice rolls will be available on your board",
- "optionscode" => "yesno",
- "value" => "1",
- "disporder" => 1,
- "gid" => intval($gid)
- );
- $db -> insert_query("settings",$diceroll_setting);
- $diceroll_setting = array(
- 'sid' => 'NULL',
- "name" => "diceroll_salt",
- "title" => "Dice role salt (for verification)",
- "description" => "Set this value to be a string only your admins know. They can use it to verify the authenticity of roles.",
- "optionscode" => "text",
- "value" => "OJISndiujn91udndu9nasdu",
- "disporder" => 3,
- "gid" => intval($gid)
- );
- $db -> insert_query("settings",$diceroll_setting);
- $diceroll_setting = array(
- 'sid' => 'NULL',
- "name" => "diceroll_verificationvisible",
- "title" => "Is the verification code visible?",
- "description" => "If set to YES, the verification code will be visible on posts",
- "optionscode" => "yesno",
- "value" => "1",
- "disporder" => 2,
- "gid" => intval($gid)
- );
- $db -> insert_query("settings",$diceroll_setting);
- rebuild_settings();
- $db -> add_column("posts","diceroll","text");
- }
- function diceroll_deactivate()
- {
- global $db;
- $db -> query("DELETE FROM " . TABLE_PREFIX . "settings WHERE name IN ('diceroll_enabled')");
- $db -> query("DELETE FROM " . TABLE_PREFIX . "settings WHERE name IN ('diceroll_salt')");
- $db -> query("DELETE FROM " . TABLE_PREFIX . "settings WHERE name IN ('diceroll_verificationvisible')");
- $db -> query("DELETE FROM " . TABLE_PREFIX . "settinggroups WHERE name = 'TJsDiceRollPlugin'");
- $db -> drop_column("posts","diceroll");
- rebuild_settings();
- }
- $plugins -> add_hook("global_start","diceroll_init");
- function diceroll_init()
- {
- global $db;
- global $diceroll_salt;
- global $diceroll_verificationvisible;
- global $diceroll_enable;
- global $plugins;
- $result = $db -> query("SELECT * FROM " . TABLE_PREFIX . "settings WHERE name IN ('diceroll_salt')");
- $diceroll_salt = $db -> fetch_field($result,"value");
- $result = $db -> query("SELECT * FROM " . TABLE_PREFIX . "settings WHERE name IN ('diceroll_verificationvisible')");
- $diceroll_verificationvisible = $db -> fetch_field($result,"value");
- $result = $db -> query("SELECT * FROM " . TABLE_PREFIX . "settings WHERE name IN ('diceroll_enabled')");
- $diceroll_enable = $db -> fetch_field($result,"value");
- if($diceroll_enable)
- {
- $plugins->add_hook("datahandler_post_insert_post", "diceroll_roll");
- $plugins->add_hook("datahandler_post_insert_thread_post", "diceroll_roll");
- $plugins -> add_hook("postbit","diceroll_appendrolls");
- }
- }
- /**************************************************************************/
- function diceroll_roll(&$post)
- {
- global $db;
- $msg = $post->post_insert_data['message'];
- $rollArray = array();
- $matches = array();
- preg_match_all("!\[roll([\.|\!]?) ([0-9a-z ]+) ([0-9]{1,2})k([0-9]{1,2})\]!i",$msg,$matches,PREG_SET_ORDER);
- // \[roll([\.|\!]?) ([0-9a-z ]+) ([0-9]{1,2})k([0-9]{1,2})([^\]]*)\]
- //? would \[roll([^\]]*)\] and then regex $match[1] be faster?
- if($matches)
- {
- foreach($matches as $match)
- {
- $rollType = 'Skilled';
- if( $match[1] == '.')
- {
- $rollType = 'Unskilled';
- }
- else if( $match[1] == '!')
- {
- $rollType = 'Emphasis';
- }
- $rollName = $match[2];
- $rolledDice = $match[3];
- $keptDice = $match[4];
- $tags = $match[5];
- $bonus = 0;
- $explodeOn = 10;
- if( $rollName && $rolledDice > 0 && $keptDice > 0 )
- {
- while( $rolledDice > 10 )
- {
- if( $keptDice <= 10 )
- {
- $rolledDice -= $rolledDice % 2;
- $olledDice -= 2;
- $keptDice ++;
- }
- else
- {
- $rolledDice--;
- $bonus += 2;
- }
- }
- if( $keptDice >= $rolledDice )
- {
- if( $rolledDice == 10 )
- {
- $bonus += 2 * ( $keptDice - 10);
- }
- $keptDice = $rolledDice;
- }
- //$rollArray[$rollName]['Tags'] = $bonus . ' ' . $rollType . ' ' . $tags;
- for($roll = 0; $roll < $rolledDice; $roll ++)
- {
- $rollArray[$rollName][$keptDice][$roll] = 0;
- $num = rand(1,10);
- if( $rollType == 'Emphasis' && $num == 1 )
- {
- $num = rand(1,10);
- }
- while( $rollType != 'Unskilled' && $num >= $explodeOn )
- {
- $rollArray[$rollName][$keptDice][$roll] += $num;
- $num = rand(1,10);
- }
- $rollArray[$rollName][$keptDice][$roll] += $num;
- }
- sort($rollArray[$rollName][$keptDice]);
- }
- $replace = '['.$rollName.']';
- $post['message'] -> post_insert_data['message'] = str_replace($match[0],$replace,$post -> post_insert_data['message']);
- }
- $saveString = serialize($rollArray);
- $post->post_insert_data['diceroll'] = $db -> escape_string($saveString);
- }
- }
- function diceroll_appendrolls(&$post)
- {
- global $diceroll_salt;
- global $diceroll_verificationvisible;
- if($post['diceroll'])
- {
- $rollArray = @unserialize($post['diceroll']);
- if(is_array($rollArray))
- {
- if(count($rollArray) > 0)
- {
- $post['message'] .= '<br /><br /><span style="color:purple;"><i>Dice rolls attached to this post:</i>';
- foreach($rollArray as $rollName => $rolledPool)
- {
- //+$tags = $rollArray[$rollName]['Tags'];
- $rollType = 'Skilled'; //match[2] in tags
- $bonus = 0; //match[1] in tags
- $calledRaises = 0; //regex 'cr#'
- $freeRaises = 0; //regex 'fr#'
- ///
- $voidSpent = 0; //regex 'v#'
- $explodeOn = 10; //regex 'E#'
- ///
- foreach( $rolledPool as $keptDice => $dice )
- {
- $post['message'] .= '<br /><i>' . $rollName . ' (';
- if( $rollType == 'Unskilled' )
- {
- $post['message'] .= 'Unskilled ';
- }
- $post['message'] .= count($dice) . 'K' . $keptDice;
- if( $bonus != 0 )
- {
- $post['message'] .= ' ';
- if( $bonus > 0 )
- {
- $post['message'] .= '+';
- }
- $post['message'] .= $bonus;
- }
- if( $rollType == 'Emphasis' )
- {
- $post['message'] .= ' with Emphasis';
- }
- if( $calledRaises > 0 )
- {
- $post['message'] .= ' ' . $calledRaises . ' called Raises';
- }
- $post['message'] .= '): ';
- $appendRolls = '';
- $highestKept = 0;
- $count = 0;
- foreach( $dice as $diceNum => $rollResult )
- {
- if( $count > 0 )
- {
- $appendRolls .= ', ';
- }
- if( $count >= count($dice) - $keptDice )
- {
- $highestKept += $rollResult;
- }
- $appendRolls .= $rollResult;
- $count ++;
- }
- $highestKept += $bonus;
- if( $calledRaises > 0 )
- {
- $highestKept -= $calledRaises * 5;
- }
- if( $count > 1 )
- {
- $appendRolls .= ' = ' . $highestKept;
- }
- else
- {
- $appendRolls = $highestKept;
- }
- if( $freeRaises > 0 )
- {
- $appendRolls .= ' with ' . $freeRaises . ' free Raises';
- }
- $post['message'] .= $appendRolls;
- }
- $post['message'] .= '</i>';
- }
- if($diceroll_verificationvisible)
- {
- $post['message'] .= '<br /><br />Verification Code: ' . sha1($diceroll_salt . $post['pid']) . '<br />';
- }
- $post['message'] .= '</span>';
- }
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement