[Release] Room On Register

JayC

Always Learning
Aug 8, 2013
5,493
1,398
Hey Devbest!

So this is a dynamic room system, that is 100% random and you can add as many templates as you want. Go ahead and read each of the spoilers (Alot of information to put, so I am going to divide it up), to explain how it works and how to add them!

Alright, Step 1 is to add it. Here is the client code:
Code:
<?php
// Starter
$getStats = mysql_query("SELECT null FROM `user_stats` WHERE id = '".$_SESSION['user']['id']."'");
if(mysql_num_rows($getStats) != 1){
  $getRoomKit = mysql_fetch_assoc(mysql_query("SELECT * FROM room_starterkit ORDER BY RAND() LIMIT 1"));
  $welcomeMessage = "Welcome " . $_SESSION['user']['username'];
  mysql_query("INSERT INTO `rooms` (caption,owner,description,model_name,wallpaper,floor) VALUES ('".$welcomeMessage."', '".$_SESSION['user']['id']."', 'Welcome to Hablore', '".$getRoomKit['room_Model']."', '".$getRoomKit['room_Wallpaper']."', '".$getRoomKit['room_Floor']."') ");
  $theRoomID = mysql_fetch_assoc(mysql_query("SELECT id FROM `rooms` ORDER BY `id` DESC LIMIT 1"));
  mysql_query("UPDATE `users` SET `home_room` = '".$theRoomID['id']."' WHERE `id` = '".$_SESSION['user']['id']."'");
  $getRoomItems = mysql_query("SELECT * FROM room_itemkits WHERE roomKit = '".$getRoomKit['id']."'");

  while($currItem = mysql_fetch_assoc($getRoomItems)){
    mysql_query("INSERT INTO `items`(user_id,room_id,base_item,extra_data,x,y,z,rot,wall_pos) VALUES ('".$_SESSION['user']['id']."','".$theRoomID['id']."','".$currItem['item_BaseID']."', '".$currItem['extra_data']."', '".$currItem['x']."', '".$currItem['y']."', '".$currItem['z']."','".$currItem['rot']."', '".$currItem['wall_pos']."')");
  }

}
?>
Explanation:
- Checks if the user has entered the client before (First login creates the user_stats), and then if the user hasn't it grabs all of the information from my created tables, and then will create the room and set their first homeroom.

Code:
DROP TABLE IF EXISTS `room_starterkit`;
CREATE TABLE `room_starterkit` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `room_Model` varchar(50) NOT NULL,
  `room_Wallpaper` varchar(50) NOT NULL,
  `room_Floor` varchar(50) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
This table is for adding the layout of the room. Will explain more of this later.

Code:
DROP TABLE IF EXISTS `room_itemkits`;
CREATE TABLE `room_itemkits` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `roomKit` int(11) NOT NULL,
  `item_BaseID` int(11) NOT NULL,
  `x` int(11) NOT NULL,
  `y` int(11) NOT NULL,
  `z` double(11,0) NOT NULL,
  `rot` int(11) NOT NULL,
  `wall_pos` varchar(120) NOT NULL,
  `extra_data` varchar(120) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
This code will put each of the items in the room, into the new room! Will explain how to add later.

You can build any room you would like, and how you add the information will be explained in step 3. The room should be relatively small however because each item does take up another ID in the items table; and does create more work for you (see step 3 now!)

First of all once you create the room open the room table and get the following information from the room you just created:
- Model , Wallpaper ID and the Floor ID
Then go into the table room_starterkit and add the field {ID} {Model} {Wallpaper ID} {Floor ID}

