Posts RSS Comments RSS 5 Posts and 3 Comments till now

(Very) Simple SMF Level System

I can't stress the "simple" part enough for this one. This runs entirely on the template side. The level is calculated on the fly, and not stored in any variable or in the database where you can call it elsewhere. This is probably both an advantage and a disadvantage, depending on what you're planning to do with it.

I use this for RMRK, an RPG Making forum.

It calculates a level based off the user's postcount and member ID (lower (i.e. an older member) being better).

To use this is very simple, open up your theme's Display.template.php and find the following:

// Show how many posts they have made.

Either remove or comment out the default, which will almost always be something just like this:

echo '', $message['member']['posts'] ,' <br />'

and insert this instead:

$number = explode('.',round(pow (log10 ($message['member']['real_posts'] + ($context['common_stats']['latest_member']['id'] - $message['member']['id'])), 3),2));

$string = $number[0]. (isset($number[1]) ? ' ('. $number[1] . (strlen($number[1]) <2 ? '0' : '') .'%)' : '');

echo ' <br /><abbr title="Member ',$message['member']['id'],'  •  ',$message['member']['posts'],' Posts">Level ', $string , '</abbr><br />';

Here's an explanation of what is going on here:

$number = explode('.',round(pow (log10 ($message['member']['real_posts'] + ($context['common_stats']['latest_member']['id'] - $message['member']['id'])), 3),2));

This works out as follows: It starts off with the member's postcount. From here, we add the latest member's ID (a way of basically saying how many registered users there are on your forum), and then subtract from this the member's user ID.

If two members have the same amount of posts, the one with the lower user ID will have a higher number at the outcome of this equasion, resulting in a higher level. After all, they've been there longer! Then we do some extra math to generate the actual level from this number. It's such that as a level increases, it becomes harder to attain the next one. Finally the result is prepared to be interpreted by the next line..

$string = $number[0]. (isset($number[1]) ? ' ('. $number[1] . (strlen($number[1]) <2 ? '0' : '') .'%)' : '');

This takes the level number and formats it with a percentage on the end (if the level isn't an exact number). This gives a nice way of showing how far the member is towards the next level. Examples of how this would show:

Level 12

Level 5 (06%)

Level 40 (74%)

Now we have all this, let's display the member's level:

echo ' <br /><abbr title="Member ',$message['member']['id'],'  •  ',$message['member']['posts'],' Posts">Level ', $string , '</abbr><br />';

Since the level is generated from Postcount and User ID, I provide this information in a tooltip if a viewer hovers over the level. I also do this since on my own forum, user IDs and postcount aren't shown on the message display. You could do this differently for your own forum. I've only tested and used this whilst inside the display template, though it should also be usable on a member's profile

Trackback this post | Feed on Comments to this post

Leave a Reply