Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Server Development
Habbo Retros
Habbo Releases
CMS Releases
[RevCMS] LIMITED furniture sales in CMS [Phoenix]
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="thewicard" data-source="post: 191850" data-attributes="member: 8814"><p>So, I used a few hours figuring this out xP</p><p>Hope you enjoy. Sorry about insanely long code.</p><p>Price is now configured in DB.</p><p> </p><p>What does this code do?</p><p>It allows you to sell furniture in limited quantities.</p><p>Is it secure?</p><p>It has double money-in-pocket check <strong>(1 in whatever page it's placed in AND 1 when delivering furniture)</strong></p><p>It has double furniture-not-sold-out check <strong>(1 in whatever page it's placed in AND 1 when delivering furniture)</strong></p><p>Will not work to refresh page to get another furniture unless there are still available AND you have money for it.</p><p>Added POST Filter <strong>(Now only allow numeric posts)</strong> //Thanks to Leenster for telling me it was needed.</p><p> </p><p>First: Run this queue</p><p>[PHP]DROP TABLE IF EXISTS `rev_ltd`;</p><p>CREATE TABLE `rev_ltd` (</p><p> `furni_id` int(255) NOT NULL,</p><p> `furni_left` int(255) NOT NULL DEFAULT '100',</p><p> `furni_sold` int(255) NOT NULL DEFAULT '0',</p><p> `furni_price` int(255) NOT NULL DEFAULT '5000',</p><p> PRIMARY KEY (`furni_id`)</p><p>) ENGINE=MyISAM DEFAULT CHARSET=latin1;</p><p>INSERT INTO `rev_ltd` VALUES ('227', '15', '0', '5000');[/PHP]</p><p> </p><p>Second: Create a file in app/tpl/skins/YOURSKIN/ named buyltd.php</p><p>Place this content in the file and save:</p><p>[PHP]<?php</p><p>$ltd_id = preg_replace('/[^0-9]/', '', $_POST["ltd_id"]);</p><p>$user_id = $_SESSION['user']['id'];</p><p>$selectfromusers = mysql_query("SELECT * FROM users WHERE id = '".$user_id."'") or die(mysql_error());</p><p>while ($getmoney = mysql_fetch_array($selectfromusers))</p><p>$money_current = $getmoney['credits'];</p><p>$selectfromfurninum = mysql_query("SELECT * FROM rev_ltd WHERE furni_id = '".$ltd_id."'") or die(mysql_error());</p><p>while ($getfurninum = mysql_fetch_array($selectfromfurninum))</p><p>$furnileft = $getfurninum['furni_left'] and</p><p>$furnisold = $getfurninum['furni_sold'] and</p><p>$ltd_price = $getfurninum['furni_price'];</p><p>if($furnileft > '0')</p><p>{</p><p>if($money_current < $ltd_price)</p><p>{</p><p>echo "You don't have enough money for this item";</p><p>}</p><p>else</p><p>{</p><p>$newmoney = $money_current - $ltd_price;</p><p>mysql_query("UPDATE users SET credits='".$newmoney."' WHERE id='".$user_id."'") or die(mysql_error());</p><p>$newfurnileft = $furnileft - '1';</p><p>$newfurnisold = $furnisold + '1';</p><p>mysql_query("UPDATE rev_ltd SET furni_sold='".$newfurnisold."'") or die(mysql_error());</p><p>mysql_query("UPDATE rev_ltd SET furni_left='".$newfurnileft."'") or die(mysql_error());</p><p>$highestid = mysql_query("SELECT * from items ORDER BY id DESC LIMIT 1") or die(mysql_error());</p><p>while ($checknewid2 = mysql_fetch_array($highestid))</p><p>$newid2 = $checknewid2['id'];</p><p>$newid = $newid2 + '1';</p><p>mysql_query("INSERT INTO items (id, user_id, room_id, base_item, extra_data, x, y, z, rot, wall_pos) VALUES ('".$newid."','".$user_id."',0,'".$ltd_id."',0,0,0,0,0,0)") or die(mysql_error());</p><p>echo "Item bough successfully!";</p><p>}</p><p>}</p><p>else</p><p>{</p><p>echo "All of furniture is already sold, sorry";</p><p>}</p><p>?></p><p><meta http-equiv="refresh" content="1; URL=me">[/PHP]</p><p> </p><p>Third:</p><p>Goto whatever page you want this in, add this at the top:</p><p>[PHP]<?php</p><p>$user_id = $_SESSION['user']['id'];</p><p>$selectfromusers = mysql_query("SELECT * FROM users WHERE id = '".$user_id."'") or die(mysql_error());</p><p>while ($getmoney = mysql_fetch_array($selectfromusers))</p><p>$money_current = $getmoney['credits'];</p><p>?>[/PHP]</p><p> </p><p>Forth:</p><p>Add this wherever you want the output, this is made for Priv theme.</p><p>[PHP]<?php</p><p>//Furniconfiguration</p><p>$ltd_id = "227"; //furni_id in the database</p><p>$ltd_name = "Dragonegg"; //The name of your furni</p><p>$image_url = "http://habboxwiki.com/wiki/images/1/12/Black_Dino_Egg.png"; //Image URL (optional)</p><p> </p><p> </p><p>//Collects data from database</p><p>$selectfromltd = mysql_query("SELECT * FROM rev_ltd WHERE furni_id = '".$ltd_id."'") or die(mysql_error());</p><p>while ($getltd = mysql_fetch_array($selectfromltd))</p><p>$getltd_num = $getltd['furni_left'] and</p><p>$getltd_sold = $getltd['furni_sold'] and</p><p>$ltd_price = $getltd['furni_price'];</p><p>$getltd_total = $getltd_sold + $getltd_num;</p><p>$money_lack = $ltd_price - $money_current; ?></p><p> </p><p><!-- The part that you can see, may need to be changed to fit other theme (currently for Priv theme) --></p><p><div class="left page round"><ul> <?php</p><p>if($getltd_num == '0') {</p><p>$money_lack = $ltd_price - $money_current;</p><p>echo "This item is no longer available, sorry.";?></p><p><br><br><br><h3><?php echo "$ltd_name"?></h3><img src="<?php echo "$image_url" ?>" style="float: right"></p><p><br>Sold out.<br><br></p><p><?php }</p><p>else</p><p>{</p><p>if($money_current < $ltd_price)</p><p>{</p><p>echo "You need $money_lack more credits in order to buy this item.";?></p><p><br><br><br><h3><?php echo "$ltd_name"?></h3><img src="<?php echo "$image_url" ?>" style="float: right"></p><p><br>Out of credits.<br><br></p><p><?php</p><p>} else{ ?></p><p><img src="<?php echo "$image_url" ?>" style="float: right"></p><p><font size="2" color="white"> <h3>Buy</h3></p><p><p>Buy your <?php echo "$ltd_name"?> for just <?php echo "$ltd_price"?> credits.<br></p><p></font><font size="2" color="purple"></p><p>Only <?php echo "$getltd_num"; ?> of <?php echo "$getltd_total"; ?> left!</p></font></p><p><form action="buyltd" method="post"></p><p><input type="hidden" name="ltd_id" value="<?php echo "$ltd_id"; ?>"></p><p><input type="submit" type="submit" name="help" value="Buy" class="button round"> </form></b> <?php }}?></p><p></div></ul><br><br><br><br><br><br><br><br><br>[/PHP]</p><p>This code is made for Priv theme, so if you use other you proberbly need to edit it.</p><p> </p><p>Each time you want to add a new furniture, you have to duplicate this code, edit in database table rev_ltd (insert record for each furniture you want to add), furni_id should be the same as 'id' of the furniture is in table 'furniture'.</p><p> </p><p>Images:</p><p><img src="http://puu.sh/2pQSa" alt="" class="fr-fic fr-dii fr-draggable " style="" /></p></blockquote><p></p>
[QUOTE="thewicard, post: 191850, member: 8814"] So, I used a few hours figuring this out xP Hope you enjoy. Sorry about insanely long code. Price is now configured in DB. What does this code do? It allows you to sell furniture in limited quantities. Is it secure? It has double money-in-pocket check [B](1 in whatever page it's placed in AND 1 when delivering furniture)[/B] It has double furniture-not-sold-out check [B](1 in whatever page it's placed in AND 1 when delivering furniture)[/B] Will not work to refresh page to get another furniture unless there are still available AND you have money for it. Added POST Filter [B](Now only allow numeric posts)[/B] //Thanks to Leenster for telling me it was needed. First: Run this queue [PHP]DROP TABLE IF EXISTS `rev_ltd`; CREATE TABLE `rev_ltd` ( `furni_id` int(255) NOT NULL, `furni_left` int(255) NOT NULL DEFAULT '100', `furni_sold` int(255) NOT NULL DEFAULT '0', `furni_price` int(255) NOT NULL DEFAULT '5000', PRIMARY KEY (`furni_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; INSERT INTO `rev_ltd` VALUES ('227', '15', '0', '5000');[/PHP] Second: Create a file in app/tpl/skins/YOURSKIN/ named buyltd.php Place this content in the file and save: [PHP]<?php $ltd_id = preg_replace('/[^0-9]/', '', $_POST["ltd_id"]); $user_id = $_SESSION['user']['id']; $selectfromusers = mysql_query("SELECT * FROM users WHERE id = '".$user_id."'") or die(mysql_error()); while ($getmoney = mysql_fetch_array($selectfromusers)) $money_current = $getmoney['credits']; $selectfromfurninum = mysql_query("SELECT * FROM rev_ltd WHERE furni_id = '".$ltd_id."'") or die(mysql_error()); while ($getfurninum = mysql_fetch_array($selectfromfurninum)) $furnileft = $getfurninum['furni_left'] and $furnisold = $getfurninum['furni_sold'] and $ltd_price = $getfurninum['furni_price']; if($furnileft > '0') { if($money_current < $ltd_price) { echo "You don't have enough money for this item"; } else { $newmoney = $money_current - $ltd_price; mysql_query("UPDATE users SET credits='".$newmoney."' WHERE id='".$user_id."'") or die(mysql_error()); $newfurnileft = $furnileft - '1'; $newfurnisold = $furnisold + '1'; mysql_query("UPDATE rev_ltd SET furni_sold='".$newfurnisold."'") or die(mysql_error()); mysql_query("UPDATE rev_ltd SET furni_left='".$newfurnileft."'") or die(mysql_error()); $highestid = mysql_query("SELECT * from items ORDER BY id DESC LIMIT 1") or die(mysql_error()); while ($checknewid2 = mysql_fetch_array($highestid)) $newid2 = $checknewid2['id']; $newid = $newid2 + '1'; mysql_query("INSERT INTO items (id, user_id, room_id, base_item, extra_data, x, y, z, rot, wall_pos) VALUES ('".$newid."','".$user_id."',0,'".$ltd_id."',0,0,0,0,0,0)") or die(mysql_error()); echo "Item bough successfully!"; } } else { echo "All of furniture is already sold, sorry"; } ?> <meta http-equiv="refresh" content="1; URL=me">[/PHP] Third: Goto whatever page you want this in, add this at the top: [PHP]<?php $user_id = $_SESSION['user']['id']; $selectfromusers = mysql_query("SELECT * FROM users WHERE id = '".$user_id."'") or die(mysql_error()); while ($getmoney = mysql_fetch_array($selectfromusers)) $money_current = $getmoney['credits']; ?>[/PHP] Forth: Add this wherever you want the output, this is made for Priv theme. [PHP]<?php //Furniconfiguration $ltd_id = "227"; //furni_id in the database $ltd_name = "Dragonegg"; //The name of your furni $image_url = "http://habboxwiki.com/wiki/images/1/12/Black_Dino_Egg.png"; //Image URL (optional) //Collects data from database $selectfromltd = mysql_query("SELECT * FROM rev_ltd WHERE furni_id = '".$ltd_id."'") or die(mysql_error()); while ($getltd = mysql_fetch_array($selectfromltd)) $getltd_num = $getltd['furni_left'] and $getltd_sold = $getltd['furni_sold'] and $ltd_price = $getltd['furni_price']; $getltd_total = $getltd_sold + $getltd_num; $money_lack = $ltd_price - $money_current; ?> <!-- The part that you can see, may need to be changed to fit other theme (currently for Priv theme) --> <div class="left page round"><ul> <?php if($getltd_num == '0') { $money_lack = $ltd_price - $money_current; echo "This item is no longer available, sorry.";?> <br><br><br><h3><?php echo "$ltd_name"?></h3><img src="<?php echo "$image_url" ?>" style="float: right"> <br>Sold out.<br><br> <?php } else { if($money_current < $ltd_price) { echo "You need $money_lack more credits in order to buy this item.";?> <br><br><br><h3><?php echo "$ltd_name"?></h3><img src="<?php echo "$image_url" ?>" style="float: right"> <br>Out of credits.<br><br> <?php } else{ ?> <img src="<?php echo "$image_url" ?>" style="float: right"> <font size="2" color="white"> <h3>Buy</h3> <p>Buy your <?php echo "$ltd_name"?> for just <?php echo "$ltd_price"?> credits.<br> </font><font size="2" color="purple"> Only <?php echo "$getltd_num"; ?> of <?php echo "$getltd_total"; ?> left!</p></font> <form action="buyltd" method="post"> <input type="hidden" name="ltd_id" value="<?php echo "$ltd_id"; ?>"> <input type="submit" type="submit" name="help" value="Buy" class="button round"> </form></b> <?php }}?> </div></ul><br><br><br><br><br><br><br><br><br>[/PHP] This code is made for Priv theme, so if you use other you proberbly need to edit it. Each time you want to add a new furniture, you have to duplicate this code, edit in database table rev_ltd (insert record for each furniture you want to add), furni_id should be the same as 'id' of the furniture is in table 'furniture'. Images: [IMG]http://puu.sh/2pQSa[/IMG] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Server Development
Habbo Retros
Habbo Releases
CMS Releases
[RevCMS] LIMITED furniture sales in CMS [Phoenix]
Top