Mys 1.3.6 Item Drop Mod

Forum
Last Post
Threads / Messages

Hall of Famer

Administrator
Staff member
Administrator
Joined
Dec 15, 2008
Messages
4,535
Points
48
Location
United States
Mysidian Dollar
213,993
Another Mod I decided to revise for Mys v1.3.6 is this Item Drop Mod, which should be perfectly compatible with the new version. With this plugin, users have a chance to get a specific item by clicking on a certain species of adoptable. It may help with users exchange clicks, but do not abuse this feature so users get way too many important items.

You can assign either one or multiple items to an adoptables species, which will drop items based on their item drop-rate. For instance, if an adoptable has drop-rate of 30, your user will have 30% chance to get an item by clicking on this pet. If you assign two or three items to this species, each of them will have 15% or 10% chance to come out. Unfortunately there's no way to 'discriminate' among items for a given adoptable, but I will consider making one in future.

Assuming you have a fresh installation of Mys v1.3.6, you can simply download the .zip files I upload myself, then go to /install/genderratio.php to execute the file to install the Mod. A download link is provided below:


If your site is heavily customized or you have other mods installed(ie. my Gender Ratio Mod), you'd have to install manually. To begin with, go to PhpMyAdmin and insert two columns `dropitems`(type varchar(100)) and `droprate`(type INT) into your table `prefix.adoptables`. 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 column dropitems VARCHAR(100) DEFAULT NULL AFTER cost
ALTER TABLE adopts_adoptables ADD column droprate INT DEFAULT 0 AFTER dropitems

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 ('Item Drop Mod v1.3.6', 'https://forums.mysidiaadoptables.com', 'item_drop', 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 $shop;
    protected $cost;

Add two more properties below these lines:

PHP:
    protected $dropitems;
    protected $droprate;

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)];
    }

And add some chunk of code above this method:

PHP:
    public function getDropItems(){
        return $this->dropitems;
    }
    
    public function getDropRate(){
        return $this->droprate;
    }
    
    public function canDropItem(){
        return ($this->dropitems && $this->droprate > 0);
    }
    
    public function dropItem(){
        $mysidia = Registry::get("mysidia");
        $rand = mt_rand(0, 99);
        $ownedItem = NULL;
        if($rand < $this->droprate){
            $items = explode(",", $this->dropitems);
            $num = count($items);
            if(count($items) == 1) $item = $items[0];
            else{
                $itemrand = mt_rand(0, $num - 1);
                $item = $items[$itemrand];
            }
            $ownedItem = new OwnedItem($item, $mysidia->user->getID());
            $ownedItem->add(1, $mysidia->user->getID());
        }
        return $ownedItem;
    }

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()):

Code:
        $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 fields `dropitems` and `droprate` 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"), "dropitems" => $mysidia->input->post("dropitems"), "droprate" => (int)$mysidia->input->post("droprate")]);

Then we need to modify the adoptable creation form in ACP to add two textfields for `dropitems` and `droprate`. Simply go to /view/admincp/adoptview.php and locate these lines of code(starting at line 108 for unmodified code, inside method AdoptView::add()):

Code:
        $adoptForm->add($basicInfo);
        $adoptForm->add($shopSettings);
        $adoptForm->add($conditions);
        $adoptForm->add($miscellaneous);

And add the following code below:

PHP:
        $itemdrop = new FieldSetBuilder("Item Drop Settings");
        $itemdrop->add(new Comment("Items dropped by clicking this adopt: (must be item IDs. If multiple items are possible, separate them by comma)"));
        $itemdrop->add(new TextField("dropitems"));
        $itemdrop->add(new Comment("Items dropped rate: (must be somewhere between 0 and 100"));
        $itemdrop->add(new TextField("droprate"));
        $adoptForm->add($itemdrop);

We are now done with ACP, the adoptables can be created with drop items and drop rate. Wonderful, but the work is not done yet. We still need to hijack the adoptables click/levelup action to allow items to be dropped, for this we will need to edit two more files. First, go to /controller/main/levelupcontroller.php and find these lines of code(starting at line 64 for unmodified code, inside method LevelupController::click($aid)):

PHP:
            if($mysidia->user instanceof Member){
                $reward = mt_rand($this->settings->reward[0], $this->settings->reward[1]);
                $mysidia->user->changeMoney($reward);           
                $this->setField("reward", new Integer($reward));   
            }

Replace by:

PHP:
            if($mysidia->user instanceof Member){
                $plugins = Registry::get("plugins");
                if($plugins->isEnabled("item_drop") && $this->adopt->canDropItem()){
                    $itemdrop = $this->adopt->dropItem();
                    if($itemdrop) $this->setField("itemdrop", $itemdrop);
                }
                
                $reward = mt_rand($this->settings->reward[0], $this->settings->reward[1]);
                $mysidia->user->changeMoney($reward);           
                $this->setField("reward", new Integer($reward));   
            }

This will allow an item to be dropped via clicking an adoptable, this item will appear automatically in the user's inventory(only works for members, guests will not get items of course). We are almost done, but it's better if we can display this information to the user. So go to /view/main/levelupview.php and locate these lines(starting at line 32 for unmodified code, inside method LevelupView::click()):

PHP:
            $summary->add(new Comment("<br> You have earned {$reward} {$mysidia->settings->cost} for leveling up this adoptable. "));
            $summary->add(new Comment("You now have {$mysidia->user->getMoney()} {$mysidia->settings->cost}"));

Add the following two lines below:

PHP:
            $itemdrop = $this->getField("itemdrop");
            if($itemdrop) $summary->add(new Comment("Congratulations, you have acquired an item {$itemdrop->getItemName()} by clicking this adoptable!"));

Well done, it is not hard at all isnt it? Congratulations, you have now added an interesting tiny little feature to your site. Hopefully your members will love it, although you need to be careful with the `droprate` of each adoptable. To low `droprate` frustrates your members, while too high `droprate` makes this entire thing pointless. Good luck.
 

Constellraetion

Member
Member
Joined
May 6, 2022
Messages
20
Points
3
Mysidian Dollar
208
wouldn't it make more sense for, instead of the drop rate for items being assigned per individual type of adopt, from the adopt page (i'm foreseeing a huge pain when there are a lot of different kinds of adopts present) for the drop rate to be assigned per item? and then possibly with a value to attribute it to an adopt instead?
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,187
Messages
32,473
Members
1,553
Latest member
Polymori
BETA

Latest Threads

Top