PDA

View Full Version : Mys 1.3.3 Gender Ratio Mod for Mys v1.3.3


Hall of Famer
03-16-2013, 07:37 PM
Now that Mys v1.3.3 has been released, it is about time for me to update my old addons/plugins to be compatible with the new version. The first Mod I have converted is this gender ratio Mod, whose process took me just about half an hour. I've included an rar file at the end of this post for you to download the files, make sure to enter the directory /install and execute the file /install/genderratio.php so that the column genderratio will be inserted successfully into the database.

Incase you cannot use the default files I have provided for some reason, I am writing a simple guide for manual installation of this Mod. It is quite easy, and requires less script edits than the older version.


Anyway, to begin with, insert the column genderratio into your table prefix.adoptables. Its type is INT, default value should be 50:


'genderratio', INT( 11 ), default 50


After this is done, go to your script file /admincp/adopt.php, and find the following code:


$adoptForm->add($basicInfo);
$adoptForm->add($shopSettings);
$adoptForm->add($conditions);
$adoptForm->add($miscellaneous);
$adoptForm->add(new Button("Create this Adoptable", "submit", "submit"));
$document->add($adoptForm);


Add above:(it actually does not matter if you mistakenly inserted these lines below instead, thats the beauty of OOP and GUI!)

$miscellaneous->add(new Comment("The Gender Ratio of your adoptable is ", FALSE));
$miscellaneous->add(new TextField("genderratio", 50));


Before closing this file, find the sql insertion query for prefix.adoptables at:

$mysidia->db->insert("adoptables", array("id" => NULL, "type" => $mysidia->input->post("type"), "class" => $mysidia->input->post("class"), "description" => $mysidia->input->post("description"), "eggimage" => $eggimage, "whenisavail" => $mysidia->input->post("cba"),
"alternates" => $mysidia->input->post("alternates"), "altoutlevel" => $mysidia->input->post("altoutlevel"), "altchance" => $mysidia->input->post("altchance"), "shop" => $mysidia->input->post("shop"), "cost" => $mysidia->input->post("cost")));



Replace this chunk of code with:

$mysidia->db->insert("adoptables", array("id" => NULL, "type" => $mysidia->input->post("type"), "class" => $mysidia->input->post("class"), "description" => $mysidia->input->post("description"), "eggimage" => $eggimage, "whenisavail" => $mysidia->input->post("cba"),
"alternates" => $mysidia->input->post("alternates"), "altoutlevel" => $mysidia->input->post("altoutlevel"), "altchance" => $mysidia->input->post("altchance"), "shop" => $mysidia->input->post("shop"), "cost" => $mysidia->input->post("cost"), "genderratio" => $mysidia->input->post("genderratio")));



You may now close this /admincp/adopt.php file. The very next thing to do is to open a file located at /classes/class_adoptable.php. First of all, find a list of properties for this class at:

protected $id;
protected $type;
protected $class;
protected $description;
protected $eggimage;
protected $whenisavail;
protected $alternates;
protected $altoutlevel;
protected $altchance;
protected $shop;
protected $cost;
protected $conditions;
protected $levels;



Replace by:

protected $id;
protected $type;
protected $class;
protected $description;
protected $eggimage;
protected $whenisavail;
protected $alternates;
protected $altoutlevel;
protected $altchance;
protected $shop;
protected $cost;
protected $genderratio;
protected $conditions;
protected $levels;


Perfect, we only have one last thing to do before this is all completed. Find the gender determination code at:

public function getGender(){
$genders = array('f', 'm');
$rand = rand(0,1);
return $genders[$rand];
}


Replace by:

public function getGenderRatio(){
return $this->genderratio;
}

public function getGender(){
$genderNumber = rand(0, 99);
if($genderNumber < $this->genderratio) $gender = "f";
else $gender = "m";
return $gender;
}


This is a reusable method, which means that both adopt.php and breeding.php can make use of it without writing the same block of code twice. Another reason why OOP pwns.


So this marks the end of manual installation process, its a lot simpler than last time isnt it? Anyway I hope you enjoy the Mods I am making for the script, I've decided to work on a few more new plugins for the script in the next few days. Lemme know if you have any suggestions to make, please do lemme know.

SilverDragonTears
05-07-2013, 10:39 PM
When I run it I get a blank screen.

