Well it is finally time to upgrade my old Mods to Mys v1.2.x compatible version. The first one I am doing is this Gender Ratio Mod, since its rather simple. The evolution Mod will be done after I complete ACP-Integration for Itemshop, it will use the plugin system just like Kaeliah's Multi-Adopt Image engine.
To start off, I am assuming you guys/gals know how to add columns in tables? Well it does not matter if you dont, just run the script called install_genderratio.php on your site and delete it. Anyway create a new column at the end of table prefix.adoptables:
PHP Code:
'genderratio', INT( 11 )', default 50
Next, go to admin.php and find the following lines:
PHP Code:
<p>Alternate Outcomes Selection Information:</p>
<p>
Start using the alternate outcome at level number:
<input name='altoutlevel' type='text' id='altoutlevel' size='6' maxlength='6'>
<br />
(Use Level 0 to have the alternate outcome be used from birth. This will not affect the first / egg image.)
</p>
<p>
The alternate outcome has a chance of 1 in
<input name='altchance' type='text' id='altchance' size='6' maxlength='6'>
of being selected.<br />
(Here you can select the chance that the alternate images for this adoptable are used.
So, for an equal chance of using say male or female images,
put 2 in the box to have a 1 out of 2 or 50% chance of using the alternate image.
If you want to have the alternate images be rare images, use a higher number,
like 100 for a 1 out of 100 chance of using the alternates.)
</p>
<p>
<input type='submit' name='Submit' value='Create This Adoptable'>
</p>
</form>";
Replace with:
PHP Code:
<p>Alternate Outcomes Selection Information:</p>
<p>
Start using the alternate outcome at level number:
<input name='altoutlevel' type='text' id='altoutlevel' size='6' maxlength='6'>
<br />
(Use Level 0 to have the alternate outcome be used from birth. This will not affect the first / egg image.)
</p>
<p>
The alternate outcome has a chance of 1 in
<input name='altchance' type='text' id='altchance' size='6' maxlength='6'>
of being selected.<br />
(Here you can select the chance that the alternate images for this adoptable are used.
So, for an equal chance of using say male or female images,
put 2 in the box to have a 1 out of 2 or 50% chance of using the alternate image.
If you want to have the alternate images be rare images, use a higher number,
like 100 for a 1 out of 100 chance of using the alternates.)
</p>
<p>The Gender Ratio of your adoptable is
<input name='genderratio' type='text' id='genderratio' size='6' maxlength='6'>
<p>
<p>
<input type='submit' name='Submit' value='Create This Adoptable'>
</p>
</form>";
Now you will have to edit nadopt.php to ensure the value entered for genderratio will appear in database. Find:
PHP Code:
$alternates = $_POST["alternates"];
$altoutlevel = $_POST["altoutlevel"];
$altchance = $_POST["altchance"];
Add below:
PHP Code:
$genderratio = $_POST["genderratio"];
Also in nadopt.php, find the following codes:
PHP Code:
runquery("INSERT INTO {$prefix}adoptables VALUES ('', '{$name}', '{$class}' ,'{$description}','{$eggimage}','{$cba}','{$promocode}', '{$freqcond}', '{$number}','{$datecond}','{$date}','{$adoptscond}','{$maxnumcond}','{$morethannum}','{$usergroupcond}','{$usergroups}','{$alternates}','{$altoutlevel}','{$altchance}', '{$cost}')");
Replace with:
PHP Code:
runquery("INSERT INTO {$prefix}adoptables VALUES ('', '{$name}', '{$class}' ,'{$description}','{$eggimage}','{$cba}','{$promocode}', '{$freqcond}', '{$number}','{$datecond}','{$date}','{$adoptscond}','{$maxnumcond}','{$morethannum}','{$usergroupcond}','{$usergroups}','{$alternates}','{$altoutlevel}','{$altchance}', '{$cost}', '{$genderratio}')");
You are done with nadopt.php, but the game is not over yet. We have yet to add the gender generation script. To do this, open doadopt.php and find the following lines:
PHP Code:
$genders = array('f', 'm');
$rand = rand(0,1);
runquery("INSERT INTO {$prefix}owned_adoptables VALUES ('', '{$row['type']}', '$name','$loggedinname','0','0', '$code', '','$alts','fortrade','no', '$genders[$rand]','0')");
Replace the entire text with:
PHP Code:
$tempgender = rand(0, 99);
if($tempgender < $row['genderratio']) {
$gender = "f";
unset($tempgender);
}
else {
$gender = "m";
unset($tempgender);
}
runquery("INSERT INTO {$prefix}owned_adoptables VALUES ('', '{$row['type']}', '$name','$loggedinname','0','0', '$code', '','$alts','fortrade','no', '$gender','0')");
This should do the trick. I've uploaded the file install_genderratio.php, run it on your site to add column genderration in only one step. Note the range of gender ration is between 0 to 100. A gender ratio of 0 means the adoptable is 100% male, a gender ratio of 100 means the adoptable is 100% female. The adoptable has equal chance to be male or female if the value is set to be 50.
Hall of Famer