Mysidia Adoptables Support Forum

Mysidia Adoptables Support Forum (http://www.mysidiaadoptables.com/forum/index.php)
-   Mys v1.1.x Mods (http://www.mysidiaadoptables.com/forum/forumdisplay.php?f=20)
-   -   Hall of Famer's gender ratio system (http://www.mysidiaadoptables.com/forum/showthread.php?t=1611)

Hall of Famer 11-24-2010 02:46 AM

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:
http://oi54.tinypic.com/k2hesp.jpg



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:
http://oi52.tinypic.com/28pqb.jpg

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

PTGigi 11-25-2010 01:25 AM

RE: Hall of Famer's gender ratio system
 
Oh very nice :D I was wondering how to do something like this and thought out a not very good way to do it XD Nice of you to think of a better way. :D I'll be sure to test this out when I can get the time, thank you very much! =3

Hall of Famer 11-25-2010 01:58 AM

RE: Hall of Famer's gender ratio system
 
You are very welcome, glad you like it. ^^

Like I've pointed out before, there's still a small problem with the formula used to calculate gender ratio. There are 101 integers between 0 to 100, not 100. Because of this, it is impossible to achieve 50-50 chance for male or female adoptables(it will be 51-50 instead). There are ways to fix this I am sure, and one easy approach is to set the range of Gender ratio to be 0-99 or 1-100, but then it will lead to confusion of the definition of Gender Ratio. *sigh*

Also if you are running a pokemon site and you want genderless pokemon such as Magnemite, the script does a good job for you. All you have to do is to enter a gender ratio outside of the range 0-100. I did 101 for my pokemon such as Magnemite and Voltorb, but you can even try 1000 if you want to. The adoptable you get will always be genderless then.

PTGigi 11-25-2010 03:04 AM

RE: Hall of Famer's gender ratio system
 
Quote:

Originally Posted by Hall of Famer
Also if you are running a pokemon site and you want genderless pokemon such as Magnemite, the script does a good job for you. All you have to do is to enter a gender ratio outside of the range 0-100. I did 101 for my pokemon such as Magnemite and Voltorb, but you can even try 1000 if you want to. The adoptable you get will always be genderless then.

Lol did my name give it away? XD Thank you for that too :D It will most certainly come in handy =3

Hall of Famer 11-25-2010 02:50 PM

RE: Hall of Famer's gender ratio system
 
Well yeah, a Pokemon trainer. XD

And you are welcome, just use my script if its available for public. I am actually not even half as good as Kaeliah when it comes to PHP coding, and if you ever encounter glitches please lemme know.

PTGigi 11-27-2010 11:39 PM

RE: Hall of Famer's gender ratio system
 
Quick question, to get an all female or all male you use 0 and 100 right? 0 for all male and 100 for all female?

Also couldn't you change $tempgender = rand(0, 100); to $tempgender = rand(1, 100); to erase the 50-51 problem? =3 (not sure just started PHP X3)

Hall of Famer 11-28-2010 01:25 AM

RE: Hall of Famer's gender ratio system
 
Quote:

Originally Posted by pokemontrainergigi
Quick question, to get an all female or all male you use 0 and 100 right? 0 for all male and 100 for all female?

Also couldn't you change $tempgender = rand(0, 100); to $tempgender = rand(1, 100); to erase the 50-51 problem? =3 (not sure just started PHP X3)

Since this is a female gender ratio script, I'd say 100 = all female and 0 = all male.

Well yeah, you can technically change that to as simple as 0 to 9. The problem is that most people are used to the idea of having a range of ratio/percentage between 0 to 100, but sure you can do that. ^^

Hall of Famer 12-24-2010 09:59 PM

RE: Hall of Famer's gender ratio system
 
Oh btw, Arianna's gender mod is added in RA version 1.1, so you do not have to install any pre-requisites if you use RA version 1.1. Simply follow the rest of the steps as I provided a few weeks ago and you should have a fully functioning gender ratio system. ^^

Merry Christmas everyone!

Hall of Famer

RoconzaArt 01-24-2011 01:06 AM

I'm getting this error:

Quote:

The ID specified does not match any adoptable in our system. Sorry. If you wish, you can adopt a pet.
Did I do some thing wrong?

Hall of Famer 01-24-2011 01:15 AM

Can you show me the tables prefix_adoptables and prefix_owned_adoptables from phpmyadmin? My initial guess is that your table structure is different so the sql query lines must be modified to account for this change.


All times are GMT -5. The time now is 06:47 PM.

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