News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Point system

Started by nend, April 19, 2016, 12:15:34 AM

Previous topic - Next topic

nend

I wanted to create a point system to award my members by their activity.

Sort of similar to the shop mods, which I did consider but decided it was in the best interest to start from scratch. One main reason is there was too many unnecessary source edits in the current modifications available.

So forth I created two tables and added these lines to Load.php.
if ($set == 'normal')
{
$select_columns = '
(mem.posts + mem.topics + mem.aeva_comments + mem.aeva_items + mem.point_offset - mem.point_spent) AS points,

elseif ($set == 'profile')
{
$select_columns = '
(mem.posts + mem.topics + mem.aeva_comments + mem.aeva_items + mem.point_offset - mem.point_spent) AS points,

'points' => $profile['points'],
'avatar' => array(
'name' => $profile['avatar'],
'image' => $profile['avatar'] == '' ? ($profile['id_attach'] > 0 ? '<img class="avatar" src="' . (empty($profile['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $profile['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $profile['filename']) . '" alt="" />' : '') : (stristr($profile['avatar'], 'http://') ? '<img class="avatar" src="' . $profile['avatar'] . '"' . $avatar_width . $avatar_height . ' alt="" />' : ($profile['avatar'] == 'gravatar' ? '<img class="avatar" src="' . get_gravatar($profile['email_address']) . '"' . $avatar_width . $avatar_height . ' alt="" />' : '<img class="avatar" src="' . $modSettings['avatar_url'] . '/' . htmlspecialchars($profile['avatar']) . '" alt="" />')),
'href' => $profile['avatar'] == '' ? ($profile['id_attach'] > 0 ? (empty($profile['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $profile['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $profile['filename']) : '') : (stristr($profile['avatar'], 'http://') ? $profile['avatar'] : ($profile['avatar'] == 'gravatar' ? get_gravatar($profile['email_address']) : $modSettings['avatar_url'] . '/' . $profile['avatar'])),
'url' => $profile['avatar'] == '' ? '' : (stristr($profile['avatar'], 'http://') ? $profile['avatar'] : ($profile['avatar'] == 'gravatar' ? get_gravatar($profile['email_address']) : $modSettings['avatar_url'] . '/' . $profile['avatar']))
),


You can see why I didn't want to go with those shop mods, the point calculations is set up already with a few file edits in one file. I might change the query metrics, but this is proof of concept you can do it with minimal hacking.

point_offset is when I award points to a member or I can have some areas of generation depending on circumstances.
point_spent is how much points the user has spent. This would be used to calculate the balance also.

Now I just have to build the store part which will run independently of any of the sources.

What do you think?

margarett

There are several ways to approach it, depending on your main goal.
If it's for your own usage only, then it seems OK ;)

If you want to make it a more general package, maybe submit it as a MOD, then it might be a bit too "simplistic" as it stands... On a quick glimpse:
- you need to make sure that AEVA-related stuff (mem.aeva_comments + mem.aeva_items) doesn't fail on a forum which doesn't have it installed
- you might want to consider different weights for the different contributions
- you might want to consider minumum/maximum values (eg, be sure not to go below 0)
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

nend

Yeah, really not interested in making into a mod, at least not at this time. Would rather have mod authors reexamine their code. Yes the current systems work, but IMHO are way too intrusive in their methods.

Weights could be in the query.
(mem.posts * '.$modSettings['points_post'].') + (men.topics * '.$modSettings ['points_topics'].') +

If weights get changed when members already have points, then we would have to calculate the inflation/deflation. Points offset can be used to do this. Allot of updates to the member tables but this shouldn't happen much as this would be a admin option.

A check to see if the  value is less than 0 before inserting into the array seems logical. Maybe I can just leave it and tell them, hey you, you have a negative balance pay up.

Thanks for the suggestions, hopefully not too many typos, on mobile.

Advertisement: