News:

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

Main Menu

Auto Award

Started by JohnWayne999, December 20, 2011, 01:02:25 PM

Previous topic - Next topic

JohnWayne999

Link to Mod

Link to Mod

Sixteen medals in total and are awarded automatically based on post count. Takes effect right away and also retrospectively. For example some members may have made many posts already prior to introduction of this mod. Not to worry. As soon as this mod is installed, all members will be awarded all medals they deserve.

TURN ON/OFF
This mod piggy backs on total number of posts and display of it. So make sure your forum has display for total number of posts enabled in order for this mod to work. By default this should be on anyway (already on), so you shouldn't need to worry too much.

DISPLAY OF MEDALS
Medals will be displayed under the poster's name in the posts, currently not displaying in profile page.

DIRECTORY WHERE MEDALS ARE STORED
Medals are stored in /Theme/default/images/medals
Feel free to add more or remove medals. I find 35 x 60 pixels a good size, but you are free to change that ratio as you please. HTML tables can be implemented easily to accommodate for varied sizes. This might be a feature of future version.

Please keep your medal filenames to medal1.png, medal2.png, medal3.png,.. in sequence because that's how they will be fetched in that order. I have included /Themes/default/medal1.png - medal16.png for you. You can change pictures or use different file extensions (eg. medal1.jpg, medal2.jpg...) but as long as the first part of filename sticks to sequential medal1, medal2 etc. Note also if you are using .gif then all files are .gif. If you want to use .png, then all files are .png, no mixing around please. For example medal1.gif, medal2.jpg, medal3.png will not work.

SETTING POST COUNTS FOR AWARDS
To specify how many posts deserves the next medal, simply go into /Themes/default/Display.template.php and change the numbers in $medalscore = array (10,20,30,40,50,100,150,200,300,400,600,800,1000,1300,1600,2000);
For example the way this array is set up by default now says there are 16 medals in total (16 elements in the array). To be awarded the first medal, you need to have posted a total of 10 posts. Not too hard. To be awarded the next medal, you need to post another 10 posts (absolute total of 20 posts). To get the final 16th medal, you need to post in total 2000 posts (can be new topics and/or replies, as long as they add up to 2000 from the time you registered to this forum). If you wish to add an additional medal to the reservoir, just lengthen the array, and don't forget to also place your medal#.png in /Theme/default/images/medals where # is sequential natural number. For example, obviously the next file in line will be medal17.png

Just a few quick clarifications:
Note 1: The numbers in the array are absolute number of posts not incremental posts.
Note 2: Person who receives current award, is also automatically awarded all awards below it if not already done so. For example if a member has been with this forum for some time, has posted 100 posts before this mod was installed. Now you install this mod, he is automatically awarded 6 medals all at once (for 10,20,30,40,50,100 posts check points).
Note 3: Obviously the numbers in the array need to be getting larger towards the right. For example it makes no sense setting up an array of 50,10,60,30,70,5,100,...
Note 4: If you see next to the medals an error message that says someone "has no influence", that means your array is longer than there are actually images for medals. To solve this problem is simple: either shorten your array, or add a few more images into /Theme/default/images/medals

USING IMAGES OTHER THAN PNG
Currently the engine searches for .png automatically. If you prefer .jpg or something else, just go into the file /Themes/default/Display.template.php and scroll down to this line
echo '<img src="', '/Themes/default/images/medals', '/medal', $mc++, '.png" />';

Change the .png in there to dot whatever extension you like. For example .jpg or .gif

BASE AWARD ON OTHER THAN POST COUNT
If you want the medals to be awarded based on something like how much money the user has, karma, or how long since he/she registered, it's pretty straightforward also. Just replace the variable $message['member']['posts'] with whatever variable you have in mind, as long as you know what those exact variables are.

FORWARD & BACKWARD COMPATIBILITY
This mod was developed and tested fine on SMF 2.0.1. NOTE: THIS MOD HAS NOT BEEN TESTED BY MYSELF ON ANY VERSION AFTER 1.1.15 or 2.0.1. The actual code is very small and straightforward. Please test at your own risk. If it works on a recent different version, I would love to know. For all upgrades, please firstly uninstall existing version of AutoAward then install the new version. Alternatively you can just look at the code for minor changes and DIY. Please always backup your data before trying any new mod. That will save you hours of debugging or re-installing. Just back up and copy back to last save point if need be, is the fastest and safest way.

BUGS
This mod will execute on any theme now, best against light themes. Earlier versions had poorly processed medals which showed unclean edges against dark backgrounds. You might still see examples of them in sample snapshots. The tools I used were InstantMask and iaza.com to make the medals' background transparent. These are free but rather basic tools. ARG very kindly polished up the medals nicely. So now most themes (even dark themes) should do fine.  You may still find occasional gray themes problematic.

FUTURE CONSIDERATIONS
1. Autoscale, so admin can just throw medals of any size into the directory, and medals will automatically be scaled to equal size on display.
2. Might add descriptions to individual medals.
3. Have the medals show up in personal profile page.
4. Would be interesting to make some sort of game out of the rankings. For example allow people to trade medals or sell them for non-real money on the forum.

OTHER RECOMMENDATIONS
If you enjoy this mod, then maybe you would be interested in SMF Shop by vbgamer45 and Member Awards by Spuds also. SMF Shop lets users buy things using credits earned from posts. You can reserve special edition medals for people to purchase or swap around. Member Awards is straight forward. Moderators can award individual members things (eg. trophies or limited edition medals) which will stick to their profile and album indefinitely.

UPDATE LOG
Amendment 1: Removed excess variable $medalmax
Amendment 2: Added alt="" for XHTML 
Amendment 3: Internalised if (!isset($context['disabled_fields']['posts']))
Amendment 4: Fixed <install for="2.0 - 2.0.99">
Amendment 5: Corrected HTML bug - excess comma in front of alt="" (thanks to beta tester Bugo)
Amendment 6: Corrected vertical alignment.
Amendment 7: Special thanks for ARG for polishing up medal edges and backgrounds which now work well against most dark themes


That's about it in a nutshell. Thanks for using Auto Award! All comments, suggestions including feature requests are welcome at http://www.simplemachines.org/community/index.php?topic=462876.msg3232239#msg3232239 . Check out some of the posts there as people have posted ways of fine tuning and adding features to this mod DIY, for example adding comments to icons, or setting number of icons per row.

Lastly but importantly, please remember to backup first before trying this mod.

Bugo

HTML code is not valid. Look at:

, alt="" /></li>';

Please, remove a comma before alt.

JohnWayne999

#2
Ah well spotted. What was I thinking. Thanks. Corrected and uploaded as amendment5 now.

If there are any more issues, would appreciate people reporting them and I'll try fixing asap.

(If it works for you, I'd love to hear about it too.)

chinaren


OMFG!!!  I could kiss you for this mod.  :-*  I've been looking for something like it for ever


Many blessing rain down upon you.  I've installed it and it works perfectly, though I'm going to adjust the medals an d counts a bit, as it takes up rather a lot of room as is. 


Now, I just need one for years of membership (that can go alongside this one).   :laugh:
Again, thank you for this!!
The Opus Path - The Next Generation of the Written Word

keyboard

Thank you for this awesome mod.  It is a nice addition for any Board.  :) :)

My site has thousands of posts and I would like to increase the totals from:
$medalscore = array (10,20,30,40,50,100,150,200,300,400,600,800,1000,1300,1600,2000);

To:
$medalscore = array (10,20,30,40,50,100,250,500,750,1000,1500,2500,5000,7500,10000,20000);

So All I need to do, is to go to   /Themes/default/Display.template.php   and change the numbers?

Thanks
Ron
Слaва
Украинi

thecoo1est

aww yessss! Been waiting so long, wont you tell me if Im coming on to strong, this heart of mine has been hurt before, this time I want to be sure.

Been waiting for a mod like this to come into my life, it looks so simple to and yet everything it needs to be, thanks!

JohnWayne999

#6
Quote from: keyboard on January 03, 2012, 10:25:52 AM
My site has thousands of posts and I would like to increase the totals from:
$medalscore = array (10,20,30,40,50,100,150,200,300,400,600,800,1000,1300,1600,2000);

To:
$medalscore = array (10,20,30,40,50,100,250,500,750,1000,1500,2500,5000,7500,10000,20000);

So All I need to do, is to go to   /Themes/default/Display.template.php   and change the numbers?

Keyboard, yes.

Chinaren, years of membership sounds nice. I probably won't have time to do it in the near future. Do you know what the variable for that is (years of membership)?

Thanks guys for the feedback. I share your pain and joy.

One pending problem for this mod is the medals are not very well polished. They work fine with light themes. If you try dark theme the edges get ugly. Someone just needs to edit those medal edges pixel by pixel to smooth them out. I personally won't have the time to do this until end of 2012. If anyone is able to help out that'll be excellent (bear in mind the background of medal needs to remain transparent). Otherwise I might do it myself in 12 months time :D

Happy new year and may all your resolutions come true.

thecoo1est

****** this is perfect I changed my icons already with png's, but I would like to name the icon if possible, so when a user hovers over with mouse a text popup will say what the award name is, would that be possible, not that its a big deal, Im super happy as is and thanks again, the mod is SWEEEET!

JohnWayne999

#8
Quote from: thecoo1est on January 04, 2012, 11:15:00 PM
****** this is perfect I changed my icons already with png's, but I would like to name the icon if possible, so when a user hovers over with mouse a text popup will say what the award name is, would that be possible, not that its a big deal, Im super happy as is and thanks again, the mod is SWEEEET!

Hi Cool1est

That's a good suggestion and not too hard to implement.

Many ways to do it. I'll outline one approach, see if you or anyone wants to DIY. Otherwise I can throw it in the upgrade (may be months from now).

Look for alt"" part of the code.
Insert whatever text you like in there and it will show up when the user hovers mouse next to medal.

What you want though is each medal to show up a different description.
So you will need to set up a separate array that corresponds each icon with its own description. Once that correlation is set up, you can just retrieve that description accordingly by having the the alt= point to appropriate part of the array.

So something like this

Add after this code: foreach($medalscore as $ms){
this line:    foreach($medaldesc as $md);

Add after this code: $medalscore = array (10,20,30,40,50,100,150,200,300,400,600,800,1000,1300,1600,2000);
this line:       $medaldesc = array ('Newbie', 'Medal2 Desc', 'Medal3 Desc', .., .., 'God');
      
Replace this line: echo '<img src="', $imagesURL, '/medal', $mc++, '.gif" alt="" />';
With this line: echo '<img src="', $imagesURL, '/medal', $mc++, '.gif" alt="$md" />';

So overall it should look something like this:
// Start of AutoAward
if (!isset($context['disabled_fields']['posts'])){
$imagesURL = $settings['default_images_url'] . '/medals';
$medalscore = array (10,20,30,40,50,100,150,200,300,400,600,800,1000,1300,1600,2000);
$medaldesc = array ('Newbie', 'Medal2 Desc', 'Medal3 Desc', .., .., 'God');

$mc=1;
foreach($medalscore as $ms){
foreach($medaldesc as $md);

if($message['member']['posts']>=$ms)
echo '<img src="', $imagesURL, '/medal', $mc++, '.gif" alt="$md" />';
} // end of ms foreach
} //end isset disabled fields if
// End of AutoAward.


I haven't tested it yet. See if that works for you. You might get a bug from alt="$md". The foreach might give you grief. Or maybe not and you get lucky, everything works first go :D

Addendum: Actually on second look, this code won't work. You best use two dimensional array which I can't remember how to do :D The problem with coding is it's like an addiction. You code some, want to fix it more, fix more, want to code more. Before you know it a weekend has gone.

keyboard

Hi

I am not a seasoned user of SMF and need to clarify something with you.....I have over 70 users.  I have added them all by registering them myself,  I did not assign a group to them,  so right now, they all have the  "no primary membergroup "..There have been a lot of posts and a lot of medals earned,  and now,  I would like to move all of them to a new Member Group called "Regular Members ".

Now after setting the permissions for a group called  "Regular Members", and if I assign all the Users from  "no primary member group " to this new Group,  will they lose all their hard earned medals ?
Слaва
Украинi

chinaren

Usually the 'regular member' group is 'no primary member group' by default.  Usually.


If that's not clear:  Users with 'no primary membergroup' are all members of the 'Regular Members' group.  If you change their primary member group to something else, they're (if I understand this right) still members of 'regular members' but the new primary group settings take precedence.
That's probably more confusing.  I've muddled myself now.  ???
The Opus Path - The Next Generation of the Written Word

JohnWayne999

#11
Quote from: keyboard on January 09, 2012, 08:44:35 PM
I have over 70 users.  I have added them all by registering them myself,  I did not assign a group to them,  so right now, they all have the  "no primary membergroup "..There have been a lot of posts and a lot of medals earned,  and now,  I would like to move all of them to a new Member Group called "Regular Members ".

Now after setting the permissions for a group called  "Regular Members", and if I assign all the Users from  "no primary member group " to this new Group,  will they lose all their hard earned medals ?

Hello keyboard. Interesting question. I haven't used membergroups myself so can't tell you definitely.

The way this mod works is it basically takes your total post count, and displays appropriate number of medals accordingly.
Whenever you see post count (displayed as "Posts:" under your avatar), that's the number the mod takes.

I think changing groups (from "no primary group" to "regular") does not affect your post count. For example if I started off as "no primary group" user and I posted 100 posts. Then I was upgraded to regular, and I post 50 more posts. Now I have a total of 150 posts in my "Posts: 150" display. I will get the right number of medals accordingly (ie. medals for 150 posts, not just 50 posts). Changing group/permission should not affect medal system as long as post count is not disturbed.
The assumption is: post count is not disturbed when you change group (which I think is the case).
If the post count goes back to 0 when you change group  (which I don't think is the case), then medal will go back to 0 medals.

I don't think you have anything to worry about. To be certain, why don't you test it? Just use a dummy user, make some posts to earn a few medals, then upgrade him to another group/permission and see if the medals are still there. Most likely they are still there.

Hope this answers your question. Let me know if there is abnormal behaviour. Thanks.

(By the way the algorithm used is actually not very efficient, but I haven't got time to fix it. If anyone has suggestions I am happy to consider it, thanks)

keyboard

Thanks JohnWayne999

I can confirm that I had no problems with assigning User Member Groups.. :) :) :)   

This is a nice and functional Mod  :D
Слaва
Украинi

David Blyth

Downloaded and install this Mod and it works perfectly well and the medals are stunning, I successfully changed the number of posts required to win each award however I am trying to base the medals awarded on the karma of a member so I changed the $message['member']['posts'] to $message['member']['karma'] but it still uses the number of posts, can you give me any advice on this matter.

JohnWayne999

#14
Quote from: David Blyth on January 22, 2012, 06:05:40 PM
Downloaded and install this Mod and it works perfectly well and the medals are stunning, I successfully changed the number of posts required to win each award however I am trying to base the medals awarded on the karma of a member so I changed the $message['member']['posts'] to $message['member']['karma'] but it still uses the number of posts, can you give me any advice on this matter.

Hi there.

I haven't tested this yet, but try

using this

$message['member']['karma']['good'] - $message['member']['karma']['bad']

instead of your

$message['member']['karma']


(Just in case I'm not clear. What I mean is, you said you altered my code from $message['member']['posts'] to $message['member']['karma']. I am suggesting you alter my code from its original $message['member']['posts'] to $message['member']['karma']['good'] - $message['member']['karma']['bad']. Don't touch $message['member']['posts'] and $message['member']['karma'] that's outside of my code. To tell where my code starts and end, you should be able to find comments that say something like "// AutoAward starts here" and "// AutoAward ends here". Anything in between is my code. Anything outside is SMF's own stuff)


Also, a less important point, consider changing

this

if (!isset($context['disabled_fields']['posts'])){

to this

if ($modSettings['karmaMode'] == '1'){


Good luck. Let us know how you go.

keyboard

#15
Great Mod !!!!

I am moving things around and deleting messages , the total count gets less and less, to the point where some Users are losing medals ...Yikes !!!!!

Is there anyway where I can manual add to their total so they do not lose their hard earned medals ?


Thanks again for this awesome mod
Ron
Слaва
Украинi

JohnWayne999

Quote from: keyboard on February 02, 2012, 10:47:13 AM
I am moving things around and deleting messages , the total count gets less and less, to the point where some Users are losing medals ...Yikes !!!!!

Is there anyway where I can manual add to their total so they do not lose their hard earned medals ?

Hi there keyboard. Thanks for the feedback. This mod feeds on total post count. So if total post count comes down far enough, then yes people will start to lose medals.

I didn't know erasing posts can lead to people losing their post count. If this is the case, then it's an SMF issue which needs to be solved from their end.

You should be able to manually edit the SQL database and turn up individual user's post count. Then their medals will also return, once post count is back up. (Make sure to back up your database first before making changes manually).

Good luck!

pixeleyes

Actually I want to keep one award.

I want that when user reach next level post

so previous award automatically be removed or converted to next award.

e.g.
100 posts : 200 posts
on 200posts previous award of 100posts should not be shown.

JohnWayne999

#18
Quote from: pixeleyes on April 07, 2012, 12:58:25 AM
Actually I want to keep one award.

I want that when user reach next level post

so previous award automatically be removed or converted to next award.

e.g.
100 posts : 200 posts
on 200posts previous award of 100posts should not be shown.

Hi.

A good request. In summary you want to display only the single highest medal at all times.

However I am quite busy at the moment. If you don't mind experimenting, please edit this file /Themes/default/Display.template.php, try replacing this bit of the original code


$mc=1;
foreach($medalscore as $ms){
if($message['member']['posts']>=$ms)
echo '<img src="', $imagesURL, '/medal', $mc++, '.png" alt="" />';
} // end of ms foreach



with this new section of code

$mc=1; $printedonce=0;
foreach($medalscore as $ms){
if($message['member']['posts']>=$ms) $mc++;

if($message['member']['posts']<$ms && $printedonce==0){
if($mc>=1) echo '<img src="', $imagesURL, '/medal', $mc, '.png" alt="" />';
$printedonce=1; $mc++;
}
                                } // end of ms foreach


Please note this is something I made up spontaneously and have not tested. Normally my code needs about 5 debugs before it's good to release. So this one may or may not work.

Good luck.

pixeleyes

Thank you so much JohnWayne999
ThumbsUP This is exactly what I wanted.

I would like to request one more feature but whenever you have free time.  :)

1) Want to add text before Award e.g. "Achievement"
2) Under Award in second line I want that "left posts to next achievement"
e.g.  200 Posts to Next Achievement

Advertisement: