Mysidia Adoptables Support Forum  

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

Notices

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #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: 1,011
Gender: Male
Credits: 111,779
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!
__________________
My Mods Site (1.3.4, 2020 Mods)
Reply With Quote
 

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 09:15 AM.

Currently Active Users: 665 (0 members and 665 guests)
Threads: 4,080, Posts: 32,024, Members: 2,016
Welcome to our newest members, jolob.
BETA





What's New?

What's Hot?

What's Popular?


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