Mysidia Adoptables Support Forum

Mysidia Adoptables Support Forum (http://www.mysidiaadoptables.com/forum/index.php)
-   Mys v1.3.x Mods (http://www.mysidiaadoptables.com/forum/forumdisplay.php?f=42)
-   -   Mys v1.3.1 Gender Ratio Mod for v1.3.1 (http://www.mysidiaadoptables.com/forum/showthread.php?t=3592)

Hall of Famer 04-15-2012 03:33 PM

Gender Ratio Mod for v1.3.1
 
1 Attachment(s)
It is about time to upgrade some of my old Mods. This one is the simple Gender Ratio addon, which I have been thinking about whether to add into the official package. Lemme know if you want this to happen, it is really an easy modification anyway.

I've provided a zip file that contains all necessary modifications to make in your script file in order to get this to work. Incase you have a highly customized site, you may install this Mod manually by following the instruction below. To begin with, insert a new column into table prefix.adoptables as usual:

PHP Code:

'genderratio'INT11 ), default 50 

Since admin.php file does not exist nowadays, you need to go to the file /admincp/adopt.php to modify the form. To add the input field Genderratio into adoptables creation form, find the following code below:

PHP Code:

                            <p>
                            <
input name='page' type='hidden' id='page' value='createanadopt'>
                            <
input type='submit' name='Submit' value='Create This Adoptable'
                            </
p>
                            </
form>"; 

Add above

PHP Code:

                                  <p>The Gender Ratio of your adoptable is 
                          
<input name='genderratio' type='text' id='genderratio' size='6' maxlength='6'
                          <
p

The gender ratio input field can theoretically be added anywhere you like, just do not 'break' your form. As you have completed this very first step, go to admincp/adoptpost.php and find these lines:

PHP Code:

            $alternates $_POST["alternates"];
            
$altoutlevel $_POST["altoutlevel"];
            
$altchance $_POST["altchance"]; 

Add below:

PHP Code:

$genderratio $_POST["genderratio"]; 

Then find this database insert code you should be familiar with:

PHP Code:

$adopts->insert("adoptables", array("id" => NULL"type" => $name"class" => $class"description" => $description"eggimage" => $eggimage"whenisavail" => $cba,
                                                    
"alternates" => $alternates"altoutlevel" => $altoutlevel"altchance" => $altchance"cost" => $cost)); 

Replace by the following new line:

PHP Code:

                $adopts->insert("adoptables", array("id" => NULL"type" => $name"class" => $class"description" => $description"eggimage" => $eggimage"whenisavail" => $cba,
                                                    
"alternates" => $alternates"altoutlevel" => $altoutlevel"altchance" => $altchance"cost" => $cost"genderratio" => $genderratio)); 

The last thing to do, of course, is to manually update our doadopt.php file to enable gender ratio to work while a user is trying to adopt a pet. Find these lines that determine adoptables gender:

PHP Code:

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

Replace by the gender ratio generation code:
PHP Code:

                       if($tempgender $row->genderratio){
                            
$gender "f";
                            unset(
$tempgender);
                        }
                        else {
                            
$gender "m";
                            unset(
$tempgender);
                        }
  
                        
$adopts->insert("owned_adoptables", array("aid" => NULL"type" => $row->type"name" => $name"owner" => $loggedinname"currentlevel" => 0"totalclicks" => 0"code" => $code
                                        
"imageurl" => NULL"usealternates" => $alts"tradestatus" => 'fortrade'"isfrozen" => 'no'"gender" => $gender"lastbred" => 0)); 

You are done with it, or almost. The below edit is not required, but for those who want pets gender ratio to take effect on breeding. To do this, you need to go to breeding.php and find the following lines:

PHP Code:

            $genders = array('f''m');
            
$genderrand rand(0,1); 

Replace with:

PHP Code:

            $genderratio = ($typerand == 0)?$female_species->genderratio:$male_species->genderratio;
            
$tempgender rand(099);
            if(
$tempgender $genderratio){
               
$gender "f";
            unset(
$tempgender);
            }
            else {
                
$gender "m";
                unset(
$tempgender);
            } 

Now we are all done, it is just this simple isnt it? Like I mentioned earlier I've uploaded a zip file containing all modified scripts for those who are running a fresh installation of Mysidia Adoptables. Note you can only use them if you have not heavily modified your script files. The install_genderratio.php file needs to be executed to insert the column genderratio(INT 11) automatically to your database, although you can again do it manually. Enjoy!

PokePets 04-16-2012 09:05 AM

Thaaanks *will use*

Tequila 04-20-2012 09:28 AM

Trying to install this for CH, and I'm getting the following as an error:
Quote:

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/u666097869/public_html/admincp/adopt.php on line 549
When I look the string up it's the following:
PHP Code:

"<input name='reward' type='checkbox' id='reward' value='yes'>"

Any idea?

Hall of Famer 04-20-2012 09:39 AM

1 Attachment(s)
My goodness, what a mistake. I accidentally typed an arbitrary string(generated from strongpassword.com) into the /admincp/adopt.php file... *sigh* Now just download the new file and it should work nicely:

Tequila 04-20-2012 09:58 AM

Thanks, it works now. ;3

kristhasirah 05-23-2012 11:30 AM

HI, i have a problem when it comes to breeding, the offspring dont have a gender, dont know if the problem is how i created the parents, or if is the code...
i usually create 2 adopts 1 100% female and 1 100% male. my site is based on pokemon, so in order to add the shiny version i do that, and works perfectly when adopting, but when it comes to breeding is like the code cant decide if the offspring is going to be male or female.... is there a way to fix that? right now i use the original breeding code, but i have to change some of the images manually, because it use the male image on a female.

SilverDragonTears 05-23-2012 12:19 PM

You have to do the same thing to the breeding script that you did with the adopt script.

kristhasirah 05-23-2012 04:51 PM

i did change it, i followed HoF instructions, and after that, the offspring dint get a gender. so i reverted the changes that i made to the breeding code.

PTGigi 05-23-2012 05:11 PM

Quote:

This one is the simple Gender Ratio addon, which I have been thinking about whether to add into the official package. Lemme know if you want this to happen, it is really an easy modification anyway.
I think you should add it! (...because I completely forgot it wasn't built in already XD)

MaximumRide 05-23-2012 05:34 PM

What does this do? :)

SilverDragonTears 05-23-2012 05:42 PM

Can you post your breeding script for me?

kristhasirah 05-23-2012 05:53 PM

sure: this is the edited code, and i only edited the area with the gender.
Code:

//***************//
//  START SCRIPT //
//***************//

$breedinglevel = grabanysetting('breedinglevel');

$article_title = "Breeding System";
$article_content = "<p>You may breed your adoptables here. They must be at least a level {$breedinglevel} to be able to breed.</p>";

$femaleid = $_POST['female'];
$maleid = $_POST['male'];
$breed = $_POST['breed'];
$userstatus = getuserstatus($loggedinname);

if($isloggedin == "yes" and $userstatus['canbreed'] == "yes"){
    if ($breed != 'yes'){ // if they have not chosen which pets to breed yet, we let them choose
        $article_content .= "<p>Select the two adoptables that you'd like to breed:</p><form method='post'>";
                $lastweek = time() - ((grabanysetting('breedinginterval')) * 24 * 60 * 60);
               
                // show all available female adoptables
        $stmt = $adopts->select("owned_adoptables", array(), "owner = '{$loggedinname}' AND gender = 'f' AND currentlevel >= {$breedinglevel} AND lastbred <= '{$lastweek}'");
        $row = $stmt->fetchObject();
                if(is_object($row)){
            //Fetch the first row...
                        $article_content .= "<p>Female: <select name='female'>
            <option value='{$row->aid}'>{$row->name} ({$row->type})</option>";

            // Continue to fetch more rows...
                        while ($row = $stmt->fetchObject()) {
                                $article_content .= "<option value='{$row->aid}'>{$row->name} ({$row->type})</option>";
                        }
                        $article_content .= "</select></p>";
                }
                else {
                        $article_content .= "<p>None of your female adoptables can breed at the time.</p>";
                }
               
                // show all available male adoptables
                $stmt = $adopts->select("owned_adoptables", array(), "owner = '{$loggedinname}' AND gender = 'm' AND currentlevel >= {$breedinglevel} AND lastbred <= '{$lastweek}'");
        $row = $stmt->fetchObject();
                if (is_object($row)) {
                        $article_content .= "<p>Male: <select name='male'>
                                <option value='{$row->aid}'>{$row->name} ({$row->type})</option>";
                        while ($row = $stmt->fetchObject()) {
                                $article_content .= "<option value='{$row->aid}'>{$row->name} ({$row->type})</option>";
                        }
                        $article_content .= "</select></p>";
                }
                else {
                        $article_content .= "<p>None of your male adoptables can breed at the time.</p>";
                }
        $article_content .= "<input type='hidden' name='breed' value='yes'><input type='submit' value='Breed It'></form>";
    }
    else {
                $female = $adopts->select("owned_adoptables", array(), "aid = '{$femaleid}'")->fetchObject();       
                $female_species = $adopts->select("adoptables", array(), "type = '{$female->type}'")->fetchObject();       
        $female_class = explode(",",$female_species->class);
               
                $male = $adopts->select("owned_adoptables", array(), "aid = '{$maleid}'")->fetchObject();       
                $male_species = $adopts->select("adoptables", array(), "type = '{$male->type}'")->fetchObject();
        $male_class = explode(",",$male_species->class);

                // let's check the requirements first.
        if(classcheck($female_class, $male_class) == "no"){//check if the male and female belong to the same breeding class
            $article_content = "Sorry, it seems that your two adoptables do not belong to the same breeding class.";
        }
        elseif(($female->currentlevel < (grabanysetting('breedinglevel'))) OR ($male->currentlevel < (grabanysetting('breedinglevel')))){ // check the adoptables' levels
            $article_content .= "Sorry, one of your adoptables don't have the minimum level to breed. Keep getting clicks for them so they can grow.";   
        }
        elseif($female->owner != $loggedinname or $male->owner != $loggedinname){
          // The adoptables do not belong to the owner... This user has apparently modified the content of drop-down form, and thus deserves his/her punishment
          $ban = banuser($loggedinname);
          $article_title = "An error has occurred";   
          $article_content = "It appears that at least one of the adoptables selected do not belong to yours. You have been banned for this action, please contact site administrator for more info.";
        }
        elseif($female->gender != "f" or $male->gender != "m"){
          // The female's gender is male or male's gender is female? This user has apparently modified the content of drop-down form, and thus deserves his/her punishment
          $ban = banuser($loggedinname);
          $article_title = "An error has occurred";   
          $article_content = "It appears that the female and/or male adoptables gender's have been modified. You have been banned for this action, please contact site administrator for more info.";             
        } 
        else {
                        // we choose the type!
                        $types = array($female->type, $male->type);
                        $typerand = rand(0,1);               
                       
                        // we choose the gender
                        $genderratio = ($typerand == 0)?$female_species->genderratio:$male_species->genderratio;
                        $tempgender = rand(0, 99);
            if($tempgender < $genderratio){
              $gender = "f";
            unset($tempgender);
            }
            else {
                $gender = "m";
                unset($tempgender);
            }                               
            $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
    } //this bracket ends the else where we find the male/female id's
}// this is the end of if($isloggedin == "yes")
elseif($isloggedin == "yes" and $userstatus['canbreed'] == "no"){
    $article_content .= "It appears that you have been banned from breeding your adoptables. Please contact an administrator for assistance."; 
}
else {
    $article_content .= "You are not logged in. Please log in to use this feature.";
}

//***************//
//  OUTPUT PAGE  //
//***************//

echo showpage($article_title, $article_content, $date);

?>


SilverDragonTears 05-23-2012 07:38 PM

Change this:
Code:

$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 this:
Code:

$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" => $gender, "lastbred" => 0));


kristhasirah 05-24-2012 11:09 AM

THANK YOU! everything is working perfectly now! =D

quirkii 08-15-2012 10:30 AM

Hi, there seems to be a problem with the gender ratio mod. Everything worked great and all, except that it seemed to have caused some redirecting errors after adopting a pet.

Usually, after the adoption; users would be redirected to a page where they'll be told to either manage or feed their adoptables. Prior to installing the gender ratio mod, this part had no problems. But after installing it- this error message saying "invalid adoptable id specifiedThe ID specified does not match any adoptable in our system. Sorry. If you wish, you can adopt a pet." appears instead. The url, which usually displays the id number of the adoptable- did not generate. What I mean by that is that it turns out like this>> "website.com/myadopts.php?act=manage&id=" when it should have been "website.com/myadopts.php?act=manage&id=1" (example).

Can anyone provide a fix to this problem?

Hall of Famer 08-17-2012 03:25 AM

I see, it appears that the adoptables id is not loaded correctly. I do not think anyone else has reported this problem a few months ago, so there's a good chance that you installed the mod incorrectly. Would you mind showing me your doadopt.php file after installing this mod? I can fix it for you then.


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

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