Thread: Breeding
View Single Post
  #10  
Old 10-25-2009, 03:06 PM
gabeki gabeki is offline
Premium Member
 
Join Date: Oct 2009
Posts: 24
Gender: Female
Credits: 1,308
gabeki
Default RE: Breeding

ok, I did it... I did not test it, because my gender system is a little different, but I'll test soon.

I'm not sure it'll work, but I tried to explain everything for you, so you can change what is necessary

If it works, or if you change it so it works, you can release it in mods forum :D

PHP Code:
<?php

// Basic Rusnak PHP Adoptables Script configurations
include("inc/functions.php");
include(
"inc/config.php");

$themeurl grabanysetting("themeurl");
$links getlinks();

$ads getads("any");

$pagecontent getsitecontent("index");
$article_title $pagecontent[title];
$article_content $pagecontent[content];
$article_content nl2br($article_content);

$browsertitle grabanysetting("browsertitle");
$sitename grabanysetting("sitename");
$slogan grabanysetting("slogan");

$loginstatus logincheck();
$isloggedin $loginstatus[loginstatus];
$loggedinname $loginstatus[username];

// End of basic configurations

$femaleid $_POST['female'];
$maleid $_POST['male'];
$breed $_POST['breed'];
// this two variables will get the female and male ID's from the selection form and the answer if the user has selected the adoptables or not.

// First let's create a page so the users can choose the two adoptables that they want to breed

if($isloggedin == "yes"){ 
// we have to put that in the start of the breeding system, so users that are not logged in cannot see the selection forms

if($breed != 'yes'){
// if the anser if the user has selected the adoptables or not, is different than YES, we have to show the options so the user can select them

// This will start a selection form to select the females
$article_content $article_content."<p>Select the Two adoptables you want to Breed:</p><p><form method='post'><select name = 'female'>"

//This will select all the female adoptables the user has
$result mysql_query("SELECT * FROM ".$prefix."owned_adoptables WHERE owner = '$loggedinname' AND gender = 'female'");
$num mysql_num_rows($result);

// Loop Out code < this will loop so you select all the rows and not just one
$i 0;
while (
$i $num){
$aid mysql_result($result,$i,'aid');
$type mysql_result($result,$i,'type');
$name mysql_result($result,$i,'name');

$article_content $article_content."<option value='".$aid."'>".$name." (".$type.")</option>";
//this will display something like that: cute kitty (cat), the name (the type); for each adptable (female) the user has

$i++;
}

$article_content $article_content."</select><select name='male'>"//now let's do the same for the males

$result2 mysql_query("SELECT * FROM ".$prefix."owned_adoptables WHERE owner = '$loggedinname' AND gender = 'male'");
$num2 mysql_num_rows($result2);

// Loop Out code
$i2 0;
while (
$i $num){
$aid mysql_result($result2,$i2,'aid');
$type mysql_result($result2,$i2,'type');
$name mysql_result($result2,$i2,'name');

$article_content $article_content."<option value='".$aid."'>".$name." (".$type.")</option>";

$i2++;
}

$article_content $article_content."</select><input type='hidden' name='breed' value='yes'><input type='submit' value='Breed It'></form>";

// ok now the user has two selection forms to those a female and a male adoptable and when they click Breed It, it will be posted to the variables $_POST['female'] and $_POST['male'], which will be two aid (adoptables ids), and with that ID we can select the information that we need from the database, and breed them

// the hidden input will give us an answer to our question, the user has selected it? and it'll be 'yes'

// this is the end of if($breed != 'yes'), so now we have to put an ELSE statment, that means that the answer IS yes, and we can proceed with the breeding

else {
// ok, if the user gets here, it means that we have the male and female ID, and with it we can select the informations from the database.

// here you can estabilish what you want.. the adoptables have to be which level to breed? the adoptables have to be the same type? 

// I will do something like that: the adoptables have to be the same type, and level 2 or more. but you can do what you want.. if you have an element system like me, you can estabilish that two water adoptables breed a another water adoptable. or fire and water are incompatible, etc

// first let's get the information we need

$result mysql_query("SELECT * FROM ".$prefix."owned_adoptables WHERE aid = '$femaleid'");
// the result should be just one row, so we don't need a loop

$female_type mysql_result($result,0,'type'); 
// 0 means that we are selecting the very first row, in this case, the only one
$female_name mysql_result($result,0,'name');
$female_level mysql_result($result,0,'currentlevel');


$result2 mysql_query("SELECT * FROM ".$prefix."owned_adoptables WHERE aid = '$maleid'");
// the result should be just one row, so we don't need a loop

$male_type mysql_result($result2,0,'type'); 
// 0 means that we are selecting the very first row, in this case, the only one
$male_name mysql_result($result2,0,'name');
$male_level mysql_result($result2,0,'currentlevel');

// now we have all we need. let's start the security system, to guarantee that the user has the requirements

if($male_level OR $female_level 2){
$article_content $article_content."Sorry, one of your adoptables don't have the minimum level to breed. Keep training them.";
}
else {
if (
$male_type != $female_type){
$article_content $article_content."Sorry, your adoptables are not the same type, they cannot breed."
}
else{
// ok, we can go one and BREED it, let's make it more real and estabilish a certain chance that the breed will not work. let's say the chance of it to fail, is a formula with the difference of the levels, that way if a adoptable is very old, it will be difficult to breed

$article_content $article_content."<p>Your adoptables are breeding.</p>"

$rand rand(1,100);

if(
$male_level $female_level){
$failchance $male_level $female_level 3
else{
$failchance $female_level $male_level 3;
}
// that way if one is level 2 and the other is level 4, they have a 6% chance of failing, because the formula is higher level - lower level x 3

if($rand $failchance){
$article_content $article_content."<p>Result: <b>FAIL</b></p><p>I'm sorry, your adoptables failed at breeding, you can try again later.</p>";
}
else{
$article_content $article_content."<p>Result: <b>Bred Succesfully</b></p><p>Your new egg is being transferred to you right now.</p>";

// now let's insert the new egg at owned_adoptables

$gender_rand rand(0,1);

if(
$gender_rand 0){
$new_name $male_name." & ".$female_name."'s Son";
$gender 'male';
}
else{
$new_name $male_name." & ".$female_name."'s Daughter";
$gender 'female';
}

$code rand(120000);

$result3 mysql_query("SELECT * FROM ".$prefix."adoptables WHERE type='$male_type'");
$aid=@mysql_result($result3,0,"id"); //The adoptable's ID
$eggimage=$mysql_result($result3,0,'eggimage');

$alts getaltstatus($aid00);

mysql_query("INSERT INTO ".$prefix."owned_adoptables VALUES ('', '$male_type', '$new_name','$loggedinname','0','0', '$code', '','$alts','notfortrade','no','$gender')");

$article_content $article_content."<p><img src='".$eggimage."'><br /><a href='myadopts.php'>Manage ".$new_name." now!</a> You can change its name.</p>";

}

}
}
}

// this is the end of if($isloggedin == "yes")

else { //this is the else of if($isloggedin == "yes")

$article_content $article_content."You are not logged in.";

}

// **********************************************************************
// Begin Template Definition
// **********************************************************************

//Define our current theme
$file $themeurl;

// Do the template changes and echo the ready template
$template file_get_contents($file);

$template replace(':ARTICLETITLE:',$article_title,$template);
$template replace(':ARTICLECONTENT:',$article_content,$template);
$template replace(':ARTICLEDATE:',$article_date,$template);

$template replace(':BROWSERTITLE:',$browsertitle,$template);
$template replace(':SITENAME:',$sitename,$template);

//Define our links
$template replace(':LINKSBAR:',$links,$template);

//Get the content for the side bar...

$sidebar getsidebar();
$template replace(':SIDEFEED:',$sidebar,$template);

//Get the ad content...
$template replace(':ADS:',$ads,$template);

//Get the slogan info
$template replace(':SLOGAN:',$slogan,$template);

echo 
$template;

// **********************************************************************
// End Template Definition
// **********************************************************************
?>
Reply With Quote