Awesome. Everything is working perfectly except one thing.
<?php
/*================================*\
|| RPG Statistics v1.0.0 - by Sam ||
\*================================*/
// Idiot-Poofing \\
if(!defined('IN_MYBB'))
{
die('This file cannot be accessed directly!');
}
// Hook It \\
$plugins->add_hook('postbit', 'rpgstats_postbit');
// Plugin Infos \\
function rpgstats_info() {
return array(
'name' => 'RPG Statistics',
'description' => 'This plugin generates RPG stats and displays them on postbits.',
'website' => 'http://s43.eclipstice.com',
'author' => 'Sam',
'authorsite' => 'http://s43.eclipstice.com',
'version' => '1.0.0',
'guid' => '69696969696969696969696969',
'compatibility' => '14*',
);
}
// Activate The Plugin \\
function rpgstats_activate() {
// Necessary Stuff \\
require MYBB_ROOT.'/inc/adminfunctions_templates.php';
global $db;
// Create the Setting Group \\
$rpgstat_group = array(
'name' => 'rpgstats',
'title' => 'RPG Statistics',
'description' => 'This selection allows you to make small tweaks to the general functionality of the RPG Statistics plugin.',
'disporder' => '100',
'isdefault' => 'no',
);
// Insert the Setting Group Into the Databutz \\
$db->insert_query('settinggroups',$rpgstat_group);
$gid = $db->insert_id();
// Create Individual Settings \\
// This is for the on/off setting.
$rpgstat_setting_1 = array(
'name' => 'rpgonoff',
'title' => 'RPG Offline',
'description' => $db->escape_string('Do you want to show generated RPG statistics on users\' postbits?'),
'optionscode' => 'onoff',
'value' => 'on',
'disporder' => '1',
'gid' => intval($gid),
);
// This is for the buff multiple.
$rpgstat_setting_2 = array(
'name' => 'rpgbuff',
'title' => 'Buff Multiple',
'description' => 'The generated HP and MP will be multiplied by this number.',
'optionscode' => 'text',
'value' => '10',
'disporder' => '2',
'gid' => intval($gid),
);
// Insert the Settings Into the Databutz \\
$db->insert_query('settings', $rpgstat_setting_1);
$db->insert_query('settings', $rpgstat_setting_2);
// Create a Template \\
$rpgstat_template = array(
"title" => 'postbit_author_rpg',
"template" => $db->escape_string('
<table width="100%">
<tr>
<td width="33%">
<span class="smalltext"><span style="font-weight:bold;">HP:</span> {$hpcur} / {$hpmax}</span><br />
{$hpbar}<br />
<span class="smalltext"><span style="font-weight:bold;">Level:</span> {$level}</span>
</td>
<td width="33%">
<span class="smalltext"><span style="font-weight:bold;">MP:</span> {$mpcur} / {$mpmax}</span><br />
{$mpbar}
</td>
<td width="33%">
<span class="smalltext"><span style="font-weight:bold;">EXP:</span> {$exptotal}</span><br />
{$expbar}<br />
<span class="smalltext"><span style="font-weight:bold;">To Next:</span> {$expnext} ({$expcent}%)</span>
</td>
</tr>
</table>
'),
'sid' => '-1',
);
// Insert the Template Into the Databutz \\
$db->insert_query('templates',$rpgstat_template);
// This inserts RPG stats var into postbit tempaltes.
find_replace_templatesets('postbit', "#".preg_quote("{\$post['button_delete_pm']}")."#", "{\$post['button_delete_pm']}<br />{\$rpg_details}");
find_replace_templatesets('postbit_classic', "#".preg_quote("{\$post['button_delete_pm']}")."#", "{\$post['button_delete_pm']}<br />{\$rpg_details}");
// Rebuild Settings \\
rebuild_settings();
}
// Deactivate The Plugin \\
function rpgstats_deactivate() {
// Necessary Stuff \\
require MYBB_ROOT."/inc/adminfunctions_templates.php";
global $db;
// Delete Settings \\
$db->write_query("DELETE FROM ".TABLE_PREFIX."settings WHERE name IN('rpgonoff','rpgbuff')");
// Delete Setting Group \\
$db->write_query("DELETE FROM ".TABLE_PREFIX."settinggroups WHERE name='rpgstats'");
// Delete Template \\
$db->write_query("DELETE FROM ".TABLE_PREFIX."templates WHERE title='postbit_author_rpg'");
// This removes RPG stats var from the postbit templates.
find_replace_templatesets('postbit', "#".preg_quote("{\$rpg_details}")."#", "");
find_replace_templatesets('postbit_classic', "#".preg_quote("{\$rpg_details}")."#", "");
// Rebuilt Settings \\
rebuild_settings();
}
// Math \\
function rpgstats_postbit($post) {
global $mybb, $templates, $rpgstats;
if($mybb->settings['rpgonoff'] != 'off') {
// Buff HP and MP \\
$hp = $hp * $mybb->settings['rpgbuff'];
$mp = $mp * $mybb->settings['rpgbuff'];
eval("\$rpg_details = \"".$templates->get('postbit_author_rpg')."\";");
}
// This Was All Done by Ryan Ashbrook \\
global $mybb, $db;
$post['postnum'] = str_replace($mybb->settings['thousandssep'], '', $post['postnum']);
$daysreg = (time() - $post['regdate']) / (24*3600);
$postsperday = $post['postnum'] / $daysreg;
$postsperday = round($postsperday, 2);
if($postsperday > $post['postnum']) {
$postsperday = $post['postnum'];
}
$rpglvl = $post['postnum'];
$level = pow (log10 ($rpglvl), 3);
$ep = floor (100 * ($level - floor ($level)));
$showlevel = floor ($level + 1);
$hpmulti = round ($postsperday / 6, 1);
if ($hpmulti > 1.5) {
$hpmulti = 1.5;
}
if ($hpmulti < 1) {
$hpmulti = 1;
}
$maxhp = $level * 25 * $hpmulti;
$hp = $postsperday / 1;
if ($hp >= 1) {
$hp = $maxhp;
}
else {
$hp = floor ($hp * $maxhp);
}
$hp = floor ($hp);
$maxhp = floor ($maxhp);
if ($maxhp <= 0) {
$zhp = 1;
}
else {
$zhp = $maxhp;
}
$hpf = floor (100 * ($hp / $zhp)) - 1;
$maxmp = ($daysreg * $level) / 5;
$mp = $rpglvl / 3;
if ($mp >= $maxmp) {
$mp = $maxmp;
}
$maxmp = floor ($maxmp);
$mp = floor ($mp);
if ($maxmp <= 0) {
$zmp = 1;
}
else {
$zmp = $maxmp;
}
$mpf = floor (100 * ($mp / $zmp)) - 1;
$showlevel = my_number_format($showlevel);
$maxhp = my_number_format($maxhp);
$hp = my_number_format($hp);
$maxmp = my_number_format($maxmp);
$mp = my_number_format($mp);
// Back to Me! Me, me, me! \\
// This calculates all the other EXP parameters.
$delevel = $showlevel - 1;
$earnedexp = $delevel * 1000;
$remainexp = $ep * 10;
$totalexp = $earnexp + $remainexp;
$nextexp = $showlevel * 1000;
$totalexp = my_number_format($totalexp);
$nextexp = my_number_format($nextexp);
// Set Parameter Vars \\
$level = '{$showlevel}';
$hpcur = '{$hp}';
$hpmax = '{$maxhp}';
$hpbar = '
<table class="rpg1" align="center" width="100px" cellspacing="0">
<tr>
<td class="rpg2" nowrap="nowrap">
<img src="images/rpg/bhg.gif" alt="{$post[\'username\']}\'s HP" width="{$hpf}%" height="8px" /><img alt="{$post[\'username\']}\'s HP" src="images/rpg/bhb.gif" width="1px" height="8px" />
</td>
</tr>
</table>
';
$mpcur = '{$mp}';
$mpmax = '{$maxmp}';
$mpbar = '
<table class="rpg1" align="center" width="100px" cellspacing="0">
<tr>
<td class="rpg2" nowrap="nowrap">
<img src="images/rpg/bmg.gif" alt="{$post[\'username\']}\'s MP" width="{$mpf}%" height="8px" /><img alt="{$post[\'username\']}\'s MP" src="images/rpg/bmb.gif" width="1px" height="8px" />
</td>
</tr>
</table>
';
$exptotal = '{$totalexp}';
$expnext = '{$nextexp}';
$expcent = '{$ep}';
$expbar = '
<table class="rpg1" align="center" width="100px" cellspacing="0">
<tr>
<td class="rpg2" nowrap="nowrap">
<img src="images/rpg/bxg.gif" alt="{$post[\'username\']}\'s EXP" width="{$ep}%" height="8px" /><img alt="{$post[\'username\']}\'s EXP" src="images/rpg/bxb.gif" width="1px" height="8px" />
</td>
</tr>
</table>
';
}
?>
That's the new code with all the corrections (I even found a ton inconsistencies in the variables and stuff, it wouldn't have worked anyways; they're corrected now. >XD). Everything is functioning correctly, except $rpg_details isn't displaying postbit_author_rpg like it should. I think it has something to do with this line, here:
eval("\$rpg_details = \"".$templates->get('postbit_author_rpg')."\";");
And yes, I do have the setting turned on. I'm clearly overlooking something.