Thread: Mys 1.3.1 Gender Ratio Mod for v1.3.1
View Single Post
  #1  
Old 04-15-2012, 03:33 PM
Hall of Famer's Avatar
Hall of Famer Hall of Famer is offline
Administrator, Lead Coder
 
Join Date: Dec 2008
Location: South Brunswick
Posts: 4,448
Gender: Male
Credits: 340,455
Hall of Famer is on a distinguished road
Default Gender Ratio Mod for v1.3.1

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!
Attached Files
File Type: rar gender ratio mod.rar (16.0 KB, 17 views)
__________________


Mysidia Adoptables, a free and ever-improving script for aspiring adoptables/pets site.
Reply With Quote