Author Topic: User Selected Awards  (Read 3985 times)


  • Guest
User Selected Awards
« on: January 31, 2007, 06:32:41 am »
I am not a coder...suck at it and this code is rather bad. However incase anyone wants to improve or if it gives ideas here you go:

I downloaded the awards mod from the SMF website This allows the admin to assign awards to users. I created (again rather poorly written) an item in my smfshop. It allows users to purchase an award. I set the quantity to 1 to make them rare.

Code Below:

Code: [Select]
if (!defined('SMF'))
die('Hacking attempt...');

item_ninjapirate extends itemTemplate
function getItemDetails()
$this->authorName 'Swiftburn';
$this->authorWeb '';
$this->authorEmail '';

$this->name 'Ninja Pirate Award';
$this->desc 'Give yourself the Ninja Pirate Award';
$this->price 17250;

$this->require_input false;
$this->can_use_item true;
$this->addInput_editable false;

function onUse()
global $db_prefix$ID_MEMBER$item_info;
$today date("Y-m-d");
srand ((double) microtime() * 1000000);
$random_number rand(1000,9999);

(ID_AWARD_MEMBER, ID_AWARD, ID_MEMBER, dateReceived, favorite) 
{$random_number}{$ID_MEMBER}', '[color=red]8'[/color], '{$ID_MEMBER}', '{$today}', '0' ) ")
or die(mysql_error());
    return 'Successfully Awarded Medal';



You have to change the red 8 to the item number of your medal. Putting th emouse over each medal gives you the ID. The award mod requires a random number for ID_AWARD_MEMBER so i used a crude randomizing script. Again this code is bad and so-so just wanted to post to give people ideas. Cheers and thanks for all the items everyone posted they are great. Oh and the SMF Shop is great too !

Offline littleone

Re: User Selected Awards
« Reply #1 on: February 06, 2007, 01:36:18 am »
Actually this code is quite dangerous in the sense that the awards mod doesnt randomize anything.  I am the one who paid jay for the mod and worked one on one with him to get it to work.  If you ranomize it your run the risk of duplicating the award number which will either cause u errors or over writing something you dont want over run.  here is the way it assigns the awards:

It combines the award # with the member # and places 3 zeros in the middle to avoid duplications....

So if you have member 25 and award 3 you gets 250003 or either 300025 (dont remember what order its in)  We had the problem originally of having not having zeros which lead to a problem.  Some members were not getting awards because the award # had already been assigned. So it was 253 meaning if you were member 2 you couldnt get award 53 and if you were member 25 you couldnt get award 3 so we fixed that with adding the three 000s in the middle.  Hope that helps you fix your code, otherwise you will have issues with randomizing.


  • Guest
Re: User Selected Awards
« Reply #2 on: February 07, 2007, 02:38:16 pm »
It chooses a random number between 1000 and 9999 so I was hoping that it wouldn't pick a duplicate since there are a thousand combinations. However taking the member number and the award number with zeros would be the best just can get the code to work out. Any improvements to my above crappy code would be appreciated  ;D


  • Guest
Re: User Selected Awards
« Reply #3 on: July 07, 2007, 08:26:17 pm »
ERROR: Could not create instance of 'award' item!

The code isn't working for me.