Mys 1.3.6 Item Rarities + AdminCP Mod

Forum
Last Post
Threads / Messages

clay

Member
Member
Joined
May 2, 2023
Messages
8
Points
3
Age
27
Mysidian Dollar
158
This script will install item rarities for your item database so that you might easier sort and grant them via PHP. It does not display item rarities by default, you'll have to scroll to the bottom of this post to find examples of how to utilize this script so players actually know item rarities in-game.

By default, items are marked as "Common" (including items pre-existing in your database before you install this script), and the default rarity tier list is Super Common < Very Common < Common < Uncommon < Rare < Super Rare < Ultra Rare < Legendary < Collectible. You can change the names of these tiers while installing the mod to your liking, though. "Collectible" is meant to be reserved for items that are only released once.



First, open model\domainmodel\item.php and add this after protected $chance.
Code:
    protected $rarity;

Then add this line of code after the getChance() function.
PHP:
    public function getRarity(){
        return $this->rarity;
    }

Open your database, edit the structure, and add this rarity column to your (prefix)_adopts_items table.
sdfdfs.png

Open controller\admincp\itemcontroller.php and paste this after "chance" => (int)$mysidia->input->post("chance"), . There's two instances in this file, once in add() and once in edit().
PHP:
"rarity" => $mysidia->input->post("rarity"),

Open view\admincp\itemview.php and change $itemTable->buildHeaders("Image", "Item", "Description", "Function", "Edit", "Delete"); to the following code.
PHP:
$itemTable->buildHeaders("Image", "Item", "Description", "Rarity", "Function", "Edit", "Delete");
Now, after $cells->add(new TCell($item->getDescription())); add this:
PHP:
           $cells->add(new TCell($item->getRarity()));
Now after $itemForm->add(new Comment($this->lang->price_explain)); you're gonna add this. There are two instances of this again, once in add() and once in edit().
PHP:
        $itemForm->add(new Comment("Rarity: ", FALSE));
        $itemForm->buildDropdownList("rarity", "RarityList");
This is so you can add rarities when you add/edit a new item, but we haven't built the DropdownList yet. We'll do that in the next step...

Open service\helper\formhelper.php add this function, put it after buildItemShopList($name) and as it states, you can edit what you want your item rarities to be named here, along with the default selected rarity.
PHP:
    /***item rarities
    edit what you want your rarity list to be named here
    ***/
    public function buildRarityList($name){
        $rarityList = new DropdownList($name);
        $stmt = ["Super Common", "Very Common", "Common", "Uncommon", "Rare", "Super Rare", "Ultra Rare", "Legendary", "Collectible"];
        $rarityList->add(new Option("No Rarity Selected", "none"));
        foreach ($stmt as $field) {
             $option = new Option($field, $field);
            if($option->getValue() == "Common") $option->setSelected(TRUE); // default rarity
            $rarityList->add($option);
        }
        return $rarityList;
    }



Now, when you upload items using the AdminCP, you should see a dropdown with rarities to select from, "Common" (or whichever you added in the last step) being the default.
sdfdsfdsf.png



To show an item's rarity, use $item->getRarity(). This can be added to the inventory, the shop browse page, and any other places where items are shown.
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

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

Latest Threads

Latest Posts

Top