View Single Post
  #1  
Old 11-24-2010, 02:46 AM
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: 393,118
Hall of Famer is on a distinguished road
Default Hall of Famer's gender ratio system

Well this one is based on Arianna's gender mod. As far as I know, Kaeliah already has a gender ratio/chance system before I made this one, so I do not take any credits for this script. Dont forget to credit Arianna though, she was the first one to bring up this excellent gender idea that Rusnak Adoptables were originally, lacking.

Before you proceed, make sure you you have Arianna's gender system on your script already. Her thread can be found here:
http://www.rusnakweb.com/forum/showthread.php?tid=1367&page=1

It is rather straight forward to follow Arianna's mod-installation guide, so I wont explain much. The script simply defines a new variable Gender, which is a random number that has 50-50 chance of being male or female. The myadopts.php also displays an adoptable's gender. For those of you who do not know how to add a gender column to the 'owned_adoptables' table, I've attached this screenshot below for you to follow the instruction. Shouldnt be hard though, there's no coding involved:




Alright lets get started on this gender ratio system. Before we proceed, it is necessary to add a new column called 'genderratio' to the table adoptables. Its strongly advised that you add it to the last column.

After this is done, go to admin.php and find the codes below:

PHP Code:
 <hr>
  <
p><strong>Alternate Outcomes Settings:</strong></p>
  <
p>This section allows you to set if you want to enable alternate outcomesThis setting allows you to specify what the chances are of a user getting an alternate or special version of this adoptableCheck the checkbox below to enable this feature and then fill out the information below.. </p>
  <
p><strong>
    <
input name='alternates' type='checkbox' id='alternates' value='enabled'>
</
strong>Enable Alternate Outcomes </p>
  <
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 birthThis 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 usedSo, for an equal chance of using say male or female imagesput 2 in the box to have a 1 out of 2 or 50chance of using the alternate image. If you want to have the alternate images be rare images, use a higher numberlike 100 for a 1 out of 100 chance of using the alternates.)</p>
  <
p>
    <
input type='submit' name='Submit' value='Create This Adoptable'
  </
p>
  <
p>&nbsp; </p>
</
form>"; 
Select and replace the entire codes with:

PHP Code:
<hr>
  <
p><strong>Alternate Outcomes Settings:</strong></p>
  <
p>This section allows you to set if you want to enable alternate outcomesThis setting allows you to specify what the chances are of a user getting an alternate or special version of this adoptableCheck the checkbox below to enable this feature and then fill out the information below.. </p>
  <
p><strong>
    <
input name='alternates' type='checkbox' id='alternates' value='enabled'>
</
strong>Enable Alternate Outcomes </p>
  <
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 birthThis 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 usedSo, for an equal chance of using say male or female imagesput 2 in the box to have a 1 out of 2 or 50chance of using the alternate image. If you want to have the alternate images be rare images, use a higher numberlike 100 for a 1 out of 100 chance of using the alternates.)</p>
  <
p>
  <
p>The Gender Ratio of your adoptable is 
  
<input name='genderratio' type='text' id='genderratio' size='6' maxlength='6'
  <
p>
<
input type='submit' name='Submit' value='Create This Adoptable'
  </
p>
  <
p>&nbsp; </p>
</
form>"; 

You can see that we add codes for gender ratio in admin control panel, so you will be able to define gender ratio in acp instead of going all the way to PHPmyadmin. You will have to modify nadopt.php next, otherwise you will not be able to create new adoptables!



In nadopt.php, find:

PHP Code:
$alternates $_POST["alternates"];
$alternates secure($alternates);

$altoutlevel $_POST["altoutlevel"];
$altoutlevel secure($altoutlevel);

$altchance $_POST["altchance"];
$altchance secure($altchance); 
Add below:

PHP Code:
$genderratio $_POST["genderratio"];
$genderratio secure($genderratio); 
Also find the sql commands in this script file:

PHP Code:
mysql_query("INSERT INTO ".$prefix."adoptables VALUES ('', '$name', '$description','$eggimage','$cba','$promocode', '$freqcond', '$number','$datecond','$date','$adoptscond','$maxnumcond','$morethannum','$usergroupcond','$usergroups','$alternates','$altoutlevel','$altchance')"); 
Replace with:

PHP Code:
mysql_query("INSERT INTO ".$prefix."adoptables VALUES ('', '$name', '$description','$eggimage','$cba','$promocode', '$freqcond', '$number','$datecond','$date','$adoptscond','$maxnumcond','$morethannum','$usergroupcond','$usergroups','$alternates','$altoutlevel','$altchance','$genderratio')"); 


Alright now we are done with nadopt.php. This isnt over yet, we will have to add codes for the actual gender ratio system. In doadopt.php, find:

PHP Code:
$name $_GET["name"];
$name preg_replace("/[^a-zA-Z0-9\\040.]/"""$name);
$name secure($name); 
Add below:

PHP Code:
$genderratio $_GET["genderratio"];
$genderratio preg_replace("/[^a-zA-Z0-9\\040.]/"""$genderratio);
$genderratio secure($genderratio); 
This is how we define the variable $genderratio in doadopt.php. Note this ratio must be an integer. After you complete this step, find:

PHP Code:
$aid=@mysql_result($result,$i,"id"); //The adoptable's ID
$type=@mysql_result($result,$i,"type");
$description=@mysql_result($result,$i,"description");
$eggimage=@mysql_result($result,$i,"eggimage"); 
Add below:

PHP Code:
$genderratio=@mysql_result($result,$i,"genderratio"); 
This is how we retrieve data from sql. Here comes the fun, I promise it does. Search for the codes below:

PHP Code:
//The gender mod
$tempgender rand(01);
if(
$tempgender == "0") {
$gender "Female";
unset(
$tempgender);
}
else {
$gender "Male";
unset(
$tempgender);

Yes this is Arianna's gender mod. You will have to install it before using my gender ratio script. We are going to replace Arianna's gender determination system with this gender ratio system. So select the codes and replace with:

PHP Code:
//The gender mod
if($genderratio >= and $genderratio 101) {
$tempgender rand(0100);
if(
$tempgender >= and $tempgender $genderratio) {
$gender "Female";
unset(
$tempgender);
}
else {
$gender "Male";
unset(
$tempgender);
}
}
else {
$gender "Genderless";


So yes, we are all set now. Isnt this easy? Well there is a flaw in this code that the gender ratio is actually not 50-50 when you set the gender ratio to be 50. This is because there are actually 101 integers between 0 to 100. One way to solve this problem is to use another if-else statement that deals with gender ratio = 50, another way is to increase the gender ratio maximum from 100 to 1000, or even 10000. This may sound confusing, but please give a try if you are an aspiring coder.

Also, keep in mind that this is actually female gender ratio, not male gender ratio. A gender ratio of 80 typically tells us that you have 80% chance to get female adoptable, and 20% chance of getting male adoptable. Similarly, a gender ratio of 15 means that you only have 15% chance to get a female adoptable. What if you enter a gender ratio above 100? Well, if you actually look into the codes I wrote, I define it as genderless and such cases may exist for adoptables like Magnemite and Shellder in pokemon series. Make good use of it if you can. Here is an example of my genderless Magnemite:


Thats the end of it. Sorry I wrote a lot, and thanks for taking the time and trouble to go through the entire article. I hope it helps.

Hall of Famer
Reply With Quote