Mys 1.3.6 Gender Ratio Mod

Forum
Last Post
Threads / Messages

Hall of Famer

Administrator
Staff member
Administrator
Joined
Dec 15, 2008
Messages
4,563
Points
48
Location
United States
Mysidian Dollar
214,216
With the release of Mys v1.3.6, old mods/addons are no longer working with the new version. For this reason, I've decided to update my own mods/addons for compatibility of the latest release. The first one is this Gender ratio mod, which allows site admins to set unbalanced gender for new adoptables(and if you wish, some adoptables can be male-only or female-only). I've included a link to the Mysidia Resource Manager that you can download the zip file and upload everything there to your site via FTP. Make sure to overwrite existing files, and then enter the directory /install and execute the file /install/genderratio.php so that the column genderratio will be inserted successfully into the database(as well as a record inserted into table prefix_acp_hooks).

The download link in Mysidia Resource Manager can be accessed from this url below:



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. To begin with, go to PhpMyAdmin and insert the column `genderratio` into your table `prefix.adoptables`. Its type is INT, default value should be 50. You may also use the query tab to execute this following query manually(assuming default table prefix, changes adopts_ to whatever it is for you incase it is different):

SQL:
ALTER TABLE adopts_adoptables ADD genderratio INT DEFAULT 50 AFTER cost

Also insert a record into the table prefix_acp_hooks, this will allow the plugin to be enabled/disabled via ACP. You may execute this query from PhpMyAdmin:

SQL:
INSERT INTO adopts_acp_hooks (`linktext`, `linkurl`, `pluginname`, `pluginstatus`) VALUES ('Gender Ratio Mod v1.3.6', 'https://forums.mysidiaadoptables.com', 'gender_ratio', 1)

After the SQL part is done, go to your script file /model/domainmodel/adoptables.php, locate the list of properties:

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

Add a new property $genderratio below the code:

PHP:
protected $genderratio;

Then find the following code(at line 128 for unmodified file, method Adoptables::getGender()):

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

replace by:

PHP:
    public function getGenderRatio(){
        return $this->genderratio;
    }
    
    public function getGender(){
        $plugins = Registry::get("plugins");
        if($plugins->isEnabled("gender_ratio")){
            $genderNumber = rand(0, 99);
            return ($genderNumber < $this->genderratio) ? "f" : "m";               
        }
        else{
            $genders = ["f", "m"];
            return $genders[rand(0,1)];
        }
    }

Now we need to add some code to the ACP. Go to /controller/admincp/adoptcontroller.php and find the line that inserts adoptables record to database(line 58 for unmodified code, inside method AdoptController::add()):

PHP:
        $mysidia->db->insert("adoptables", ["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" => (int)$mysidia->input->post("altoutlevel"), "shop" => (int)$mysidia->input->post("shop"), "cost" => (int)$mysidia->input->post("cost")]);

And replace the above chunk of code by the new code below, which allows field gender ratio to be saved to database:

PHP:
        $mysidia->db->insert("adoptables", ["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" => (int)$mysidia->input->post("altoutlevel"), "shop" => (int)$mysidia->input->post("shop"), "cost" => (int)$mysidia->input->post("cost"), "genderratio" => (int)$mysidia->input->post("genderratio")]);

Finally, we still need to modify the adoptable creation form in ACP to add a textfield for gender ratio. Simply go to /view/admincp/adoptview.php and locate these lines of code(starting at line 108 for unmodified code, inside method AdoptView::add()):

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

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

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

So this marks the end of manual installation process, hopefully its not much more complicated than last time(just the query for acp_hooks is new addition, as I've decided that admins can enable/disable this mod in ACP)? 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.
 
i love all the little mods i can add as i go, just a question, if you are trying to change the ratio do you need to define it? Right now it just defults "50" which I assume is 50/50

if I want it to the 25/75, (F/M) do I fill it in "25, 75"

or is the default aimed at just one (like a male) so I'd just put in the 75?


Found an old thread that said it's female chance, so I tested it, and it looks like 0 = all male, 100= all female, so if I want a 25/75 (M/F) I'd do 25, and so on. Just in case anyone wonders
 
Last edited:

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,267
Messages
33,048
Members
1,602
Latest member
BerrieMilk
BETA

Latest Threads

Latest Posts

Top