[1.3.4] Pet Lineages

Forum
Last Post
Threads / Messages

Abronsyth

A Headache Embodied
Member
Joined
Aug 25, 2011
Messages
1,012
Points
36
Location
NY
Mysidian Dollar
73,285
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:
lineage_2_by_perocore-dbdjkff.png


classes/class_breeding.php
Go into this file and find the line starting like so;
PHP:
$mysidia->db->insert("owned_adoptables", array("aid" => NULL...

At the end of the list (starting with "aid" => NULL) add this:
PHP:
"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:
if($num > 0){

Replace everything between the if brackets (if{...}) with this;
PHP:
                $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:
$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:
<strong>Parents:</strong> {$p1name} and {$p2name}

In a non-view file...
Code;
PHP:
		$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!
 
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:
$maternalgma = $mother->mother;

Want to readily call the maternal grandmother's data? Also easy!

PHP:
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:
$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 :happycbig:
 
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
 
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:
$document->add(new Comment("<strong>Parents:</strong> {$p1name} and {$p2name}"));
 
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?
 
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:
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!! */
}
 
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?:desudesudesu:
 
Jump bumping this thread because the tutorial is VERY unclear, im not even sure where to put said code on the breedingview page.
 
None of this code goes in a breeding view page (as the breeding view page is the page where breeding happens). You'll either want to make a new page named whatever you want to display the lineage or perhaps shove into the pet profiles. Where you want to display the code is up to you. Most of what the code provided here does is modify the breeding page to save information needed to display a lineage wherever you intend to display it.
 
None of this code goes in a breeding view page (as the breeding view page is the page where breeding happens). You'll either want to make a new page named whatever you want to display the lineage or perhaps shove into the pet profiles. Where you want to display the code is up to you. Most of what the code provided here does is modify the breeding page to save information needed to display a lineage wherever you intend to display it.
GOD BLESS YOU!!! im going to try this out today, nd also creating a new page i do that on notepad ++ and then upload it with the code to the server as a (nameoffile).php in the view file correct?

Update: so im running into the old problem i had where the page is blank when i try to breed two adoptables.
 
Last edited:
You should see some error messages if the page is blank, cant you ask your webhost to enable error reporting, or configure this yourself? Its more informative and helpful if you can see the error messages.
 
ahh ive found the problem, its the displaying them part. I've created a new page called lineage and put the code into it it. how would i intergrade it
 
It's generally designed to just be displayed on a pet profile page/manage page. Don't need to make a new page to display it. The last section of the tutorial covers this :veeee:
 
This would be a fantastic Mod to port over to the latest version!

Preferably something visible to all members, so it could be used when selling or trading a pet ... seeing the 'bloodline' so to speak.

Looking at it, it seems all it needs is to use the mother and father ID instead of the name, but we'd want that shown too.

Will see if I can get this working, if anyone has any ideas please share :)
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,274
Messages
33,115
Members
1,602
Latest member
BerrieMilk
BETA

Latest Threads

Latest Posts

Top