Hall of Famer's Gender Ratio Mod v1.2

Forum
Last Post
Threads / Messages

Hall of Famer

Administrator
Staff member
Administrator
Joined
Dec 15, 2008
Messages
4,564
Points
48
Location
United States
Mysidian Dollar
214,223
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:
'genderratio', INT( 11 )', default 50
Next, go to admin.php and find the following lines:

PHP:
                                            <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:
 <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:
        $alternates = $_POST["alternates"];
        $altoutlevel = $_POST["altoutlevel"];
        $altchance = $_POST["altchance"];
Add below:
PHP:
        $genderratio = $_POST["genderratio"];
Also in nadopt.php, find the following codes:

PHP:
            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:
            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:
                        $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:
$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
 

Attachments

  • install_genderratio.php
    487 bytes · Views: 17
umm there is no gender ratio feature for an official release. I am assuming you are talking about the old gender ratio script I made for Mys v1.1.x? Well there aint a big difference, just this one is for Mys v1.2.x and the old one may not be compatible with latest release.
 
With the gender ratio script you can set the ratio of male and female for a certain species, it can even be 100% male or 100% female.
 
Thanks for your comment, you are again more than welcome to test the code on your site to see if it works for you.
 
I will eventually... .I don't think I have use for it at the moment... but I'm sure I will soon.
 
Alright, you may use it at anytime you want. There is a chance that I may update the script once Mys v1.3.0 is released. Also the Gender Ratio Mod v1.2 fixed a flaw in the old script. It may take some time to explain, I will tell you if you want to.
 
my doadopt.php looks like this:

Code:
$code = rand(1, 20000);
                        $genders = array('f', 'm');
                        $rand = rand(0,1);
                        $petgender = $genders[$rand];
                        switch($petgender){
                          case "f": 
                          $alts = "yes";
                          break;
                          default: 
                          $alts = "no";
                        }

b/c i'm using the alternate gender mod. How do i use it with this?
 
Well then, remove the alternate gender mod codes you've posted above, and replace with this:

PHP:
$code = rand(1,20000)
$tempgender = rand(0, 99);
if($tempgender < $row['genderratio']) {
$gender = "f";
$alts = "yes";    
unset($tempgender);
}
else {
$gender = "m";
$alts = "no";          
unset($tempgender);
}

runquery("INSERT INTO {$prefix}owned_adoptables VALUES ('',  '{$row['type']}', '$name','$loggedinname','0','0', '$code',  '','$alts','fortrade','no', '$gender','0')");
 
I some how did some thing wrong and it's not creating the adoptable. I can't tell if it this or a evolution mod.The adopt shows up in the adopt page but when I go to adopt it, it will not add the adopt to my account.
 
Last edited:
Well are you like unable to create new adoptables through ACP, or that you cannot adopt new pets? Chances are your database structures in prefix.adoptables and prefix.owned_adoptables are messed up, please show me what you get from phpMyadmin. I do not believe the evolution system will cause any problem like that, since it does not really modify any existing tables or columns.
 
2pzcgh0.jpg

dra7p2.jpg
 
Well did you follow the instruction I provided? The tables look fine, you will need to go to nadopt.php and find this line:

PHP:
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}')");

See if your mysql query insert command is different from the one I provided. If so, replace the old one with the new line above.
 
I did what you said and it's still not working.

PHP:
<?php

include("inc/functions.php");
$admin = true;

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

