Breeding System - Complete!

Forum
Last Post
Threads / Messages

Arianna

Dev Staff
Staff member
Dev Staff
Joined
Sep 25, 2009
Messages
334
Points
0
Age
27
Mysidian Dollar
13,840
Firstly, I don't take credit for all this. This code was made by gabeki, Seapyramid, Brandon, and me. :D

You'll need to have some kind of gender mod for this, so viewing the thread that I have would be very useful. ;)

Just copy and paste the file at the bottom of this post into a file and call it 'breeding.php'. Then upload it via FTP or FileManager to your website, in the 'adoptables' folder (or whatever else you called it).

There are a few things you'll need to change - if you don't have a date system like me, take out the following part on line 204.
PHP:
$date = date("F jS, Y");

Then find and replace.
PHP:
//find this code, around line 207 or 208
mysql_query("INSERT INTO ".$prefix."owned_adoptables VALUES ('', '$type', '$name','$loggedinname','0','0', '$code', '','$alts','fortrade','no','$gender','$date')");
//replace it with this
mysql_query("INSERT INTO ".$prefix."owned_adoptables VALUES ('', '$type', '$name','$loggedinname','0','0', '$code', '','$alts','fortrade','no','$gender',)");

If you don't have a trade system or plan to install one, you can change 'fortrade' to 'notfortrade', though it is not nessecary.

The last thing you need is a link to the breeding page. You can put it in the top nav bar (I do that via PHPmyAdmin) or in the sidebar (functions.php) but make sure your members have some way to access it.

Tell me if there is anything left which is wrong with the code, please!

PHP:
<?php

// **********************************************************************
// Rusnak PHP Adoptables Script
// Copyright 2009 Brandon Rusnak
// For help and support: http://www.rusnakweb.com/forum/
//
// Redistribution prohibited without written permission
// **********************************************************************

// Wake the sleeping giant

// **********************************************************************
// Basic Configuration Info
// **********************************************************************

include("inc/functions.php");
include("inc/config.php");

$themeurl = grabanysetting("themeurl");

// **********************************************************************
// Define our top links by calling getlinks()
// **********************************************************************

$links = getlinks();

// **********************************************************************
// Define our ads by calling getads()
// **********************************************************************

$ads = getads("any");

// **********************************************************************
// Grab any settings that we will need for the current page from the DB
// **********************************************************************

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

// **********************************************************************
// Check and see if the user is logged in to the site
// **********************************************************************

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

// **********************************************************************
// End Prepwork - Output the page to the user
// **********************************************************************


$article_content = $article_title."Breeding System"; 
$article_content = $article_content."<p>Adoptable breeding systems sure aren't easy to make! I wish that this would work!</p>"; 

$femaleid = $_POST['female'];
$maleid = $_POST['male'];
$breed = $_POST['breed'];

