04-20-2015, 01:40 AM
|
|
Premium Member
|
|
Join Date: Jan 2014
Posts: 857
Gender: Unknown/Other
Credits: 111,370
|
|
Display Pet's Birthday / Original Owner
This mod could also be used for other things. The basic concept is that you have some bit of information you need associated with a pet but that bit of information needs to be attached to them when they are born or otherwise created by the system.
DatabaseOpen up phpMyAdmin so you have access to your database, and open up the owned_adoptables table. We're going to create two new columns.
You can add these columns by pressing Structure and, at the bottom of that page, observing where you can type in '2' to add 2 columns at the end of the table, and pressing 'Go'.
Both will be stored as the VARCHAR type, originalowner with a length of 20, birthday with a length of 30. I recommend you fill birthday with a default value formatted such as "April 20th, 2015" and all existing pets will have this date set as their birthday. You can do the similar with originalowner, but if it's more fitting for your needs, leave it blank.
Alternatively, you can instead use the following query by opening the SQL tab instead of the Structure tab:
Code:
ALTER TABLE adopts_owned_adoptables ADD `originalowner` varchar(20) NOT NULL DEFAULT '',
ALTER TABLE adopts_owned_adoptables ADD `birthday` varchar(20) NOT NULL DEFAULT 'April 20th, 2015'
If your default prefix for your database is not adopts_, you'll need to edit the code above first!
Pet Creation Areas Pets can be created through five different means so code needs to be changed in each place. In classes/class_stockadopt.php pets are created for adoptable shops, in classes/class_promocode.php, pets are created from user entered promo-codes, in classes/class_breeding, pets are created via two pets being bred together to make offspring, in adopt.php the pets are created from a list of always available pets for free, and finally, in admincp/ownedadopt.php you can, as admin, give new pets directly to members. Open all of these files up and look for this, it only happens once in each of these five files (be sure not to miss a single file):
PHP Code:
$mysidia->db->insert("owned_adoptables", array(
Make sure that it does say insert, not update. We're only looking to make additions to the insert function. Observe this line and try to wrap your head around what's going on -- that's right, these correspond directly with the column names in the database.
Alright, anywhere in these lines, I prefer at the end, we're going to add references to our new database columns and what we want to be in these fields.
PHP Code:
"originalowner" => $mysidia->user->username, "birthday" => date("F jS, Y")
Psst, an example of how the birthday field will display itself is "April 20th, 2015". If you'd like to store data differently, look into how PHP formats dates.
Displaying Information Unfortunately, the method I'm using on my own site is kind of hack-y and simply rewrites the error page announcing "you've already clicked this pet today". This isn't the most desirable nor elegant approach. So this is not a guide to making profile pages for your pets as I have done on my own site.
However, sticking with the original framework, pet stats can be found from a pet's management page where only the current owner can find this information. If you open up classes/class_ownedadoptable.php and find public function getStats() you'll be able to add information in this location, for example, by modifying the $adoptStats variable to include references to $this->originalowner and $this->birthday which each correspond to the values found in the columns we added to the database:
PHP Code:
$adoptStats = "<br>Original Owner: {$this->originalowner}<br>Birthday: {$this->birthday}<br>Trade Status: {$this->tradestatus}<br> Current Level: {$this->currentlevel}<br>Next Level: {$nextLevel}</b>";
This mod is very similar to Wallie's Pet Stats/Skills mod which is the same basic concept - adding columns to the database to hold new pet information, making sure this information is created when the pets are created, and displaying it. Wallie's thread attempts to go into detail about displaying pet information in other ways, and I based my own pet profile pages after what I learned there, so it may or may not be of help - it depends on how well you can wrap your head around code. However, Wallie's version is specific to v1.3.3, and some things have changed slightly.
__________________
Please do not contact me directly outside of Mysidia.
I also cannot troubleshoot code more than two years old - I legit don't remember it.
|