• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Select house items from database

mkq

New Member
Joined
Jun 23, 2008
Messages
11
Reaction score
0
I need to get some house items using database query.
I have made some changes on TFS 3.42 pl2 :

Code:
ALTER TABLE `tiles` ADD `house_id` INT( 10 ) UNSIGNED NOT NULL

iomapserialize.h:
i have change:
Code:
bool saveTile(Database* db, uint32_t tileId, const Tile* tile);
to:
Code:
bool saveTile(Database* db, uint32_t tileId, const Tile* tile, uint32_t house_id);


iomapserialize.cpp:
i have change:
Code:
bool IOMapSerialize::saveTile(Database* db, uint32_t tileId, const Tile* tile)
to:
Code:
bool IOMapSerialize::saveTile(Database* db, uint32_t tileId, const Tile* tile, uint32_t house_id)


i have change:
Code:
query << "INSERT INTO `tiles` (`id`, `world_id`, `x`, `y`, `z`) VALUES " << "(" << tileId << ", " << g_config.getNumber(ConfigManager::WORLD_ID);
query << ", " << tilePosition.x << ", " << tilePosition.y << ", " << tilePosition.z << ")";
to:
Code:
query << "INSERT INTO `tiles` (`id`, `world_id`, `x`, `y`, `z`, `house_id`) VALUES " << "(" << tileId << ", " << g_config.getNumber(ConfigManager::WORLD_ID);
query << ", " << tilePosition.x << ", " << tilePosition.y << ", " << tilePosition.z << ", " << house_id << ")";

In function
Code:
bool IOMapSerialize::saveMapRelational(Map* map)

i have change:
Code:
saveTile(db, ++tileId, *tit);
to:
Code:
saveTile(db, ++tileId, *tit, it->second->getHouseId());

And i have problem, because it doesn't work. After save or restart values on house_id = 0.
Whats wrong ?

Meaby is other way to get all items from specific house?

Thanks for help and sorry for my bad english...
 
i want get all items from specific house.
i can get all player items, depot items but player house items i cant...
 
Still I have no clue what you want to do with this, and when. It is needed while loading? Or when server saves? Or anytime when houses are already loaded.

Here you have simple example, looping over all items inside house

Code:
	Item* item = NULL;
	House* house = House* house = Houses::getInstance().getHouse(houseId);
	for(HouseTileList::iterator it = house->getHouseTileBegin(); it != house->getHouseTileEnd(); ++it)
	{
		for(int32_t i = 0; i < (*it)->getThingCount(); ++i)
		{
			if(!(item = (*it)->__getThing(i)->getItem()) || (item->isNotMoveable() && !item->forceSerialize()))
				continue;

			//found item, do what you want..
			std::cout << item->getID() << std::endl;
		}
	}
 
sometimes i want make query to database and get all items from specific house.

for example (its totally abstract query):
Code:
select itemtype, count from tile_items where house_id = 5

and then i know what items are in house of id = 5.

im looking on current structure of DB, but there aren't any relations needed to get informations about items in house.

so i must store house id information, "near" informations about items on map. I thing taht best place is in 'tiles' table.


btw. why this information isn't stored in official version ? i thing it's very usefully
 
Back
Top