Next, go to the items table and get the following information FOR EACH ITEM IN THE ROOM:
- Item ID, X, Y, Z, ROT, wall_pos, extra_data
Add this into the room_itemkits by putting the next ID (This ID can be used if you wanted to make a housekeeping attachment to easily add each room :) This might come at a later release, and if I do make a nice housekeeping page I will link it on this thread. Pretty much you could have it auto grab all of this stuff from the housekeeping page by just entering the room id and have it insert all this stuff for you.)
{ID} {RoomKitID} {Item ID} {X} {Y} {Z} {ROT} {WALL_POS} {EXTRA_DATA}
Now you do not have to guess on any of this. This will all be from the item table and it will tell you exactly , its just a matter of moving it into this table so you can dynamically add this item each and every time the room is selected.

And after you do those 3 simple steps, your room is ready to go! Repeat steps 2 - 3 and you can add more rooms! The number of rooms you can add is endless, and it will give the user a random room from this table EVERY TIME :)

Code:
INSERT INTO `room_itemkits` VALUES ('1', '1', '65276', '7', '1', '0', '0', ' ', ' ');
INSERT INTO `room_itemkits` VALUES ('2', '1', '65313', '0', '0', '0', '0', ':w=4,4 l=24,28 l', ' ');
INSERT INTO `room_itemkits` VALUES ('3', '1', '65277', '10', '1', '0', '0', ' ', ' ');
INSERT INTO `room_itemkits` VALUES ('4', '1', '65277', '5', '1', '0', '0', ' ', ' ');
INSERT INTO `room_itemkits` VALUES ('5', '1', '65270', '10', '1', '1', '0', ' ', ' ');
INSERT INTO `room_itemkits` VALUES ('6', '1', '65265', '5', '1', '1', '0', ' ', ' ');
INSERT INTO `room_itemkits` VALUES ('7', '1', '65301', '5', '7', '0', '0', ' ', ' ');
INSERT INTO `room_itemkits` VALUES ('8', '1', '65301', '5', '9', '0', '0', ' ', ' ');
INSERT INTO `room_itemkits` VALUES ('9', '1', '65301', '7', '7', '0', '0', ' ', ' ');
INSERT INTO `room_itemkits` VALUES ('10', '1', '65301', '7', '9', '0', '0', ' ', ' ');
INSERT INTO `room_itemkits` VALUES ('11', '1', '906', '8', '10', '0', '6', ' ', ' ');
INSERT INTO `room_itemkits` VALUES ('12', '1', '915', '8', '9', '0', '6', ' ', ' ');
INSERT INTO `room_itemkits` VALUES ('13', '1', '915', '8', '8', '0', '6', ' ', ' ');
INSERT INTO `room_itemkits` VALUES ('14', '1', '933', '8', '7', '0', '6', ' ', ' ');
INSERT INTO `room_itemkits` VALUES ('15', '1', '897', '7', '10', '0', '0', ' ', ' ');
INSERT INTO `room_itemkits` VALUES ('16', '1', '99969', '5', '8', '0', '2', ' ', ' ');
INSERT INTO `room_itemkits` VALUES ('17', '1', '89985', '5', '8', '1', '2', ' ', ' ');
INSERT INTO `room_itemkits` VALUES ('18', '1', '171', '5', '7', '0', '2', ' ', ' ');
Code:
INSERT INTO `room_starterkit` VALUES ('1', 'model_bc_274', '606', '110');

Well hope you guys enjoy the release, leave a like and a comment! I do not have any images because this project was built on something that is no longer opened :) Leave your comments below with some screenshots of some amazing rooms you built!


VERSION 2:

Code:
DROP TABLE IF EXISTS `room_starters`;
CREATE TABLE `room_starters` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

