Mysidia Adoptables Support Forum  

Home Community Mys-Script Creative Off-Topic
Go Back   Mysidia Adoptables Support Forum > Mysidia Adoptables > Addons and Modifications > Mys v1.3.x Mods

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 01-16-2017, 02:00 PM
Dinocanid's Avatar
Dinocanid Dinocanid is offline
Member
 
Join Date: Aug 2016
Location: Maryland, USA
Posts: 516
Gender: Unknown/Other
Credits: 63,602
Dinocanid is on a distinguished road
Default Achievments system

-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 Code:
<?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 Code:
<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 Code:
$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 Code:
$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 Code:
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 Code:
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 Code:
$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 Code:
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 Code:
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:
Quote:
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 by Dinocanid; 01-20-2017 at 06:07 PM.
Reply With Quote
  #2  
Old 01-16-2017, 02:20 PM
SilverDragonTears's Avatar
SilverDragonTears SilverDragonTears is offline
I am your Nemesis.
 
Join Date: Jun 2011
Posts: 1,113
Gender: Female
Credits: 81,204
SilverDragonTears is on a distinguished road
Default

Nice!!! Thank you for sharing!
__________________

Check out SilvaTales
Reply With Quote
  #3  
Old 01-18-2017, 09:08 PM
SilverDragonTears's Avatar
SilverDragonTears SilverDragonTears is offline
I am your Nemesis.
 
Join Date: Jun 2011
Posts: 1,113
Gender: Female
Credits: 81,204
SilverDragonTears is on a distinguished road
Default

Can you help me? Where exactly does this go?

PHP Code:
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/> 
__________________

Check out SilvaTales
Reply With Quote
  #4  
Old 01-18-2017, 09:57 PM
Dinocanid's Avatar
Dinocanid Dinocanid is offline
Member
 
Join Date: Aug 2016
Location: Maryland, USA
Posts: 516
Gender: Unknown/Other
Credits: 63,602
Dinocanid is on a distinguished road
Default

It would go in like this (following the example in step 2):
PHP Code:
    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));
    } 
__________________
Reply With Quote
  #5  
Old 01-18-2017, 10:20 PM
SilverDragonTears's Avatar
SilverDragonTears SilverDragonTears is offline
I am your Nemesis.
 
Join Date: Jun 2011
Posts: 1,113
Gender: Female
Credits: 81,204
SilverDragonTears is on a distinguished road
Default

Thank you :)

So once you unlock it the locked images go away?
__________________

Check out SilvaTales
Reply With Quote
  #6  
Old 01-18-2017, 11:12 PM
Dinocanid's Avatar
Dinocanid Dinocanid is offline
Member
 
Join Date: Aug 2016
Location: Maryland, USA
Posts: 516
Gender: Unknown/Other
Credits: 63,602
Dinocanid is on a distinguished road
Default

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.
__________________
Reply With Quote
  #7  
Old 01-20-2017, 04:07 PM
SilverDragonTears's Avatar
SilverDragonTears SilverDragonTears is offline
I am your Nemesis.
 
Join Date: Jun 2011
Posts: 1,113
Gender: Female
Credits: 81,204
SilverDragonTears is on a distinguished road
Default

What would be some other achievement ideas to add to this?
__________________

Check out SilvaTales
Reply With Quote
  #8  
Old 01-20-2017, 04:24 PM
IntoRain's Avatar
IntoRain IntoRain is offline
Moderator
 
Join Date: Jul 2013
Location: Portugal
Posts: 461
Gender: Female
Credits: 19,255
IntoRain is on a distinguished road
Default

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.
__________________


asp.net stole my soul.
Reply With Quote
  #9  
Old 01-20-2017, 06:11 PM
Dinocanid's Avatar
Dinocanid Dinocanid is offline
Member
 
Join Date: Aug 2016
Location: Maryland, USA
Posts: 516
Gender: Unknown/Other
Credits: 63,602
Dinocanid is on a distinguished road
Default

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.
__________________
Reply With Quote
  #10  
Old 01-21-2017, 10:50 AM
IntoRain's Avatar
IntoRain IntoRain is offline
Moderator
 
Join Date: Jul 2013
Location: Portugal
Posts: 461
Gender: Female
Credits: 19,255
IntoRain is on a distinguished road
Default

It's not stored I think, you'd have to count it with rowCount() from the table vote_voters
__________________


asp.net stole my soul.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 05:48 AM.

Currently Active Users: 461 (0 members and 461 guests)
Threads: 4,080, Posts: 32,024, Members: 2,016
Welcome to our newest members, jolob.
BETA





What's New?

What's Hot?

What's Popular?


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
vBCommerce I v2.0.0 Gold ©2010, PixelFX Studios
vBCredits I v2.0.0 Gold ©2010, PixelFX Studios
Emoticons by darkmoon3636