Loot Crate System

Status
Not open for further replies.

Queso

echo 'Web Developer';
Nov 29, 2016
232
72
Hello DevBest, today I will be releasing a small addon which I made for my old hotel a couple months ago.
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.
Code:
<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="PLACEIMAGEHERE"><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', 'JoeThank you for purchasing a loot crate, double click to open!643246337249')");
                                            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>
</ul>
Basically just add the above code to the page you want the script at.
Finally, run this query.
Code:
ALTER TABLE furniture ADD loot_crate  enum('1','0')DEFAULT '0';
P.S I do believe if you plan to use this script, the way I have it is it sends a gift to the user from your user, so you may have to send a gift to yourself and copy the extra_data and replace mine with yours so this script works properly, if you do need help, let me know.
Done.
If you have any questions or need help, PM me, and I can try to help you. Don't really care if you think this poorly coded or anything, I'm not a professional web developer, nor do I really know of ways this can be sql injected, so yeah. This was just something I wanted to have on my hotel.
 

Rebel

Spilling the tea, can't you read?🍵
Dec 24, 2015
186
161
It’s a decent release. Nothing special, the reason I say this is because if you’re a hotel that focuses on your economy this will give it aids and rape it. It’s not coded good in my opinion, it allows users to get rares from the staff catalogue which isn’t good. It doesn’t have coins, diamonds, rares filtered out or what ones they can get or don’t get you should’ve coded it so they can pick what items they wanna put in the loot crates. Like maybe a table in the database for it! Would’ve been a good thing to do instead of being lazy and making it so it picks a random id which could be an unreleased rare. But good release for noobs and hotels that don’t care about their economy.[emoji817]


Sent from my iPhone using Tapatalk
 

LaPatron

Smile, because it confuses people.
Nov 23, 2017
72
155
It’s a decent release. Nothing special, the reason I say this is because if you’re a hotel that focuses on your economy this will give it aids and rape it. It’s not coded good in my opinion, it allows users to get rares from the staff catalogue which isn’t good. It doesn’t have coins, diamonds, rares filtered out or what ones they can get or don’t get you should’ve coded it so they can pick what items they wanna put in the loot crates. Like maybe a table in the database for it! Would’ve been a good thing to do instead of being lazy and making it so it picks a random id which could be an unreleased rare. But good release for noobs and hotels that don’t care about their economy.[emoji817]


Sent from my iPhone using Tapatalk
 

Queso

echo 'Web Developer';
Nov 29, 2016
232
72
@Rebel Thanks for your opinion, but what do you mean by not filtered out? The items in the loot crate are selected from the furniture table when the item is enabled to be selected. So if you don't have an item enabled to be collected, it will not be in the crates? Your crate system which is the old one I coded is the one you're speaking about, which is the one that just selects items from a random ID in the furniture table. This is the one I re-did at Gubbo because of the matter of it selecting from staff catalog. Hence this line of SQL
Code:
$crate = mysql_query("SELECT id FROM furniture WHERE loot_crate = '1' ORDER BY RAND() LIMIT 1");
You can ask @Dustin for clarification. Thanks for the input though. @Sab, maybe the code is not added correctly, PM me, I can help you personally via Teamviewer.
 
Last edited:

Rebel

Spilling the tea, can't you read?🍵
Dec 24, 2015
186
161
@Rebel Thanks for your opinion, but what do you mean by not filtered out? The items in the loot crate are selected from the furniture table when the item is enabled to be selected. So if you don't have an item enabled to be collected, it will not be in the crates? Your crate system which is the old one I coded is the one you're speaking about, which is the one that just selects items from a random ID in the furniture table. This is the one I re-did at Gubbo because of the matter of it selecting from staff catalog. Hence this line of SQL
Code:
$crate = mysql_query("SELECT id FROM furniture WHERE loot_crate = '1' ORDER BY RAND() LIMIT 1");
You can ask @Dustin for clarification. Thanks for the input though. @Sab, maybe the code is not added correctly, PM me, I can help you personally via Teamviewer.
I don’t use the crates and didn’t look through the new code yet I will when I’m home tho
 

LaPatron

Smile, because it confuses people.
Nov 23, 2017
72
155
@Rebel This is the one I re-did at Gubbo because of the matter of it selecting from staff catalog ... You can ask @Dustin for clarification.

Actually, sir have a look at this:



the PK values aren't evenly distributed, auto_increment numbers usually are, but looking at databases of the the furni table there are large gaps in the ID field, which make the script really slow.

Old but related on how to overcome this:

Also no need to do this:

PHP:
<?php
    $lootcrate = mysql_fetch_assoc(mysql_query("SELECT `vip_points`,`lootcrates_bought` FROM `users` WHERE `id` = '".$_SESSION['user']['id']."'"));
    ?>
                                <?php

WHAT???? Why end it if you're gonna carry on

On top of this:
PHP:
$userstuff = mysql_query("SELECT * FROM `users` WHERE id='".$_SESSION['user']['id']."'");

while ($onlineuser= mysql_fetch_array($userstuff)){
                                if ($onlineuser['online'] == 0){

Don't really need to grab 'ALL' data when all you need to know is if the user online.

Plus...
your script adds a new field to the users table, which is unnecessary when you're already logging the crates on another table, duplicating data is not a wise move.

So our version is pretty much completely different from yours, but credits to you for the idea.
 
Last edited:

Xaoss

New Member
Jul 4, 2017
16
6
@queso Hello, could you give me a quick hand with this when you get a chance I've been trying to get this working for past two days I keep coming very close, could you show me exactly where to replace the Extra_data, thanks in advance!
 

treebeard

Member
Jan 16, 2018
317
173
I think I'm going to take this and reowork it to pull possible prizes from a table in db and weight certain entries to have more likelihood of being pulled. I'll prob start on it next week or two and post here
 

Kristo

Website & Software Developer
Feb 5, 2015
269
69
I think I'm going to take this and reowork it to pull possible prizes from a table in db and weight certain entries to have more likelihood of being pulled. I'll prob start on it next week or two and post here

That would be interesting to see. I would look at using that if it was done. Sounds pretty good
 

Kristo

Website & Software Developer
Feb 5, 2015
269
69
I should start work on it next week if all goes well. I've been trying to think of an option for extra goodies on my hotel.
If you happen to do it and get it working give me a shout as it's something I'd like to implement on my hotel :)
 

iChrisx

New Member
Feb 9, 2015
15
4
Can someone help me i got it in the site and everything works but i can't open the gift in the client. Im using plusemu.
 
Last edited:

Queso

echo 'Web Developer';
Nov 29, 2016
232
72
To anyone not receiving the gift in the client, it is caused by the query, you need to change the insert query. Basically, send yourself a gift, then check the items table for the gift box, copy the extra data and replace it with the current data. Mine looks like this.
PHP:
mysql_query("INSERT INTO `items` (`id`, `user_id`, `base_item`, `extra_data`) VALUES ('".$iDs."', '".$_SESSION['user']['id']."', '920020', 'JoeThank you for purchasing a loot crate, double click to open!643246337249')");
Replace this, with the extra_data from you own gift in the items table
Code:
JoeThank you for purchasing a loot crate, double click to open!643246337249
If you need further help, PM me and I will try to make time to help.
 
Status
Not open for further replies.

Users who are viewing this thread

Top