Hall of Famer
05-07-2013, 11:06 PM
Blank page? Well there is a syntax error somewhere in your script then. Did you download the files I attached, or did the manual installation?

SilverDragonTears
05-08-2013, 12:49 PM
I downloaded the files.

Alaric
06-02-2013, 03:11 AM
Is this correct?

http://oi40.tinypic.com/2q9c2ep.jpg

Tequila
06-14-2013, 09:54 AM
I just installed this on a test site (theory site) and got this when I created an adoptable for it:
Fatal error: Uncaught exception 'Exception' with message 'Database error 1054 - Unknown column 'genderratio' in 'field list'' in /home/felinefl/public_html/classes/class_database.php:161 Stack trace: #0 /home/felinefl/public_html/classes/class_database.php(54): Database->_query('adoptables', Array, 'insert') #1 /home/felinefl/public_html/admincp/adopt.php(65): Database->insert('adoptables', Array) #2 /home/felinefl/public_html/admincp/index.php(71): ACPAdoptController->add() #3 /home/felinefl/public_html/admincp/index.php(125): AdminCP->handleRequest() #4 /home/felinefl/public_html/admincp/index.php(135): AdminCP::main() #5 {main} thrown in /home/felinefl/public_html/classes/class_database.php on line 161

Hall of Famer
06-16-2013, 12:06 PM
Oh yeah Tequila my dear, you forgot to add a database column into your table prefix.adoptables. XD

Tequila
06-16-2013, 03:00 PM
*smacks forehead* ... :el:

Edit I typed the column name wrong.... ╯.╰

Hall of Famer
06-17-2013, 02:22 AM
Oh I see, so thats the problem. XD

Twinkle And Kessie
08-22-2013, 03:52 AM
Either "table prefex.adoptables" is really hard to find, or was deleted completely from my system some how. What is a Table Prefix supposed to be anyway!? The instructions are very unclear and vague, there's no specifics that help newbies like me learn what exactly we're doing. I'll have to manually learn php just to figure out what every little insignificant thing means.

I did exactly as it said step for step, and when I try to create a new adoptable or edit one of the ones I have already, I get a blank white screen. There's not even an Error Message, just a blank screen.

Wait, lemme figure this out on my own, I think I got it now.

No... I redid everything, and it still doesn't work, it's still a blank white screen. This is frustrating. :P

Hall of Famer
08-22-2013, 06:24 AM
Well there is definitely no 'prefix.adoptables' in your database unless your table prefix is 'prefix'. Replace 'prefix' by whatever the table prefix is for your site, and it should work for you. For my demo site the prefix is 'adopts' or sometimes 'mys', yours may be completely different.

katsunya
01-19-2014, 01:17 AM
Does this code work for v1.3.4, too? o 3o

Edit: Or is there a code in the works for this to work in v1.3.4?

Hall of Famer
01-19-2014, 04:02 PM
It does not work with Mys v1.3.4, but I can post a solution if anyone is interested. The reason why I havent updated my mods was that the users who used to follow my plugins are no longer requesting old mods update or new mods being made. After all, whether or not will I make a mod/plugin is mostly a matter of demand. When there is no demand, I see no need to make new mods but rather work on the core script instead.

Send me a PM if you want an updated version, I may post a new thread dedicated to Mys v1.3.4's gender ratio mod if there is more than one user who asks.

kristhasirah
01-20-2014, 09:16 AM
i was going to ask ^^ but i found the solution, and so far is working. At least i don't have any problems. I always try to find a solution myself before asking for help.

