-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:
-Step 1-
Now go to class_ownedadoptable and add these lines with all the other public and protected stuff:
Now, with the other functions, add these lines:
-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:
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:
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":
Afterwards, use this to display the progress bars:
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:
and this to edit mood:
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:
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:
(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.
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:
Afterwards, create another column with the same info, but name it mood.Name: health
Type: int
Length/Values: 11
Default: As defined: 100
Not null
-Step 1-
Now go to class_ownedadoptable and add these lines with all the other public and protected stuff:
PHP:
public $health;
public $mood;
Now, with the other functions, add these lines:
PHP:
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:
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-appearance: none;
}
progress[value]::-webkit-progress-bar {
background-color: #eee;
border-radius: 5px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25) inset;
}
progress[value]::-webkit-progress-value {
border-radius: 5px;
}
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:
{$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:
$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:
$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:
$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:
$adopt->setMood($addMood, "update");
if ($mood > 100){$adopt->setMood(100, "update");
$document->add(new Comment("<br></br>{$adopt->getName()} has happy already!"));
}
-Decrease needs daily-
Add this to your myadoptsview.php file, inside the manage function:
PHP:
$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:
$subMood = $adopt->getMood() - 10;
$subHealth = $adopt->getHealth() - 10;
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: