Loot Crate System Optimized

Queso

echo 'Web Developer';
Nov 29, 2016
233
72
Hello DevBest, today I will be re-releasing a small addon which I made for my old hotel a couple months ago, in this version, you can select which items you want to be in the loot crates via the database and also it has logs for you to check.
This script is basically just a system that allows a player to buy a crate which can contain items that have the value set to 1 in the database.
Add this where ever you want the crates to be bought at:
PHP:
<center>
                        <b>Loot Crates</b> are boxes that you can purchase, and they can contain various items, such as rares, diamonds, and even badges!<br>
                        Loot crates cost <b>50</b> diamonds!<br>
                        <img src="{url}/assets/images/loot_crate.png"><br>
                        <?php
    $lootcrate = mysql_fetch_assoc(mysql_query("SELECT `vip_points`,`lootcrates_bought` FROM `users` WHERE `id` = '".$_SESSION['user']['id']."'"));
    ?>
                                <?php
                                $userstuff = mysql_query("SELECT * FROM `users` WHERE id='".$_SESSION['user']['id']."'");
                                $crate = mysql_query("SELECT id FROM furniture WHERE loot_crate = '1' ORDER BY RAND() LIMIT 1");
                                while ($selectcrate= mysql_fetch_array($crate)){
                                while ($onlineuser= mysql_fetch_array($userstuff)){
                                if ($onlineuser['online'] == 0){
                                if(isset($_POST['lootCrate'])){
                                    if($lootcrate['vip_points'] >= 50){
                                        $iDs = rand(0,9594553674);
                                        mysql_query("INSERT INTO `crate_logs` (`username`, `userid`, `item_id`) VALUES ('".$_SESSION['user']['username']."', '".$_SESSION['user']['id']."', '".$selectcrate['id']."')");
                                        mysql_query("INSERT INTO `items` (`id`, `user_id`, `base_item`, `extra_data`) VALUES ('".$iDs."', '".$_SESSION['user']['id']."', '920020', 'quesoThank you for purchasing a loot crate!1154337249')");
                                            mysql_query("UPDATE users SET `vip_points` = `vip_points` - 50 WHERE username = '".$_SESSION['user']['username']."' LIMIT 1");
                                            mysql_query("INSERT INTO `user_presents` (`item_id`, `base_id`, `extra_data`) VALUES ('".$iDs."', '".$selectcrate['id']."', '0')");
                                            mysql_query("UPDATE `users` SET `lootcrates_bought` = `lootcrates_bought` +1 WHERE username = '".$_SESSION['user']['username']."' LIMIT 1");
                                            echo "You bought a <b>loot crate</b>, check your inventory to open your crate!<br>";
                                            }
                                        else{
                                            echo "You do not have 50 diamonds to redeem for a Loot Crate!<br>";
                                        }
                                }
                                }
                                else{
                                echo "You must log out of the client!<br>";
                                }
                                }
                                }
                                ?><br>
                                <form method="post">
                                <input type="submit" name="lootCrate" value="Buy a Loot Crate">
                                </form>
                                </center>
Next, run these queries:
Code:
CREATE TABLE `crate_logs` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(255) DEFAULT 'None',
  `userid` int(11) DEFAULT 0,
  `item_id` int(11) DEFAULT 0,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=latin1;
Code:
ALTER TABLE furniture ADD loot_crate  enum('1','0') DEFAULT '0';
ALTER TABLE users ADD lootcrates_bought INT DEFAULT '0';
Lastly, to make this work, you need to send yourself a gift, then go into your 'items' table and take the extra_data from the present, and change:
PHP:
quesoThank you for purchasing a loot crate!1154337249
to whatever was in your extra data is, and then done, loot crates should then work. To add items to lootcrates, go into the furniture table, and set the column 'loot_crate' to 1.
 
Last edited by a moderator:

Yoloboy

New Member
Dec 28, 2016
1
0
Hi, can you help me?
First of all thanks for this addon!
Second when i buy a loot i get a gift in my inventory but when i open it the furniture doesn't appear in my inventory.
 

Holyfuture

New Member
Jan 29, 2015
5
0
Nice addon, but please don't use it unless you have some knowledge about web development. He's using mysql (deprecated and no longer supported), no security and you can't maintaine the code.
 

Users who are viewing this thread

Top