$femaleid = secure($femaleid);
$maleid = secure($maleid);
$breed = secure($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 adoptable (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 ($i2 < $num2){
            $aid2 = @mysql_result($result2,$i2,'aid');
            $type2 = @mysql_result($result2,$i2,'type');
            $name2 = @mysql_result($result2,$i2,'name');

            $article_content = $article_content."<option value='".$aid2."'>".$name2." (".$type2.")</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 took out the incompatible part, it can be added back in if needed
        // 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 < 2 OR $female_level < 2){ //this is if they can't breed
            $article_content = $article_content."Sorry, one of your adoptables don't have the minimum level to breed. Keep feeding them so they can grow.";    
        } 

        else {
            //We choose the type!
					$temptype = rand(0, 1);
					if($temptype == "0") {
						$type = $male_type;
						unset($temptype);
					}
					else if($temptype = "1"){
						$type = $female_type;
						unset($temptype);
					}
			
			if ($type == $male_type) {
				$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");
			}
			
			else {
				$result3 = mysql_query("SELECT * FROM ".$prefix."adoptables WHERE type='$female_type'");
				$aid = mysql_result($result3,0,"id"); //The adoptable's ID
				$eggimage = mysql_result($result3,0,"eggimage");
			}
			
            // we're choosing a gender
			   
              
			$tempgender = rand(0, 1);

			if($tempgender == "0"){
				$new_name = "Son of ".$male_name." & ".$female_name;
				$gender = 'Male';
			}
			else if($tempgender == "1"){
				$new_name = "Daughter of ".$male_name." & ".$female_name;
				$gender = 'Female';
			}
			
			unset($tempgender);
			
            $article_content = $article_content."<p>Your adoptables are breeding.</p>";
         
            if ($type != "0"){
               $article_content = $article_content."<p>Result: <b>Bred Succesfully</b></p><p>Your new egg is being transferred to you right now. Yay!</p>";

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

               // now we're choosing the code
               $code = rand(1, 20000);

               $alts = getaltstatus($aid, 0, 0);

               // and the date comes in here too
               $date = date("F jS, Y");   
               
               $name = $new_name;

               mysql_query("INSERT INTO ".$prefix."owned_adoptables VALUES ('', '$type', '$name','$loggedinname','0','0', '$code', '','$alts','fortrade','no','$gender','$date')");

               $article_content = $article_content."<p><img src='".$eggimage."'><br /><a href='myadopts.php'>Manage ".$name." now!</a>
               It's type is ".$type." and it was born on ".$date."! You can change its name to your liking.</p>";
                    
			   unset($gender);
			   unset($type);

            } // if our type is not equal to zero, this is where we continue. this is the end of the continuation.
        } // 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
}// 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. Please log in to breed.";

}


// **********************************************************************
// 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
// **********************************************************************



?>
 
Thanks gabeki, Seapyramid, Brandon, and Arianna! I'm not sure when I'll be be able to try this out, but I definitely will in the future. Thanks for posting this!
 
Yes. :D Sea was nice enough to give me the code. :) Is there any chance this is interfering with the breeding code?
 
what do you mean by interfering? are you with some error?

how does sea's trading system works? I'll have to remake my code and I need some ideas ^^
 
gabeki said:
what do you mean by interfering? are you with some error?

how does sea's trading system works? I'll have to remake my code and I need some ideas ^^

Quite frankly, it seems to me if someone wants a code I haven't shared public they should ask me about it, not someone I gave it too....

Sea
 
I'm not giving her the code, I just thought that it might be somehow not working as she didn't have it on her install (because it might not take it if there are 'fortrades' in the table. Come to think of it, I don't think it checks, I just wanted to be sure.
By interfering, I meant that you not having it may be causing something. But IDK if that's how it works. [/php novice speak]
 
I wasn't impling anything on you Arianna.. Just saying that those who asked were asking the wrong person :)
 
Okay, that's good. :)
I can't wait to try out the system on my working site. (My pets haven't grown up yet. xD)
 
but the code that you need top put on the 207 line......in what of file you need to add(doadopt?myadopt?what??I)
 
Seapyramid, I did not ask for the code, can you read my post at least once, before saying something about it?

Thanks ^^

Or even better, even after you read it at least once, you can relax and THINK before you post. That way you can try to be less rude and more useful to people here in the Forum.

I read almost all the posts here in the adoptables forum, including yours, and seems to me that because you have a good site, with a good amout of members and scripts programmed by yourself, you think you can despise others members that are starting now. Well, it's not that way.

But, if you are rude not because you think you are something more than others members, but because of personal problems, I recommend yoga. And it doesn't mean I care about your stress or something, so no need to thank me. I just care about how I'm treated.
 
ok....now i show this hen i go in the Coupling:
i show this on the top of the page:
Code:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/a6518385/public_html/GcA/adoptables/breeding.php on line 81
WHY???
 
I don't know. Can you please be patient? Gosh, I don't even want to help if you're so impolite.
 
Arianna said:
I don't know. Can you please be patient? Gosh, I don't even want to help if you're so impolite.

Thank you for being polite Arianna. She brings up a very good point, she is spending her time maing this Modification because she wants too. She is even nice enough to help you install it.

SieghartZeke you act very impatiently in a lot of the threads you post in. I would like to ask you nicely to please be patient and to please show some respect.
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,277
Messages
33,118
Members
1,602
Latest member
BerrieMilk
BETA

Latest Threads

Top