Log in

View Full Version : breed multiple clutches


SilverDragonTears
04-24-2012, 06:08 PM
Possible? To breed more than one baby?

AlexC
04-24-2012, 07:03 PM
want, want, want. This would be pretty darn cool.

Aasixx
04-24-2012, 07:18 PM
I would love this as well.. o3o I hope it's possible.

SilverDragonTears
04-24-2012, 07:30 PM
Welllll.... I could always take a look at it myself then since you guys are interested. I'm just sooooo busy >.> Maybe I can just post my thoughts and hopefully get some help with it. *Stares at Hoffie*

Hall of Famer
04-24-2012, 07:48 PM
I think this question was asked before when breeding first became available for Mys v1.2.0. The trick is here from breeding.php:


else {
// we choose the type!
$types = array($female->type, $male->type);
$typerand = rand(0,1);

// we choose the gender
$genders = array('f', 'm');
$genderrand = rand(0,1);
$code = codegen(10, 0);

// MESSY - I'm blanking out on how to find the actual alt status stuff right now, any help would be lovely.
$alts = getaltstatus($female_species->id, 0, 0);

$time = time();
$adopts->insert("owned_adoptables", array("aid" => NULL, "type" => $types[$typerand], "name" => $types[$typerand], "owner" => $loggedinname, "currentlevel" => 0, "totalclicks" => 0, "code" => $code,
"imageurl" => NULL, "usealternates" => $alts, "tradestatus" => 'fortrade', "isfrozen" => 'no', "gender" => $genders[$genderrand], "lastbred" => 0));

$article_content = "Congratulations! Breeding is successful, you have acquired a baby {$types[$typerand]} from breeding center.
<br><a href='myadopts.php'>Manage your new {$types[$typerand]} now!</a></p>";

$adopts->update("owned_adoptables", array("lastbred" => $time), "aid = '{$femaleid}'");
$adopts->update("owned_adoptables", array("lastbred" => $time), "aid = '{$maleid}'");

} // we end the place where it goes on if the levels are ok
Assume the number of babies is a random variable ranging from 1 to 5, you can do the following:


else {
$num = mt_rand(1, 5);
for($i = 0;$i<$num;$i++){
// we choose the type!
$types = array($female->type, $male->type);
$typerand = rand(0,1);

// we choose the gender
$genders = array('f', 'm');
$genderrand = rand(0,1);
$code = codegen(10, 0);

// MESSY - I'm blanking out on how to find the actual alt status stuff right now, any help would be lovely.
$alts = getaltstatus($female_species->id, 0, 0);

$time = time();
$adopts->insert("owned_adoptables", array("aid" => NULL, "type" => $types[$typerand], "name" => $types[$typerand], "owner" => $loggedinname, "currentlevel" => 0, "totalclicks" => 0, "code" => $code,
"imageurl" => NULL, "usealternates" => $alts, "tradestatus" => 'fortrade', "isfrozen" => 'no', "gender" => $genders[$genderrand], "lastbred" => 0));

} // the end of for loop
$article_content = "Congratulations! Breeding is successful, your pets have produced {$num} babies from breeding!";
$adopts->update("owned_adoptables", array("lastbred" => $time), "aid = '{$femaleid}'");
$adopts->update("owned_adoptables", array("lastbred" => $time), "aid = '{$maleid}'");
} // we end the place where it goes on if the levels are ok
This way the script will randomly produce 1-5 babies depending on what you get from the random number generator. You can easily make it to whatever number it can go up to. You can also do database integration by creating a new field in table prefix.adoptables that stores the number of babies a specific species can produce. It can get quite tricky for interspecies breeding though, so I do not recommend it at this moment.

SilverDragonTears
04-24-2012, 08:04 PM
Ok it told me my dragons had 4 babies... but I only got two eggs?

Here's what I have....Also can I show the images of each new baby? I know how to show one but not the others?

