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
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.
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
This is the main code for the lootbox. Now you can create your lootbox items! Here's an example:
The important points are:
When it's all done, you can use the item like so.
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!
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


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.


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:

The important points are:
- item is set to lootbox (obviously)
- item is set to consumable (obviously)
- 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.


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!