<?php
// Starter
$getStats = mysql_query("SELECT null FROM `user_stats` WHERE id = '".$_SESSION['user']['id']."'");
if(mysql_num_rows($getStats) != 1){
        $randomRoomID = mysql_fetch_assoc(mysql_query("SELECT `id` FROM room_starters ORDER BY RAND() LIMIT 1"));

        $getRoom = mysql_fetch_assoc(mysql_query("SELECT * FROM `rooms` WHERE id = '".$randomRoomID['id']."' LIMIT 1"));

        $starterCaption = "Welcome " . $_SESSION['user']['username'];
        mysql_query("INSERT INTO `rooms` (roomtype, caption, owner, description, model_name, wallpaper, floor, wallthick, floorthick, allow_hidewall) VALUES ('public','".$starterCaption."','".$_SESSION['user']['id']."','Welcome to iHabbo','".$getRoom['model_name']."','".$getRoom['wallpaper']."','".$getRoom['floor']."','".$getRoom['wallthick']."','".$getRoom['floorthick']."','".$getRoom['allow_hidewall']."')");

        $lastRoomID = mysql_fetch_assoc(mysql_query("SELECT id FROM rooms ORDER BY `id` DESC LIMIT 1"));
        mysql_query("UPDATE `users` SET `home_room` = '".$lastRoomID['id']."' WHERE `id` = '".$_SESSION['user']['id']."'");
        $getItems = mysql_query("SELECT * FROM `items` WHERE `room_id` = '".$randomRoomID['id']."'");

    while($CurItem = mysql_fetch_assoc($getItems)){
        mysql_query("INSERT INTO `items` (user_id, room_id, base_item, extra_data, x, y, z, rot, wall_pos) VALUES ('".$_SESSION['user']['id']."','".$lastRoomID['id']."','".$CurItem['base_item']."','".$CurItem['extra_data']."','".$CurItem['x']."','".$CurItem['y']."','".$CurItem['z']."','".$CurItem['rot']."','".$CurItem['wall_pos']."')");
    }

}

?>
- JayCustom
 
Last edited:

Legend

https://habda.sh/
Jun 17, 2015
86
20
You obviously didn't set it up right this was created on sledmores plus emu edit and it worked 100%
I'll take another look. I used the Default Room you included in the spoiler. I ran all the queries and threw the code into my client.php. When I tested it, two rooms were made but when you tried to go to them, they were just black. Was there something that was meant to be changed? I didn't and don't see anything.
 

Joe

Well-Known Member
Jun 10, 2012
4,090
1,918
I'll take another look. I used the Default Room you included in the spoiler. I ran all the queries and threw the code into my client.php. When I tested it, two rooms were made but when you tried to go to them, they were just black. Was there something that was meant to be changed? I didn't and don't see anything.
Do you get an error in your emulator logs about the room models? I know it's basic shit but that's what happens when it can't create the model for the database.
 

Legend

https://habda.sh/
Jun 17, 2015
86
20
Do you get an error in your emulator logs about the room models? I know it's basic shit but that's what happens when it can't create the model for the database.
I'll reboot my emulator and see if I come up with any errors. Will update once I have.

Update: There weren't any errors that came up.
 
Last edited:

Joe

Well-Known Member
Jun 10, 2012
4,090
1,918
This works fine, thank you Jay.
ab8a84087ac9470fb0fe97f06997a5de.png
If it's not working for you you've obviously done something wrong.

Follow it carefully and word for word! By any chance was this made for my hotel, Hablore?! :eek:

EDIT: If I wanted to make users who have already registered have this room as well, what would I have to change? Could I just make an enum for starter set to 1 or something a long those lines?
 
Last edited:

Joe

Well-Known Member
Jun 10, 2012
4,090
1,918
@JayCustom it all works but when i reload client it makes another room happens everytime?
Ah, I get the same problem.
 
From what I've noticed if a user has registered and you reload, you get another room.
Currently reloading doesn't make a new room for me, so I guess it's that.
 
UNLESS it's after an emulator restart or something - something is triggering it, just not sure what.
 

JayC

Always Learning
Aug 8, 2013
5,493
1,398
If the room is created and black: you have to add the room model.
If it's creating new rooms: you need to change how it tests if they are a new user by assigning a variable on the session when they register and taking that variable away first time entering the client
 

Users who are viewing this thread

Top