else {
$num = mt_rand(1, 5);
for($i = 0;$i<$num;$i++){
// we choose the type!
$types = array($female->type, $male->type);
$typerand = rand(0,1);

// we choose the gender
$tempgender = rand(0, 99);
if($tempgender < $row->genderratio) {
$gender = "f";
$alts = "yes";
unset($tempgender);
}
else {
$gender = "m";
$alts = "no";
unset($tempgender);
}

$salt = passgenerator(10, 0);
$aid = passgenerator(5, 0);
$code = codegen(10, 0);



$time = time();

$bredtemp = rand(0,100);
if($bredtemp <= "50"){

$article_content = "<center>
<img src='http://taleofdragons.net/get/".$maleid.".gif'><br>
<img src='http://taleofdragons.net/get/".$femaleid.".gif'><br>
These two don't seem very interested in each other right now. Try again in a week.";

}
else{
$adopts->insert("owned_adoptables", array("aid" => $aid, "type" => $types[$typerand], "name" => $aid, "owner" => $loggedinname, "currentlevel" => 0, "totalclicks" => 0, "code" => $code,
"imageurl" => NULL, "usealternates" => $alts, "tradestatus" => 'notfortrade', "isfrozen" => 'no', "gender" => $gender, "lastbred" => 0, "date" => $date, "father" => $maleid, "mother" => $femaleid));

} // the end of for loop
$article_content = "
<center>
<img src='http://taleofdragons.net/get/".$maleid.".gif'><br>
<img src='http://taleofdragons.net/get/".$femaleid.".gif'></center><br>".$imageurl."Congratulations! Breeding is successful, you have acquired {$num} babies from breeding!<br>
<a href='myadopts.php?act=stats&id=".$aid."'><img src='http://taleofdragons.net/get/".$aid.".gif'></a></p>";

}
$adopts->update("owned_adoptables", array("lastbred" => $time), "aid = '{$femaleid}'");
$adopts->update("owned_adoptables", array("lastbred" => $time), "aid = '{$maleid}'");

} // we end the place where it goes on if the levels are ok
} //this bracket ends the else where we find the male/female id's
}

Hall of Famer
04-24-2012, 08:16 PM
This is weird... Lets troubleshoot by editing this line:


$adopts->insert("owned_adoptables", array("aid" => NULL, "type" => $types[$typerand], "name" => $types[$typerand], "owner" => $loggedinname, "currentlevel" => 0, "totalclicks" => 0, "code" => $code,
"imageurl" => NULL, "usealternates" => $alts, "tradestatus" => 'fortrade', "isfrozen" => 'no', "gender" => $genders[$genderrand], "lastbred" => 0));


to


$adopts->insert("owned_adoptables", array("aid" => NULL, "type" => $types[$typerand], "name" => $types[$typerand], "owner" => $loggedinname, "currentlevel" => 0, "totalclicks" => 0, "code" => $code,
"imageurl" => NULL, "usealternates" => $alts, "tradestatus" => 'fortrade', "isfrozen" => 'no', "gender" => $genders[$genderrand], "lastbred" => 0)) or die("Failed to create baby dragons...");


Lemme know if you get an error message that terminates the script.

SilverDragonTears
04-24-2012, 08:20 PM
Nope no error...but said I had 3 babies but looked in my lair and I have none. I posted my script in my last post. Bred again and said I had 3 eggs but only 1 in my lair.

SilverDragonTears
04-24-2012, 08:28 PM
Maybe it has something to do with the types? Like maybe the ones I can't see are the other types?

Hall of Famer
04-24-2012, 08:36 PM
Well I see, looks like it is because of the way you modify your code. XD You only get 0 or 1 baby from the last two tries because you have this 'breeding chance' settings. Here:

$bredtemp = rand(0,100);
if($bredtemp <= "50"){
$article_content = "<center> <img src='http://taleofdragons.net/get/".$maleid.".gif'><br> <img src='http://taleofdragons.net/get/".$femaleid.".gif'><br> These two don't seem very interested in each other right now. Try again in a week.";
}
According to this, the $bredtemp generates a number between 0 to 100, but only when this random number is below 50 will breeding actually occur. For this reason you wont get 3 dragons unless the variable $bredtemp gets a random number below 50 everytime. See the logic? Since each time breeding has 50% chance to succeed, it makes perfect sense why you get 1 out of 3 last time, and 2 out of 4 the first time. The script will work normally if you remove the 'breeding chance' code.

SilverDragonTears
04-24-2012, 08:38 PM
I see :) Cool! Ok... so is it possible to have some one type and some the other? Also... can I show all the baby images instead of just one??

Hall of Famer
04-24-2012, 08:41 PM
Theoretically yes, you can have two possible types of dragons for multiple offsprings production. If you look at the code itself, the baby's type is generated inside the for loop, which is why the first baby may assume its father's type while the second baby can be the same type of its mother's.

Aasixx
04-24-2012, 08:41 PM
Silver, which one of your sites are you putting this on? I would like to test it out on your site (I have an account on both).

SilverDragonTears
04-24-2012, 08:45 PM
X.X... umm... lol. Example?


EDIT: I'm so stupid. I was breeding the same two types. It already does what I wanted. *facepalm*

Ok so how do I get all the baby images to show instead of one?

Hall of Famer
04-24-2012, 10:08 PM
Well... You can simply change the equal sign = after $article_content to .=

Original code:


