MyBB Community Forums

Full Version: Give reputation based on post count
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Ok so I couldn't find a plugin for this originally, so I decided to start making my own (I have never made a plugin, so this got real interesting really fast).

I am basically stuck with an error/bug, not really an error so I guess it's a bug. I better give you the general layout of the plugin first:

I want users to be awarded 5 rep points for every "x" posts they get, this rep will be given by a user called "System". The part of giving the initial rep works fine, but it's the part afterwords that gets buggy...

I used the hook post_output_page to run the function, which I may have messed up right there. I made the function to test on my own user first, and when I hit the required posts to get the rep, it just keeps giving it until I disable the plugin. Here is my full code:

<?php



if(!defined('IN_MYBB'))
{
	die();
}

function postrep_info()
{
	return array
	(
		"name"=>"Reps based on post count",
		"description"=>"Reputation increments as posts increase",
		"website"=>"http://tah4t.com/",
		"author"=>"Nick Wilging",
		"authorsite"=> "http://tah4t.com/",
		"version"=>"1.0",
		"compatibility"=>"16*"
	);
}

function postrep_activate()
{


}

$plugins->add_hook("post_output_page", "post_rep");
function post_rep()
{
global $mybb, $db;

	$group = $mybb->user['usergroup'];
	$postcount = $mybb->user['postnum'];
	$thisuser = $mybb->user['uid'];
	$datenow = TIME_NOW;

	$data = array(
		'rid' => '0',
		'uid' => $thisuser,
		'adduid' => '1',
		'pid' => '0',
		'reputation' => '5',
		'dateline' => $datenow,
		'comments' => 'Post Count'
	);
	
	if($mybb->user['uid'] != "0")
	{
		if($postcount == "607")
		{
			$db->insert_query('reputation', $data);
			return;
		}
		
	}
}

?>

Don't mind the "607", that is just to test on my own user. I tried putting "return;" at the end to stop it from repeating the rep giving process, but it didn't work.

Any suggestions?
Try putting exit(); after return; (or am not sure, maybe break(); might work as well but am not sure) after it?

Also you might just have to use a reputation hook as well;

http://wiki.mybb.com/index.php/MyBB_Plugin_Hooks
(2011-12-28, 08:08 AM)crazy4cs Wrote: [ -> ]Try putting exit(); after return; (or am not sure, maybe break(); might work as well but am not sure) after it?

Also you might just have to use a reputation hook as well;

http://wiki.mybb.com/index.php/MyBB_Plugin_Hooks

The problem I see with that is (and keep in mind I don't understand hooks that well either), those hooks have to do with someone giving the user a reputation rating, right? So if that user is only posting and no one rates them, then they won't get the benefit of the plugin anyway...