So this is what i did to make the mod work with the new script: instead of editing 2 files, I had to edit 3 files:
/admincp/view/adoptview.php (You find the $adoptform code.)
/admincp/adopt.php (where you find the: sql insertion.)
And the:
/classes/class_adoptable.php (which you just follow the instructions posted by HoF ^^ that's all you need to do.)

That's what i did. not sure if is the correct solution, but is working.

Hall of Famer
01-21-2014, 03:52 PM
Yeah thats the correct steps to take Kristhasirah. If you get it to work, maybe you want to share it with other users? I wont urge you to do this though since mods/plugins are all voluntary work so its up for the users to decide whether to share or not(although there's one restriction, which I havent seen anyone reaching it yet).

katsunya
01-24-2014, 07:22 PM
Oh I see. The codes I tried using and editing kept giving me blank pages when I tried so thanks for posting your fix! I'll try it out that way.

GenStar1990
05-20-2019, 06:31 PM
Does it work with Mysidia 1.3.4?

kristhasirah
05-23-2019, 03:34 PM
it works you just make sure you have inserted the correct info to your table prefix.adoptables.: http://www.mysidiaadoptables.com/forum/showpost.php?p=26357&postcount=1
and how it shoud look: http://www.mysidiaadoptables.com/forum/showpost.php?p=27040&postcount=5
if you have a new install here is the page of the mod for the Mys v1.3.4: http://www.mysidiaadoptables.com/forum/showpost.php?p=28815&postcount=1
that have all the files needed for a fresh install.
the rest of the code you need to separate it in parts:
in /admincp/view/adoptview.php find:

$adoptForm->add($basicInfo);
$adoptForm->add($shopSettings);
$adoptForm->add($conditions);
$adoptForm->add($miscellaneous);
$adoptForm->add(new Button("Create this Adoptable", "submit", "submit"));
$document->add($adoptForm);
after that paste:

$miscellaneous->add(new Comment("The Gender Ratio of your adoptable is ", FALSE));
$miscellaneous->add(new TextField("genderratio", 50));
then in /admincp/adopt.php find:

$mysidia->db->insert("adoptables", array("id" => NULL, "type" => $mysidia->input->post("type"), "class" => $mysidia->input->post("class"), "description" => $mysidia->input->post("description"), "eggimage" => $eggimage, "whenisavail" => $mysidia->input->post("cba"),
"alternates" => $mysidia->input->post("alternates"), "altoutlevel" => $mysidia->input->post("altoutlevel"), "altchance" => $mysidia->input->post("altchance"), "shop" => $mysidia->input->post("shop"), "cost" => $mysidia->input->post("cost")));
and replace with this one:

$mysidia->db->insert("adoptables", array("id" => NULL, "type" => $mysidia->input->post("type"), "class" => $mysidia->input->post("class"), "description" => $mysidia->input->post("description"), "eggimage" => $eggimage, "whenisavail" => $mysidia->input->post("cba"),
"alternates" => $mysidia->input->post("alternates"), "altoutlevel" => $mysidia->input->post("altoutlevel"), "altchance" => $mysidia->input->post("altchance"), "shop" => $mysidia->input->post("shop"), "cost" => $mysidia->input->post("cost"), "genderratio" => $mysidia->input->post("genderratio")));
if you have already edited that part of the code and added some other things then you just need to add this part to the code you have:

, "genderratio" => $mysidia->input->post("genderratio")
then in classes/class_adoptable.php find this:

protected $id;
protected $type;
protected $class;
protected $description;
protected $eggimage;
protected $whenisavail;
protected $alternates;
protected $altoutlevel;
protected $altchance;
protected $shop;
protected $cost;
protected $conditions;
protected $levels;
and add this:
protected $genderratio;

then search for this code:

public function getGender(){
$genders = array('f', 'm');
$rand = rand(0,1);
return $genders[$rand];
}
and replace with:

public function getGenderRatio(){
return $this->genderratio;
}

public function getGender(){
$genderNumber = rand(0, 99);
if($genderNumber < $this->genderratio) $gender = "f";
else $gender = "m";
return $gender;
}

save the file, now go to classes/class_stockadopt.php
after
public $owner;
add:
public $genderratio;
then search for:

public function append($owner = ""){
// This method adds items to user inventory

$mysidia = Registry::get("mysidia");
$this->owner = (!empty($owner))?$owner:$this->owner;
$alts = $this->getaltstatus(0);
$code = codegen(10, 0);
$genders = array('f', 'm');
replace $genders = array('f','m'); with:
$genderNumber = rand(0, 99);
if($genderNumber < $this->genderratio) $gender = "f";
else $gender = "m";

then in

$mysidia->db->insert("owned_adoptables", array("aid" => NULL, "type" => $this->type, "name" => $this->type, "owner" => $this->owner,
"currentlevel" => 0, "totalclicks" => 0, "code" => $code, "imageurl" => "", "usealternates" => $alts,
"tradestatus" => "fortrade", "isfrozen" => "no", "gender" => $genders[$rand],
"offsprings" => 0, "lastbred" => 0));
replace : "gender" => $genders[$rand], with:
"gender" => $gender

and you should have a working mod =)