Mysidia Adoptables Support Forum  

Home Community Mys-Script Creative Off-Topic
Go Back   Mysidia Adoptables Support Forum > Mysidia Adoptables > Tutorials and Tips

Reply
 
Thread Tools Display Modes
  #1  
Old 06-21-2017, 05:41 PM
Abronsyth's Avatar
Abronsyth Abronsyth is offline
A Headache Embodied
 
Join Date: Aug 2011
Location: NY
Posts: 996
Gender: Male
Credits: 40,084
Abronsyth is on a distinguished road
Default [1.3.4] Pet Lineages

This tutorial is derived from this thread. The goal here is to modify the breeding system to record pet's lineages (parents), allowing users to keep track of breeding history and/or build a pedigree.

I am not going over making it pretty, that part will be up to you!

Database Modification

First we're going to start off with getting the database ready for this. In the adopts_owned_adoptables table, add three new columns with the following information:


classes/class_breeding.php
Go into this file and find the line starting like so;
PHP Code:
$mysidia->db->insert("owned_adoptables", array("aid" => NULL... 
At the end of the list (starting with "aid" => NULL) add this:
PHP Code:
"mother" => $this->female->getAdoptID(), "father" => $this->male->getAdoptID() 
Now when an adoptable is born via breeding, the parents IDs will be stored with its data. All done in this file, so you can close it now.

{home}/breeding.php
This is where the bulk of the work is done (aside from making them display all pretty-like).

So in public function index find this line:
PHP Code:
if($num 0){ 
Replace everything between the if brackets (if{...}) with this;
PHP Code:
                $offsprings $breeding->getOffsprings();
                
$offspringID $mysidia->db->select("owned_adoptables", array("aid"), "1 ORDER BY aid DESC LIMIT 1")->fetchColumn() - $num 1
                
$links = new LinkedList;
                
$newbabies = array(); // Kyt: Added line for Descendants Mod!!
                
foreach($offsprings as $offspring){
                    
$newbabies[] = $offspringID// Kyt: Added line for Descendants Mod!!
                    
$image $offspring->getEggImage("gui");
                    
$links->add(new Link("myadopts/manage/{$offspringID}"$image));
                    
$offspringID++;
                }
                
$this->setField("links"$links);
/* Kyt: Descendants Mod!! */
if ($female->descendants != 0){ $mothersOffspring $female->descendants; } else { $mothersOffspring ""; }
if (
$male->descendants != 0){ $fathersOffspring $male->descendants; } else { $fathersOffspring ""; }

for(
$i 0$i count($newbabies); $i++){
    
$mothersOffspring .= $newbabies[$i].",";
    
$fathersOffspring .= $newbabies[$i].",";
}

$updatedMotherOffspring preg_replace('/^(0,)+/'''$mothersOffspring);
$updatedFatherOffpsring preg_replace('/^(0,)+/'''$fathersOffspring);

$mysidia->db->update("owned_adoptables", array("descendants" => $updatedMotherOffspring), "aid = '{$female->aid}'");
$mysidia->db->update("owned_adoptables", array("descendants" => $updatedFatherOffpsring), "aid = '{$male->aid}'");
/* Descendants Mod End!! */ 
All done with this file, go ahead and close it after saving.

Displaying the information
Now for the fun part! Wherever you want to display the information (offspring and parents) the code needed will be relatively the same, but it does differ based on whether the file you're editing is a view file or a base file (ex: view/myadoptsview.php vs myadopts.php).

In a view file...
PHP Code:
$babies = array();
        
$descendants explode(","$this->adopt->descendants);
        if (
$descendants != ""){
            foreach(
$descendants as $offspring){
                if (
$offspring != 0){
                    
$babies[] = "<a href='../../levelup/click/{$offspring}'>♡</a>";
                }
            }
            
$children implode(""$babies);
            if (empty(
$children)){ $children "None"; } 
        }
        
$gender_lookup $mysidia->db->select("owned_adoptables", array("gender"), "aid = '{$this->adopt->getAdoptID()}'")->fetchColumn();
                if (
$gender_lookup == "m") { $gender "Male";$pronoun "him"; }
                if (
$gender_lookup == "f") { $gender "Female";$pronoun "her"; }
            
$p1name "---";
            
$p2name "---";
        if (
$this->mother != NULL) { $mother = new OwnedAdoptable($this->mother); $p1name $mother->name$p1id $mother->aid; } else { $p1id $this->aid; }
        if (
$this->father != NULL) { $father = new OwnedAdoptable($this->father); $p2name $father->name$p2id $father->aid; } else { $p2id $this->aid
That is the code you'll need. Then you can use the defined variables as you see fit to display the data. I include mine right under the initial defined variables in the manage function for view/myadoptsview.php. I then display it like so;
PHP Code:
<strong>Parents:</strong> {$p1name} and {$p2name
In a non-view file...
Code;
PHP Code:
        $babies = array();
        
$descendants explode(","$this->adopt->descendants);
        if (
$descendants != ""){
            foreach(
$descendants as $offspring){
                if (
$offspring != 0){
                    
$babies[] = "<a href='../../levelup/click/{$offspring}'>♡</a>";
                }
            }
            
$children implode(""$babies);
            if (empty(
$children)){ $children "None"; } 
        }
 
        if (
$this->mother != NULL) { $mother = new OwnedAdoptable($this->mother); $p1name $mother->name$p1id $mother->aid; } else { $p1name "Unkown"; }
        if (
$this->father != NULL) { $father = new OwnedAdoptable($this->father); $p2name $father->name$p2id $father->aid; } else { $p2name "Unknown"; } 
Displayed the same way.


And that should be it! I know this tutorial isn't very detailed...once you have all of the code it isn't difficult to put it all together...so I hope that it is understandable enough!
Reply With Quote
  #2  
Old 06-22-2017, 06:59 AM
parayna's Avatar
parayna parayna is offline
Member
 
Join Date: May 2013
Location: Devon, UK
Posts: 312
Gender: Female
Credits: 8,687
parayna is on a distinguished road
Default

Nice! Thank you :D
__________________

Examples from my in-progress adoptable site's 7 available starters
My personal favourite designs, in fact!
Reply With Quote
  #3  
Old 06-22-2017, 12:01 PM
Abronsyth's Avatar
Abronsyth Abronsyth is offline
A Headache Embodied
 
Join Date: Aug 2011
Location: NY
Posts: 996
Gender: Male
Credits: 40,084
Abronsyth is on a distinguished road
Default

Bonus code!

Want to show more generations on a pet's page? Easy! Since we already call the parent in a manner that let's us call their information, we can readily do this;
PHP Code:
$maternalgma $mother->mother
Want to readily call the maternal grandmother's data? Also easy!

PHP Code:
if ($mother->mother != NULL) { $matgrandmother = new OwnedAdoptable($mother->mother); $gp1name $matgrandmother->name$gp1id $matgrandmother->aid; } else { $gp1name "Unkown"; } 
Now you can summon the maternal grandmother's data like so;
(maternal grandmother's mother)
PHP Code:
$mgmm $matgrandmother->mother
And so on! ...I have not tested this quite yet, but it ought to work!

So you can create obnoxiously long pedigrees
Reply With Quote
  #4  
Old 04-05-2018, 04:08 PM
Phoeniix Phoeniix is offline
Member
 
Join Date: Oct 2013
Posts: 50
Gender: Male
Credits: 1,392
Phoeniix is on a distinguished road
Default

I having some trouble with thev view file, where do i put the <strong>Parents:</strong> {$p1name} and {$p2name} tag? and when i put the code in i get a syntax error
Reply With Quote
  #5  
Old 04-05-2018, 04:15 PM
Dinocanid's Avatar
Dinocanid Dinocanid is offline
Member
 
Join Date: Aug 2016
Location: Maryland, USA
Posts: 503
Gender: Unknown/Other
Credits: 20,167
Dinocanid is on a distinguished road
Default

Quote:
Originally Posted by Phoeniix View Post
I having some trouble with thev view file, where do i put the <strong>Parents:</strong> {$p1name} and {$p2name} tag? and when i put the code in i get a syntax error
It needs to be added like this:
PHP Code:
$document->add(new Comment("<strong>Parents:</strong> {$p1name} and {$p2name}")); 
__________________
Reply With Quote
  #6  
Old 04-06-2018, 08:13 PM
Phoeniix Phoeniix is offline
Member
 
Join Date: Oct 2013
Posts: 50
Gender: Male
Credits: 1,392
Phoeniix is on a distinguished road
Default

K thanks, but ive run into another issue, when inputting (if num<0) when i insert the code i get a blank breeding.php page. when i take it out the page is normal, is there something off with the code?
Reply With Quote
  #7  
Old 04-06-2018, 08:16 PM
Dinocanid's Avatar
Dinocanid Dinocanid is offline
Member
 
Join Date: Aug 2016
Location: Maryland, USA
Posts: 503
Gender: Unknown/Other
Credits: 20,167
Dinocanid is on a distinguished road
Default

Quote:
Originally Posted by Phoeniix View Post
K thanks, but ive run into another issue, when inputting (if num<0) when i insert the code i get a blank breeding.php page. when i take it out the page is normal, is there something off with the code?
Does it look like this when you do it?
PHP Code:
if($num 0){
$offsprings $breeding->getOffsprings(); 
                
$offspringID $mysidia->db->select("owned_adoptables", array("aid"), "1 ORDER BY aid DESC LIMIT 1")->fetchColumn() - $num 1;  
                
$links = new LinkedList
                
$newbabies = array(); // Kyt: Added line for Descendants Mod!! 
                
foreach($offsprings as $offspring){ 
                    
$newbabies[] = $offspringID// Kyt: Added line for Descendants Mod!! 
                    
$image $offspring->getEggImage("gui"); 
                    
$links->add(new Link("myadopts/manage/{$offspringID}"$image)); 
                    
$offspringID++; 
                } 
                
$this->setField("links"$links); 
/* Kyt: Descendants Mod!! */ 
if ($female->descendants != 0){ $mothersOffspring $female->descendants; } else { $mothersOffspring ""; } 
if (
$male->descendants != 0){ $fathersOffspring $male->descendants; } else { $fathersOffspring ""; } 

for(
$i 0$i count($newbabies); $i++){ 
    
$mothersOffspring .= $newbabies[$i].","
    
$fathersOffspring .= $newbabies[$i].","


$updatedMotherOffspring preg_replace('/^(0,)+/'''$mothersOffspring); 
$updatedFatherOffpsring preg_replace('/^(0,)+/'''$fathersOffspring); 

$mysidia->db->update("owned_adoptables", array("descendants" => $updatedMotherOffspring), "aid = '{$female->aid}'"); 
$mysidia->db->update("owned_adoptables", array("descendants" => $updatedFatherOffpsring), "aid = '{$male->aid}'"); 
/* Descendants Mod End!! */

__________________
Reply With Quote
  #8  
Old 04-06-2018, 08:25 PM
Phoeniix Phoeniix is offline
Member
 
Join Date: Oct 2013
Posts: 50
Gender: Male
Credits: 1,392
Phoeniix is on a distinguished road
Default



i think i got it right ....right lol
Reply With Quote
  #9  
Old 04-06-2018, 09:01 PM
Dinocanid's Avatar
Dinocanid Dinocanid is offline
Member
 
Join Date: Aug 2016
Location: Maryland, USA
Posts: 503
Gender: Unknown/Other
Credits: 20,167
Dinocanid is on a distinguished road
Default

Quote:
Originally Posted by Phoeniix View Post


i think i got it right ....right lol
It looks about right...
Do you have error reporting enabled on your host by any chance? It would help pinpoint the problem.
__________________
Reply With Quote
  #10  
Old 04-09-2018, 09:38 PM
dumpster dumpster is offline
Member
 
Join Date: Apr 2018
Posts: 2
Gender: Female
Credits: 160
dumpster is on a distinguished road
Default

Okay so, I'm a total noob to coding, could someone give me instructions (for an actual dummy) on where to go to do this?
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 07:07 PM.

Currently Active Users: 233 (1 members and 232 guests)
Threads: 3,940, Posts: 31,379, Members: 15,522
Welcome to our newest members, Nairi.
BER





What's New?

What's Hot?

What's Popular?


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