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 11-07-2016, 07:38 PM
Dinocanid's Avatar
Dinocanid Dinocanid is offline
Member
 
Join Date: Aug 2016
Location: Maryland, USA
Posts: 516
Gender: Unknown/Other
Credits: 78,903
Dinocanid is on a distinguished road
Default Health and mood system + progress bars

-What we will do-
Create a health and mood system to make pets less static. Once finished, this can easily be added on to to create things like hunger, thirst, etc. After this initial post, you can read the post afterwards if you wish to include any addons, such as pets dying when health reaches 0.

-Step 0-
First we need to go to phpMyAdmin and add a new column in the owned_adoptables table:
Quote:
Name: health
Type: int
Length/Values: 11
Default: As defined: 100
Not null
Afterwards, create another column with the same info, but name it mood.

-Step 1-
Now go to class_ownedadoptable and add these lines with all the other public and protected stuff:
PHP Code:
        public $health;
        public 
$mood
Now, with the other functions, add these lines:
PHP Code:
    public function getHealth(){ 
        return 
$this->health
    }
    public function 
getMood(){ 
        return 
$this->mood
    }

        public function 
setHealth($health$assignMode ""){
        if(
$assignMode == Model::UPDATE$this->save("health"$health);
        
$this->health $health;
    }
            public function 
setMood($mood$assignMode ""){
        if(
$assignMode == Model::UPDATE$this->save("mood"$mood);
        
$this->mood $mood;
    } 
-Step 2-
Here comes the fun part: Progress Bars! Percents and values can get so boring sometimes, so we're going to use progress bars.

Go to the css folder (located in the root folder, not your template css) and create a new file called "progress.css" Inside, paste this:
PHP Code:
progress[value] {color:red/* IE10 */
progress::-webkit-progress-bar-value {background:red}
progress::-webkit-progress-value {background:red}
progress::-moz-progress-bar {background:red;}
progress {
   -
webkit-appearancenone;
}
progress[value]::-webkit-progress-bar {
  
background-color#eee;
  
border-radius5px;
  
box-shadow0 2px 4px rgba(0000.25inset;
}
progress[value]::-webkit-progress-value {
  
border-radius5px;

This is what makes the progress bar look nice. You can change the background and background colors to whatever you want. (For more information on styling progress bars, just google "HTML5 progress bar styling")

In order to see your new progress bar's style, you have to add this to your header.tpl:
PHP Code:
{$header->loadStyle("{$home}{$css}/progress.css")} 
Now that we have the css in place, we want to display the progress bars. For now, we'll put it on the manage page of your adoptable. (You can put it elsewhere if you want, just follow the instructions)

Go to myadoptsview.php and add these under "public function manage":
PHP Code:
        $health $adopt->getHealth();
        
$mood $adopt->getMood();
$addHealth $adopt->getHealth() + 10;
$addMood $adopt->getMood() + 10;
$subtractHealth $adopt->getHealth() - 10;
$subtractMood $adopt->getMood() - 10
Afterwards, use this to display the progress bars:
PHP Code:
$document->add(new Comment ("Health: <progress max='100' value='{$health}'></progress> <br></br>Mood: <progress max='100' value='{$mood}'></progress>")); 

Aren't they spiffy?

-Adding and Removing Mood/Health-
How exactly you want to update the health and mood is up to you (Whether it's toys, medicine, clicks, etc.) But however you do it, you would do this to edit health:
PHP Code:
            $adopt->setHealth($addHealth"update");
                        if (
$health 100){$adopt->setHealth(100"update");
            
$document->add(new Comment("<br></br>{$adopt->getName()} has full health!"));
            } 
and this to edit mood:
PHP Code:
            $adopt->setMood($addMood"update");
                        if (
$mood 100){$adopt->setMood(100"update");
            
$document->add(new Comment("<br></br>{$adopt->getName()} has happy already!"));
            } 
The if statement makes sure that the health and mood are never above 100.

-Decrease needs daily-
Add this to your myadoptsview.php file, inside the manage function:

PHP Code:
$today date("d");
if (
$mysidia->user->needschecked != $today) {
        
$adopt->setMood($subMood"update");        
        if (
$mood <= 0){$adopt->setHealth($subHealth"update"); }
        }
        
$mysidia->db->update("users", array("needschecked" => $today), "username = '{$mysidia->user->username}'"); 
Now go to phpMyAdmin, adopts_users, and make a new column like this:


And you're all set! Please note that the code above is assuming that you already have $subHealth and $subMood already defined. Just in case you don't:
PHP Code:
$subMood $adopt->getMood() - 10;
        
$subHealth $adopt->getHealth() - 10
(change 10 to whatever number you want)
So if the mood drops to 0, then the health begins to drop by 10 every day. The only issue with this code is that the user has to click on the pet and refresh the page/interact with it in some way in order for this to take effect, so pets' needs could be frozen if the user just doesn't click on them, sort of cheating the system. It works alright as a prototype system though, since I couldn't figure out a better way to get it working.
__________________

Last edited by Dinocanid; 04-02-2017 at 04:50 PM. Reason: Updated to add decreasing needs
Reply With Quote
  #2  
Old 11-07-2016, 07:39 PM
Dinocanid's Avatar
Dinocanid Dinocanid is offline
Member
 
Join Date: Aug 2016
Location: Maryland, USA
Posts: 516
Gender: Unknown/Other
Credits: 78,903
Dinocanid is on a distinguished road
Default

-Addons-
(Reserved)
__________________
Reply With Quote
  #3  
Old 11-07-2016, 11:25 PM
Silver_Brick Silver_Brick is offline
Designer || Coder
 
Join Date: Oct 2016
Location: In Earth
Posts: 205
Gender: Male
Credits: 31,228
Silver_Brick is on a distinguished road
Default

Good job (Y) i hope other user will found this usefull and i am also using this and its great ^^
Reply With Quote
  #4  
Old 11-07-2016, 11:31 PM
Dinocanid's Avatar
Dinocanid Dinocanid is offline
Member
 
Join Date: Aug 2016
Location: Maryland, USA
Posts: 516
Gender: Unknown/Other
Credits: 78,903
Dinocanid is on a distinguished road
Default

Thanks! ^^
I decided to go ahead and post it since a lot of adoptables sites have some way of interacting with the pet, instead of just clicking and logging out.
__________________
Reply With Quote
  #5  
Old 11-09-2016, 02:43 PM
Eagle9615's Avatar
Eagle9615 Eagle9615 is offline
Member
 
Join Date: Jun 2013
Location: Southern US
Posts: 32
Gender: Female
Credits: 6,187
Eagle9615 is on a distinguished road
Default

I was literally just thinking of how I was going to add hunger/mood to my site right before I logged on. I'm not a programmer, so thank you for this!
__________________
Reply With Quote
  #6  
Old 11-19-2016, 12:36 PM
Abronsyth's Avatar
Abronsyth Abronsyth is offline
A Headache Embodied
 
Join Date: Aug 2011
Location: NY
Posts: 1,011
Gender: Male
Credits: 133,011
Abronsyth is on a distinguished road
Default

Awesome! Thank you for sharing! This will blend splendidly with my battle and exploration features :D
__________________
My Mods Site (1.3.4, 2020 Mods)
Reply With Quote
  #7  
Old 11-26-2016, 12:06 PM
Dinocanid's Avatar
Dinocanid Dinocanid is offline
Member
 
Join Date: Aug 2016
Location: Maryland, USA
Posts: 516
Gender: Unknown/Other
Credits: 78,903
Dinocanid is on a distinguished road
Default

Updated the OP since I forgot the part that allows you to see your progress bar's style; otherwise it will always be a blue rectangle or whatever the default look is for your browser.
__________________
Reply With Quote
  #8  
Old 12-19-2016, 05:10 PM
parayna's Avatar
parayna parayna is offline
Member
 
Join Date: May 2013
Location: Devon, UK
Posts: 342
Gender: Female
Credits: 22,533
parayna is on a distinguished road
Default

I have a little question Does the mood/health automatically drop? I mean, I'm thinking of not having health (as I probably don't want to include battling... and can't really see much point of having it) but would like mood to drop a little either every day, or every hour/whenever. This way using items that increase mood (toys, etc) can increase it and be a good way of interacting with pets. And as I was typing this I thought it might be interesting to add hunger and thirst and if they both reach 0 it starts taking from health until that gets to 0, etc. (Then perhaps the pet dies, or 'runs away' for a more 'friendly' solution)

  Spoiler: Addon Idea c: 
Also, a cool addon idea using the held items and pet companions mod could be that you set specific properties they can do. Perhaps holding a certain item, or having a certain companion can keep mood up (it decreases slower), perhaps health takes longer to drop, or heals your pet when they get hurt, or maybe they 'play' with the item once a day and mood increases. Maybe even 'trick' items that do the opposite and hurt your pet/decrease mood (great for Halloween, etc!)


Thank you ^_^
Reply With Quote
  #9  
Old 12-19-2016, 08:47 PM
Dinocanid's Avatar
Dinocanid Dinocanid is offline
Member
 
Join Date: Aug 2016
Location: Maryland, USA
Posts: 516
Gender: Unknown/Other
Credits: 78,903
Dinocanid is on a distinguished road
Default

I'm working on finding a way to make it drop, but so far I've found nothing that works. Some people suggest cronjobs, which would be ideal for this since it would only run once every 24 hours, but I've yet to find any sort of guide as to how to set it up with mysidia script. Right now I'm testing this line I added:

PHP Code:
$today date(d);
        
        if (
$mysidia->user->lastday != $today) {
        
$adopt->setMood($subMood"update");        
        }
        
$mysidia->db->update("users", array("lastday" => $today), "username = '{$mysidia->user->username}'"); 
Supposedly it could make the mood drop every day when you visit your pet's profile, but it's only been one day so I'm going to have to probably wait another to see if it's actually working.

I already mostly have a part done that makes a pet die when health reaches 0, but it also deletes the pet from the system so I have to do some pretty careful testing. I'm working on a less destructive alternative where the pet "dies" and you have a few days to revive them.

That sounds like a cool idea for an addon! Once I can actually get the bars to go down then I'll see about working on it.
__________________
Reply With Quote
  #10  
Old 12-19-2016, 08:55 PM
Hall of Famer's Avatar
Hall of Famer Hall of Famer is offline
Administrator, Lead Coder
 
Join Date: Dec 2008
Location: South Brunswick
Posts: 4,448
Gender: Male
Credits: 487,031
Hall of Famer is on a distinguished road
Default

Well the issue with cronjobs is that you cannot make them easily without going to cpanel and doing something newbie unfriendly. For advanced users its the way to go, but for a Mod/Plugin doing cronjobs like this will confuse many people. A rule of thumb when making a Mod/Plugin is not to make the installation/modification process over-complicated.

Alternatively, you can set up something called scheduled tasks, or pseudo-cronjobs. All you need is to insert a script that runs whenever someone visits your site, it will check for scheduled tasks and will execute any tasks that are ready to run(or overdue). In an active site it will emulate real cronjobs very well, on an inactive or dev/demo site it may not work as expected though. Mysidia Adoptables v1.4.0 will introduce official scheduled tasks system, I am sure it will help many users who want time-based actions/events.
__________________


Mysidia Adoptables, a free and ever-improving script for aspiring adoptables/pets site.
Reply With Quote
Reply


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:23 AM.

Currently Active Users: 686 (0 members and 686 guests)
Threads: 4,081, Posts: 32,029, 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