MyBB Community Forums

Full Version: Dice Rolling Newpoints
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello.  someone can explain and help me how to put dice rolling in a custom page in page manager.  he tries to do it and it doesn't work out
ie:
[Image: Page-Manager-Edit-Page.png]

Home » Page Manager » Add New Page

Quote:Name *
The name of your additional page.

NewPoints Dice

Quote:URI parameter *
This parameter will be used to point to your page. It is recommended to use alphanumeric characters only.

dice

Quote:Use MyBB Template?
Set this option to yes, if you want to include MyBB header and footer automatically. This will disable the possibility to use PHP in page content!
Yes
No

NO

Quote:Page content *

Type your page content here.

<?php
   $db->write_query("CREATE TABLE IF NOT EXISTS `".TABLE_PREFIX."dice` (
     `id` int(10) unsigned NOT NULL auto_increment,
     `user` varchar(240) NOT NULL,
     `bet` int(10) NOT NULL,
     `win` int(10) NOT NULL,
     PRIMARY KEY  (`id`)
   ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
                    ");
                    
   $mybbUser = $mybb->user['uid'];
   $mybbUserName = $mybb->user['username'];
   $query = $db->query("SELECT * FROM mybb_dice ORDER BY id DESC LIMIT 5");
   while($rolls = $db->fetch_array($query))
   {
   $diceArray[] = $rolls;
   } 
   
   $credits = floor($mybb->user['newpoints']);
   $result = "welcome";
   $win = 0;
   
   if (is_numeric($mybb->input['betamount']) && is_numeric($mybb->input['guess']))
   {
   if ($mybb->user['newpoints'] < $mybb->input['betamount'])
       {
       $result = "not enough credits :(";
       }
     else
       {
       $win = rand(1, 6);
       if ($mybb->input['betamount'] >= 10 && $mybb->input['betamount'] <= 500 && $mybb->input['guess'] >= 1 && $mybb->input['guess'] <= 6)
           {
           if ($mybb->input['guess'] == $win)
               {
               $winInfo = array(
       "user" => intval($mybbUser),
       "bet" => intval($mybb->input['betamount']),
       "win" => intval($mybb->input['betamount'] * 2),
   );
               newpoints_addpoints($mybb->user['uid'], $mybb->input['betamount'] * 2);
               $result = "won";
               $credits = $mybb->user['newpoints'] + ($mybb->input['betamount'] * 2);
               $db->insert_query("dice", $winInfo);
               }
             else
               {
               $winInfo = array(
       "user" => intval($mybbUser),
       "bet" => intval($mybb->input['betamount']),
       "win" => intval($mybb->input['betamount'] * -1),
   );
               newpoints_addpoints($mybb->user['uid'], $mybb->input['betamount'] * -1);
               $result = "lost";
               $credits = $mybb->user['newpoints'] - $mybb->input['betamount'];
                               $db->insert_query("dice", $winInfo);
               }
           }
         else
           {
           $result = "error";
           $win = "?";
           }
       }
   }
   else
   {
   $result = "enter numbers";
   $win = "#";
   }
   ?>
<html>
   <head>
      <title>Forum | Dice</title>
      <!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script> -->
      <script>
         var requestSent = false;
         $(document).ready(function() {
             $(function() {
                 $('#diceform').unbind().bind('submit', function(e) {
         var me = $(this);
             e.preventDefault();
         
             if ( me.data('requestRunning') ) {
                 return;
             }
         
             me.data('requestRunning', true);
                         e.preventDefault();
                         var form = $(this);
                         var post_url = form.attr('action');
                         var post_data = form.serialize();
                         $.ajax({
                             type: 'POST',
                             url: post_url,
                             data: post_data,
                             success: function(data) {
                                 var result = $('<div />').append(data).find('#row').html();
                                 $('#row').html(result);
                                 var recentrolls = $('<div />').append(data).find('.recentrolls').html();
                                 $('.recentrolls').html(recentrolls);
                             },
                             error: function(xhr, status) {
                                 alert("Sorry, there was a problem!");
                             },
                             complete: function(xhr, status) {
                                         me.data('requestRunning', false);
                             }
                         });
                     });
             });
         });
      </script>
      <style>
         @import url(https://fonts.googleapis.com/css?family=Lato);
         body {
         padding-top: 120px;
         }
         h1 {
         font-family: 'Lato', sans-serif;
         text-align: center;
         }
         .dice {
         border: 3px solid #333;
         border-radius: 3px;
         cursor: pointer;
         height: 100px;
         margin: 0 auto;
         overflow: hidden;
         width: 100px;
         }
         input[type="number"] {
         width: 150px;
         text-align: center;
         margin-bottom:4px;
         border: 2px solid #cacaca;
         }
         .roll.lost {
         background: #940000;
         }
         .recentrolls {
         position: relative;
         margin-left: 44.5%;
         margin: 0 auto;
         overflow: hidden;
         width: 150px;
         }
         .roll {
         color: #fff;
         padding: 2px;
         background:#3498DB;
         }
         input[type='number'] {
         -moz-appearance:textfield;
         }
         input::-webkit-outer-spin-button,
         input::-webkit-inner-spin-button {
         -webkit-appearance: none;
         }
         input#sendbutton {
         width: 150px;
         background: #fff;
         border: 2px solid #cacaca;
         }
         form {
         text-align: center;
         margin-top: 20px;
         }
         .side:hover {
         color: #fff;
         background: #000;
         }
         .dice:active {
         background: #333;
         }
         .dice:active .dot {
         border-color: white;
         }
         .side {
         height: 100px;
         position: relative;
         width: 100%;
         text-align: center;
         line-height: 100px;
         font-size: 100px;
         }
         .rollid {
         display: inline-block;
         color: #c3c3c3;
         text-align: left;
         width: 25%;
         }
         .rolluser {
         display: inline-block;
         /* margin-left: 10px; */
         width: 20%;
         text-align: center;
         }
         .rollbet {
         display: inline-block;
         }
         .rollwin {
         display: inline-block;
         float: right;
         }
         .roll.lost.rollwin {
         color: #f00 !important;
         }
         .rollbet {
         /* margin-left: 10px; */
         width: 20%;
         text-align: center;
         }
         .side:first-child {
         margin-top: -00px;
         transition: 2s;
         }
         .side.lost {
         background: #940000;
         color: #fff;
         }
         .roll.won {
         background: #1d9400;
         }
         .side.won {
         background: #1d9400;
         color: #fff;
         }
         .side.error {
         background: #000a92;
         color: #fff;
         }
      </style>
   </head>
   <div id="row">
      <h1>Credits: <?php echo $credits; ?></h1>
      <h1><?php echo $result;  ?></h1>
      <div class="dice">
         <div class="side <?php echo $result; ?>">
            <?php echo $win; ?>
         </div>
      </div>
   </div>
   <form method="post" id="diceform">
      <input type="number" id="guess" name="guess" placeholder="Guess (1-6)" min="1" max="6"><br>
      <input type="number" id="bet" name="betamount" placeholder="Bet (10-500)" min="10" max="500"><br>
      <input type="submit" id="sendbutton" value="Roll">
   </form>
   <div class="recentrolls">
      <div class="roll">
         <div class="rollid">ID</div>
         <div class="rolluser">User</div>
         <div class="rollbet">Bet</div>
         <div class="rollwin">Win</div>
      </div>
      <?php
         for( $i= 0 ; $i < count($diceArray) ; $i++ )
         {
             if ($diceArray[$i]['win'] > 0) 
             {
             echo "<div class=\"roll won\">";
             }
             else
             {
             echo "<div class=\"roll lost\">";
             }
             echo "<div class=\"rollid\">";
             echo $diceArray[$i]['id'];
             echo "</div>";
             echo "<div class=\"rolluser\">";
             echo $diceArray[$i]['user'];
             echo "</div>";
             echo "<div class=\"rollbet\">";
             echo $diceArray[$i]['bet'];
             echo "</div>";
             echo "<div class=\"rollwin\">";
             echo $diceArray[$i]['win'];
             echo "</div>";
             echo "</div>";
         }
         ?>
   </div>
</html>

Quote:Page enabled?
If you wish to disable this page, set this option to no.

YES

save


visit  your: forum/misc.php?page=dice

ie:
[Image: Forum-Dice.png]

[Image: Forum-Dice-1.png]

[Image: Forum-Dice-2.png]

note:
you may need to edit the page content further as I primarily only provided it "as is" here as part of the instructions you asked on how to add it as a page in page manager plugin and I have not looked at it further to see if there are anything that needs attention as one I don't have the free time nor do I have a use for this nor is it my creation and is merely something I saw provided back in 2017 hence any related knowledge came from a quick glance back then, nor do I use newpoints, though if someone did desire to use this and desired to they could say at some point fix any issues that may present themselves while using on via a page manager page and then convert such dice roller page to a plugin of its own rather than page manager page if one desired to do so, best of luck!
and you can arrange it so that the foot of mybb etc are visible ? 
Thank you for your help

I have one more question and how to do that instead of the user id it displays its name
(2021-03-09, 10:50 AM)Koper Wrote: [ -> ]and you can arrange it so that the foot of mybb etc are visible ? 
Thank you for your help


see this:

Quote: Wrote:Use MyBB Template?
Set this option to yes, if you want to include MyBB header and footer automatically. This will disable the possibility to use PHP in page content!
Yes
No

NO


That is set to NO because this page uses php and if you select YES for using mybb templates which is what you are asking for you will break this page though you could style this page and edit as you wish ( for example modify entirely to add template within to then pull and other such feature to achieve your eventual goal perhaps view the pages forum for such examples of other page manager pages that may have implementations that you could learn from, anyhoo, regardless just keep that setting set to: NO or as I suggested before or eventually turn this into a plugin yourself or find someone to do so


As for your other questions, sorry, but as I explained previously I only shared the setup instructions to help you get initial setup as that was your initial request, and as stated I do not currently have the free time nor desire to look at this further, nor do I use it or newpoints, so apologies, but, hopefully any other users that may have knowledge of such may continue to help you further if needed on further requests.

Best of luck! Big Grin Happy editing!
I have a Dice Rolling Plugin and while it is primarily designed to be used in threads for randomizing rolls, I could look into adding new functionality to it.