if($isloggedin == "yes")
{
	$group = getgroup();
	$cancp = cancp($group);
	$canedit = cando($group, "canmanageadopts");

	if($cancp == "yes" and $canedit == "yes")
	{
		// We are logged in and can access this page, so let's get the post info...
		$name = $_POST["name"];
		$class = $_POST["class"];
		$description = $_POST["description"];
		$cost = $_POST["cost"];
		$imageurl = $_POST["imageurl"];
		$existingimageurl = $_POST["existingimageurl"];
		$cba = $_POST["cba"];
		$promocode = $_POST["promocode"];
		$freqcond = $_POST["freqcond"];
		$number = $_POST["number"];
		$datecond = $_POST["datecond"];
		$date = $_POST["date"];
		$adoptscond = $_POST["adoptscond"];
		//////////////////////////////////////////////////////////////////////
		$maxnumcond = $_POST["maxnumcond"];
		$morethannum = $_POST["morethannum"];
		$usergroupcond = $_POST["usergroupcond"];
		$usergroups = $_POST["usergroups"];
		//////////////////////////////////////////////////////////////////////
		$alternates = $_POST["alternates"];
		$altoutlevel = $_POST["altoutlevel"];
		$altchance = $_POST["altchance"];
		$genderratio = $_POST["genderratio"];  

		// Now we run some checks to make sure that we have a go.

		if($name == "")
		{
			$error = "You did not enter in a name for the adoptable. Please go back and try again.";
		}

		if($name == "")
		{
			$error = "You did not enter in a name for the adoptable. Please go back and try again.";
		}

		if($imageurl == "" and $existingimageurl == "none")
		{
			$error = "You did not select an image for this adoptable. Please go back and make sure an image is selected for this adopt.";
		}

		if($imageurl != "" and $existingimageurl != "none")
		{
			$error = "You selected two images for the adoptable's egg image. Please go back and make sure that either the image textbox is blank or the image dropdown box is set to No Exising Image.";
		}

		if($cba != "always" and $cba != "promo" and $cba != "conditions")
		{
			$error = "You did not choose a valid scenario when this adoptable can be adopted. Please go back and either select the Always option, the Promo option or the Conditions option.";
		}

		//If we are using a promo code, we should have a promo code in the box...
		if($cba == "promo" and $promocode == "")
		{
			$error = "You selected that this adoptable is available for adoption only with a promo code, but you did not enter in a promo code. Please go back and either change this setting or type in a valid promo code.";
		}

		//If we are using conditions...

		if($cba == "conditions")
		{
			if($freqcond == "enabled" and !is_numeric($number))
			{
				$error = "A condition is enabled but is blank or has an incorrect value. Please go back and double check your conditions and that they contain valid input.";
			}

			if($datecond == "enabled" and $date == "")
			{
				$error = "A condition is enabled but is blank or has an incorrect value. Please go back and double check your conditions and that they contain valid input.";
			}

			if($adoptscond == "enabled")
			{
				if($moreless == "" or !is_numeric($morelessnum) or $levelgrle == "" or !is_numeric($grlelevel))
				{
					$error = "A condition is enabled but is blank or has an incorrect value. Please go back and double check your conditions and that they contain valid input.";
				}
			}

			if($maxnumcond == "enabled" and !is_numeric($morethannum))
			{
				$error = "A condition is enabled but is blank or has an incorrect value. Please go back and double check your conditions and that they contain valid input.";
			}

			if($usergroupcond == "enabled" and !is_numeric($usergroups))
			{
				$error = "A condition is enabled but is blank or has an incorrect value. Please go back and double check your conditions and that they contain valid input.";
			}
		}

		if($alternates == "enabled")
		{
				if(!is_numeric($altoutlevel) or !is_numeric($altchance))
				{
					$error = "There has been an error with the adoptable's alternate settings you selected. Please go back and make sure the alternate values are filled in correctly.";
				}
		}

		//Check and see if an adoptable with this name already exists...

		$query = "SELECT * FROM {$prefix}adoptables WHERE type = '{$name}'";
		$result = runquery($query);
		$num = mysql_num_rows($result);

		if($num > 0)
		{
			$error = "An adoptable with this name already exists in your database. Please go back and rename the adoptable to something different.";
		}

		//If we have an error, show it.  Otherwise continue...

		if($error != "")
		{
			$article_title = "An Error Has Occurred!";
			$article_content = $error;
		}
		else
		{
			//There has been no error, continue with the addition of the adoptable to the system...

			//First determine which image URL to use...

			if($imageurl != "" and $existingimageurl == "none")
			{
				$eggimage = $imageurl;
			}
			else
			{
				$eggimage = $existingimageurl;
			}

			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}')");  
			// insert our level thing
			runquery("INSERT INTO {$prefix}levels VALUES ('{$name}', '0', '0', '{$eggimage}','','','')");

			$article_title = "Adoptable Added Successfully";
			$article_content = "Your adoptable, {$name}, has been added to the database successfully. You can now <a href='admin.php?set=adopts&do=addlevel'>Add a Level</a> to this adoptable. You can also <a href='admin.php'>go back to the Admin CP index page</a>.";
		}
	} //This bracket ends the check of whether or not this user can access the adopts portion of the ACP
}
else
{
	$article_title = "Access Denied";
	$article_content = "Access Denied";
}

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

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

?>
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,277
Messages
33,118
Members
1,602
Latest member
BerrieMilk
BETA

Latest Threads

Latest Posts

Top