Mys 1.3.6 Lootbox Mod

Forum
Last Post
Threads / Messages

lemoncandy

Member
Member
Joined
Apr 7, 2022
Messages
3
Points
3
Mysidian Dollar
46
This mod adds a "lootbox" item type that, when used, will randomly give you an item (from a specific list)

it's pretty simple and not really customizable - each lootbox has exactly 10 slots for items, and an empty slot will give no item. If you want fewer than 10, you'll have to put some items in twice to fill the space. The editing is done straight in the database instead of an admincp page, but it's pretty straightforward so hopefully you shouldn't have much issue

pic1.png
pic2.png

first step is creating a new database table called (siteprefix)_lootbox, and set it up so it has 11 entries like so. lootboxID is the unique identifier of that specific lootbox, while item1-10 dictate the item id of the potential prizes. To find the item's id, check the database table (siteprefix)_items.

pic3.png
pic4.png

the second step is going to (siteprefix)_items_functions and adding a new entry. the ifid needs to be 1 higher than the previous, on a fresh install it'll be 15 but if you have other mods or added new item function it might be higher. Other than that, the function is 'Lootbox' and the intent is 'Adoptable' like so. I just put whatever in the description lol

now look for (site)/model/domainmodel/itemfunction.php - after the other item functions, but before the } at the end of the file, insert this code

protected function applyLootbox(OwnedItem $item, OwnedAdoptable $adopt){
$mysidia = Registry::get("mysidia");
$gachaid = $item->getValue();
$result = rand(1,10);
$itemprize = $mysidia->db->select("lootbox", array("item{$result}"), "lootboxID ='{$gachaid}'")->fetchColumn();

if ($itemprize == 0) {
$note = "{$adopt->getName()} cracked open the {$item->getItemname()}, but there was nothing inside...";
}
else {
$prizename = $mysidia->db->select("items", array("itemname"), "id ='{$itemprize}'")->fetchColumn();
$ownedItem = new OwnedItem($itemprize, $mysidia->user->getID());
$ownedItem->add(1, $mysidia->user->getID());
$note = "{$adopt->getName()} cracked open the {$item->getItemname()} and found {$prizename} inside!";
}

return $note;
}

This is the main code for the lootbox. Now you can create your lootbox items! Here's an example:

pic5.png

The important points are:
  1. item is set to lootbox (obviously)
  2. item is set to consumable (obviously)
  3. item's unique value will correspond to the lootboxID in the database. Since the value is '1', when you open the lootbox, it will randomly give one of the items listed under the lootboxID '1'

When it's all done, you can use the item like so.

pic7.png pic8.png

and that's it! pretty simple, but adds an extra layer to getting item rewards on your site. if you have any trouble feel free to comment and I'll help as best I can!
 

Hall of Famer

Administrator
Staff member
Administrator
Joined
Dec 15, 2008
Messages
4,536
Points
48
Location
United States
Mysidian Dollar
214,004
Looks nice, seems that you are getting a hang of creating mods for Mysidia Adoptables, I am sure it will help a lot more people. Maybe one day I should post a tutorial on how to do this step by step.
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,191
Messages
32,492
Members
1,567
Latest member
Enigmas
BETA

Latest Threads

Top