Mysidia Adoptables Support Forum

Mysidia Adoptables Support Forum (http://www.mysidiaadoptables.com/forum/index.php)
-   Tutorials and Tips (http://www.mysidiaadoptables.com/forum/forumdisplay.php?f=27)
-   -   [1.3.4] Pet Lineages (http://www.mysidiaadoptables.com/forum/showthread.php?t=5473)

Abronsyth 06-21-2017 05:41 PM

[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:
http://img08.deviantart.net/1391/i/2...re-dbdjkff.png

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!

parayna 06-22-2017 06:59 AM

Nice! Thank you :D

Abronsyth 06-22-2017 12:01 PM

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 :happycbig:

Phoeniix 04-05-2018 04:08 PM

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

Dinocanid 04-05-2018 04:15 PM

Quote:

Originally Posted by Phoeniix (Post 37108)
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}")); 


Phoeniix 04-06-2018 08:13 PM

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?

Dinocanid 04-06-2018 08:16 PM

Quote:

Originally Posted by Phoeniix (Post 37149)
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!! */



Phoeniix 04-06-2018 08:25 PM

http://i68.tinypic.com/2el9orb.png

i think i got it right ....right lol

Dinocanid 04-06-2018 09:01 PM

Quote:

Originally Posted by Phoeniix (Post 37151)
http://i68.tinypic.com/2el9orb.png

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.

dumpster 04-09-2018 09:38 PM

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:

Nairi 10-05-2018 12:05 PM

Hi,

i had the same problem =/ my breeding is blank.

Phoeniix 10-28-2020 11:28 PM

Jump bumping this thread because the tutorial is VERY unclear, im not even sure where to put said code on the breedingview page.

Kyttias 10-29-2020 01:28 AM

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.

Phoeniix 10-29-2020 10:42 AM

Quote:

Originally Posted by Kyttias (Post 37736)
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.

Hall of Famer 10-29-2020 12:02 PM

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.

Phoeniix 10-29-2020 01:12 PM

i have error messages turned on, still get a white screen.

Hall of Famer 10-29-2020 03:14 PM

Can you check the error_log file then? If its not logged on the screen, then maybe its there.

Phoeniix 10-30-2020 12:52 AM

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

Abronsyth 11-03-2020 02:43 PM

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:


All times are GMT -5. The time now is 03:23 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.