Mys 1.3.4 Achievments system

Forum
Last Post
Threads / Messages

Dinocanid

Member
Member
Joined
Aug 30, 2016
Messages
520
Points
18
Age
23
Location
Maryland, USA
Mysidian Dollar
43,334
-What This Does-
Users are able to unlock achievements by completing certain tasks, owning certain adoptables, or owning certain items. This is the same system I use on my site.

-How This Works-
There is no adminCP functionality, so new achievements have to be coded in manually; especially if you want the conditions to be complex. The example achievement goes by "fullpantry", but you can change the name to whatever since I was just too lazy to do it myself for the sake of this tutorial.

-Step 1-
To get started, we need to create two php files. In your public_html folder, create a new file called achievements.php. We're going to make a simple achievement that unlocks when a user owns a certain amount of adoptables.
Inside achievements.php, paste this:
PHP:
<?php 
class AchievementsController extends AppController{ 

    public function __construct(){ 
        parent::__construct("member"); 
    } 
     
    public function index(){ 
        $mysidia = Registry::get("mysidia"); 
    } 
     
} 
?>

-Step 2-
You will most likely never have to touch the above code again. Now go to your view folder and create a new file called achievementsview.php. Inside, paste this:
PHP:
<style>
                .s_top {
                  overflow:hidden;
                  display: block;
                }
                .sc_npc_text{  
                  width: 300px;
                  float: left;
                  position: relative;
                  left: 38%;
                  height: 70px;
                  padding: 15px;
                  margin: 10px;
                  margin-top: 30px;
                  font-family: 'Trebuchet MS', Helvetica, sans-serif;
                  overflow: auto;
                }
                .sc_npc_img{  
                  position: relative;
                }

                .sc_item {
                  display: inline-table;
                  padding: 5px;
                  text-align: center;
                  font-family: 'Trebuchet MS', Helvetica, sans-serif;
                  font-size: 14px;
                  margin-bottom: 3px;
                }
                .s_panel {
                  border-radius: 2px;
                  border: 1px solid #CCC;
                  background-color: #FBFDF2;  
                }
                .s_lockedpanel {
                  border-radius: 2px;
                  border: 1px solid #000000;
                  background-color: #898989;  
                }
            </style>
<?php 
class AchievementsView extends View{ 

    public function index(){ 
        $mysidia = Registry::get("mysidia"); 
        $document = $this->document;    
        $status = $mysidia->user->getstatus();
        
        $document->setAlign(new Align("center", "middle"));
        $document->setTitle("Achievements");
        
        $document->add(new Paragraph());
        $document->add(new Comment("<h2> Unlocked </h2>"));
        if($status->fullpantry == "unlocked"){
         $document->add(new Comment("
                <div class=\"s_panel sc_item\">
                <img rel='tooltip' title='<em>Achievement Description<em>' src='InsertImageHere'/}>
                <br/>
                  <b>Achievement Name</b>
                  <br/>
                  
                 </div>", FALSE));
         }
                 
                $document->add(new Paragraph());
                $document->add(new Comment("<h2> Locked </h2>"));
                
                
                if($status->fullpantry == "locked"){
                $document->add(new Comment("
                <div class=\"s_lockedpanel sc_item\">
                <img rel='tooltip' title='<em>Own 10 or more adoptables to unlock<em>' src='InsertImageHere'/}>
                <br/>
                  <b>???</b>
                  <br/>
                 </div>", FALSE));
                 }
    } 
     
}
(I know the style tags aren't exactly optimal, though it doesn't throw any errors, so feel free to add them to your css instead if you wish. It's the same code from the item shop mod.)
Looking at it now, this code is supposed to unlock when a user owns 10 or more adoptables. The images are used for the achievement images. I recommend using a "mystery image"/silhouette for the locked items and a normal image for the unlocked one.

-Step 3-
Now we go to myadoptsview.php and add this in public_function index:
PHP:
$adoptAmount = $mysidia->db->select("owned_adoptables", array("aid"), "owner = '{$mysidia->user->username}'")->rowCount();
		if($adoptAmount >= 10){
		$mysidia->db->update("users_status", array("fullpantry" => 'unlocked'), "username='{$mysidia->user->username}'");
		}

-Step 4-
Now we go to phpMyAdmin. Go to adopts_users_status and create a new column with this information:
Code:
Name: fullpantry
Type: VARCHAR
Length/Values: 8
Default: (as defined) locked
Collation: latin1_swedish_ci
Check the null box
Comment: Milestone Start

-End-
Simple, enough? Now we have an achievement that unlocks when the user owns 10 or more pets. It uses tooltips for the descriptions, so go here if you want to know how those work.

-Pet based achievements-
Now what if you want to reward the user for owning a certain pet? In your achievmentsview.php, you would add this line under $status,
PHP:
$Adoptcheck = $mysidia->db->select("owned_adoptables", array("type"), "type ='Species Name' and owner ='{$mysidia->user->username}'")->rowCount();
if($Adoptcheck >= 1){$mysidia->db->update("users_status", array("OwnCertainAdopt" => 'unlocked'), "username='{$mysidia->user->username}'");}

Then you put this in the "locked" section of your script:
PHP:
if($status->OwnCertainAdopt == "locked"){
                $document->add(new Comment("
                <div class=\"s_lockedpanel sc_item\">
                <img rel='tooltip' title='<em>Own InsertSpeciesHere to unlock<em>' src='IMAGE'/}>
                <br/>
                  <b>???</b>
                  <br/>
                  
                 </div>", FALSE));
         }

And this in the "unlocked" section:
PHP:
if($status->OwnCertainAdopt == "unlocked"){
         $document->add(new Comment("
                <div class=\"s_panel sc_item\">
                <img rel='tooltip' title='<em>Description<em>' src='IMAGE'/}>
                <br/>
                  <b>Achievment Name</b>
                  <br/>
                  
                 </div>", FALSE));
         }

Now you go to phpMyAdmin and add a new column with this information under adopts_users_status,
Code:
Name: OwnCertainAdopt
Type: VARCHAR
Length/Values: 8
Default: (as defined) locked
Collation: latin1_swedish_ci
Check the null box

-Item based achievements-
To reward a user for owning a certain item, follow the same formula by adding this with all the other "check" code:
PHP:
$Itemcheck = $mysidia->db->select("inventory", array("itemname"), "itemname ='ItemNameHere' and owner ='{$mysidia->user->username}'")->rowCount();
if($Itemcheck >= 1){$mysidia->db->update("users_status", array("OwnCertainItem" => 'unlocked'), "username='{$mysidia->user->username}'");}

Now add this in the locked section:
PHP:
if($status->OwnCertainItem == "locked"){ 
                $document->add(new Comment(" 
                <div class=\"s_lockedpanel sc_item\"> 
                <img rel='tooltip' title='<em>Own InsertItemHere to unlock<em>' src='IMAGE'/}> 
                <br/> 
                  <b>???</b> 
                  <br/> 
                   
                 </div>", FALSE)); 
         }

And this in the unlocked section:
PHP:
if($status->OwnCertainItem == "unlocked"){ 
         $document->add(new Comment(" 
                <div class=\"s_panel sc_item\"> 
                <img rel='tooltip' title='<em>Description<em>' src='IMAGE'/}> 
                <br/> 
                  <b>Achievment Name</b> 
                  <br/> 
                   
                 </div>", FALSE)); 
         }

Finally, add the achievement to phpMyAdmin like we did in the past steps with this information:
Name: OwnCertainItem
Type: VARCHAR
Length/Values: 8
Default: (as defined) locked
Collation: latin1_swedish_ci
Check the null box

-Extending this system-
Having trouble making your own conditions? Just reply to let me know and I'll try to help you out!
 
Last edited:
Can you help me? Where exactly does this go?

PHP:
if($status->OwnCertainAdopt == "locked"){
                $document->add(new Comment("
                <div class=\"s_lockedpanel sc_item\">
                <img rel='tooltip' title='<em>Own InsertSpeciesHere to unlock<em>' src='IMAGE'/}>
                <br/>
                  <b>???</b>
                  <br/>
 
It would go in like this (following the example in step 2):
PHP:
    public function index(){ 
        $mysidia = Registry::get("mysidia"); 
        $document = $this->document;    
        $status = $mysidia->user->getstatus();
        
        $document->setAlign(new Align("center", "middle"));
        $document->setTitle("Achievements");
        
        $document->add(new Paragraph());
        $document->add(new Comment("<h2> Unlocked </h2>"));
        if($status->fullpantry == "unlocked"){
         $document->add(new Comment("
                <div class=\"s_panel sc_item\">
                <img rel='tooltip' title='<em>Achievement Description<em>' src='InsertImageHere'/}>
                <br/>
                  <b>Achievement Name</b>
                  <br/>
                  
                 </div>", FALSE));
         }
                 
                $document->add(new Paragraph());
                $document->add(new Comment("<h2> Locked </h2>"));
                
                
                if($status->fullpantry == "locked"){
                $document->add(new Comment("
                <div class=\"s_lockedpanel sc_item\">
                <img rel='tooltip' title='<em>Own 10 or more adoptables to unlock<em>' src='InsertImageHere'/}>
                <br/>
                  <b>???</b>
                  <br/>
                 </div>", FALSE));
                 }

if($status->OwnCertainAdopt == "locked"){ 
                $document->add(new Comment(" 
                <div class=\"s_lockedpanel sc_item\"> 
                <img rel='tooltip' title='<em>Own InsertSpeciesHere to unlock<em>' src='IMAGE'/}> 
                <br/> 
                  <b>???</b> 
                  <br/>  
</div>", FALSE));
    }
 
Yep. The code is set up so the locked image only appears when it was "locked" in phpMyAdmin. Same goes for the unlocked image, which only appears when said achievement says "unlocked" in phpMyAdmin; so they can't appear at the same time.
 
Hmm maybe for amount of money reached? Or number of clicks per day. That's all I can remember besides owning certain creatures or items.
 
I added a part for item-based achievements. I didn't test it myself though, so let me know if it causes any errors or doesn't work.

Amount of money reached sounds simple enough, but I'm not sure where the amount of clicks from a user is stored to be able to call it.
 
Awesome mod, though I haven't had the chance to play with it yet...I was looking to add something like this :D
 
I was just adding notes to the checklist I have for what I need to do on my site and got to the one about installing this mod when I had a slight idea regarding the achievements... eventually your user status might get very long if you have loads of achievements, so couldn't you create a new database thing called users_achievements that is generated when a new user signs up (the same way all users database rows are) and the default is set as locked. I actually don't think this would be that difficult so as soon as the film I'm watching is over I'll perhaps go upstairs and try and do it :smile: I'm mostly just talking "out loud" here but this would probably be just a way of keeping achievements separated for those like me with organisation issues lol
 
has anyone tested to see if this works with 1.3.5? i’d really like to implement an achievements system!!!
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,274
Messages
33,115
Members
1,602
Latest member
BerrieMilk
BETA

Latest Threads

Latest Posts

Top