$article_content = <center> <img src='http://taleofdragons.net/get/".$maleid.".gif'><br> <img src='http://taleofdragons.net/get/".$femaleid.".gif'></center><br>".$imageurl."Congratulations! Breeding is successful, you have acquired {$num} babies from breeding!<br> <a href='myadopts.php?act=stats&id=".$aid."'><img src='http://taleofdragons.net/get/".$aid.".gif'></a></p>";
New Code:


$article_content .= " <center> <img src='http://taleofdragons.net/get/".$maleid.".gif'><br> <img src='http://taleofdragons.net/get/".$femaleid.".gif'></center><br>".$imageurl."Congratulations! Breeding is successful, you have acquired {$num} babies from breeding!<br> <a href='myadopts.php?act=stats&id=".$aid."'><img src='http://taleofdragons.net/get/".$aid.".gif'></a></p>";
See the difference? You bet.

SilverDragonTears
04-24-2012, 10:46 PM
Umm... lol

http://img1.UploadScreenshot.com/images/main/4/11414392644.png (http://www.UploadScreenshot.com/image/933424/8434510)

SilverDragonTears
04-25-2012, 12:37 AM
Posting what I have per Hof's request...


else {
$num = mt_rand(0, 5);
for($i = 0;$i<$num;$i++){
// we choose the type!
$types = array($female->type, $male->type);
$typerand = rand(0,1);

// we choose the gender
$tempgender = rand(0, 99);
if($tempgender < $row->genderratio) {
$gender = "f";
$alts = "yes";
unset($tempgender);
}
else {
$gender = "m";
$alts = "no";
unset($tempgender);
}

$salt = passgenerator(10, 0);
$aid = passgenerator(5, 0);
$code = codegen(10, 0);



$time = time();
$adopts->insert("owned_adoptables", array("aid" => $aid, "type" => $types[$typerand], "name" => $aid, "owner" => $loggedinname, "currentlevel" => 0, "totalclicks" => 0, "code" => $code,
"imageurl" => NULL, "usealternates" => $alts, "tradestatus" => 'notfortrade', "isfrozen" => 'no', "gender" => $gender, "lastbred" => 0, "date" => $date, "father" => $maleid, "mother" => $femaleid));

} // the end of for loop

if($num == "0"){
$article_content .= " <center> <img src='http://taleofdragons.net/get/".$maleid.".gif'><br> <img src='http://taleofdragons.net/get/".$femaleid.".gif'></center><br>These two do not seem interested in one another. Try again in a week.";
}else{
$article_content .= " <center> <img src='http://taleofdragons.net/get/".$maleid.".gif'><br> <img src='http://taleofdragons.net/get/".$femaleid.".gif'></center><br>Congratulations! Breeding is successful, you have acquired {$num} babies from breeding!<br> <a href='myadopts.php?act=stats&id=".$aid."'><img src='http://taleofdragons.net/get/".$aid.".gif'></a></p>";
}

Hall of Famer
04-25-2012, 07:09 AM
I heard that you fixed your problem already, what a relief. XD

AlexC
04-25-2012, 03:01 PM
Okay, so this is working perfectly on my site, but I was kinda wondering how to display the parents and all the babies like Silver is. I tried with her code, but it didn't work. I do however, have like, 20+ new babies.

SilverDragonTears
04-26-2012, 06:37 PM
You can also do database integration by creating a new field in table prefix.adoptables that stores the number of babies a specific species can produce. It can get quite tricky for interspecies breeding though, so I do not recommend it at this moment.

I know you aren't feeling well but I need this. I need to keep the rares and ultra rares from breeding more than 1 at a time.
I figured out a difficult and probably source consuming way....

else{


if ($female->type == 'Cake Dragon') $num = mt_rand(0, 1);
else if ($female->type == 'Sun-up Dragon') $num = mt_rand(0, 1);
else if ($female->type == 'Sundown Dragon') $num = mt_rand(0, 1);
else if ($female->type == 'Bastet Dragon') $num = mt_rand(0, 1);
else if ($male->type == 'Cake Dragon') $num = mt_rand(0, 1);
else if ($male->type == 'Sun-up Dragon') $num = mt_rand(0, 1);
else if ($male->type == 'Sundown Dragon') $num = mt_rand(0, 1);
else if ($male->type == 'Bastet Dragon') $num = mt_rand(0, 1);
else if ($female->type == 'Aqua Dragon') $num = mt_rand(0, 4);
else if ($female->type == 'Cow Amphiptere Dragon') $num = mt_rand(0, 4);
else if ($male->type == 'Aqua Dragon') $num = mt_rand(0, 4);
else if ($male->type == 'Cow Amphiptere Dragon') $num = mt_rand(0, 4);
else $num = mt_rand(0, 5);
for($i = 0;$i<$num;$i++){

I wanted to just use the rarity variable that is in the adoptables table but I wasn't sure how to call it?