• 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!

C++ Save movable items on map to database

Nekiro

Legendary OT User
TFS Developer
Joined
Sep 7, 2015
Messages
2,677
Solutions
126
Reaction score
2,112
I'm trying to make server save every movable item, that is on map on shutdown and then load them on startup. It should save and load from database.

I was looking at save house items, to get any clue, but still I'm too bad in c++ and can't do shit.

Anyone got idea how can it be done?

I'm using TFS 1.3.

bump ;)
 
Last edited by a moderator:
Solution
I'm trying to get any hints how do I iterate through every tile on map that is item on it.
I dont need complete code, but if you want to, you can move it to request.

Yeah, about the house saving. It's hard to base on this, because its getting the house and it is iterating through the tiles in house

I have no idea how to get all map tiles, so I can loop through them.
if you tried to do this on a rl map your memory would die
the house tiles are saved when the house tile is added inside of IOMap::loadMap
to do the same, you'd save each tile in the map to a std::list (look in house.h for HouseTileList) when it loads through IOMap::loadMap (thousands upon thousands of tiles)
when you save you'll have to loop through all of those...
I'm trying to make server save every movable item, that is on map on shutdown and then load them on startup. It should save and load from database.

I was looking at save house items, to get any clue, but still I'm too bad in c++ and can't do shit.

Anyone got idea how can it be done?

I'm using TFS 1.3.

bump ;)

Well im not either any pro or so haha
But I would probbly base my code of the house saving function(s), but not only house tiles etc ..

But are you looking for a complete code or just what you should do?
Do you want me to move it to requests?
 
Well im not either any pro or so haha
But I would probbly base my code of the house saving function(s), but not only house tiles etc ..

But are you looking for a complete code or just what you should do?
Do you want me to move it to requests?
I'm trying to get any hints how do I iterate through every tile on map that is item on it.
I dont need complete code, but if you want to, you can move it to request.

Yeah, about the house saving. It's hard to base on this, because its getting the house and it is iterating through the tiles in house

I have no idea how to get all map tiles, so I can loop through them.
 
I'm trying to get any hints how do I iterate through every tile on map that is item on it.
I dont need complete code, but if you want to, you can move it to request.

Yeah, about the house saving. It's hard to base on this, because its getting the house and it is iterating through the tiles in house

I have no idea how to get all map tiles, so I can loop through them.

Well you can use this function to get the positions; forgottenserver/game.h at e70f7153128596ce870bb79cf5f1ae4159262291 · otland/forgottenserver · GitHub
But ill move it to requests so hopefully someone with more knowledge can help you :)
 
I'm trying to get any hints how do I iterate through every tile on map that is item on it.
I dont need complete code, but if you want to, you can move it to request.

Yeah, about the house saving. It's hard to base on this, because its getting the house and it is iterating through the tiles in house

I have no idea how to get all map tiles, so I can loop through them.
if you tried to do this on a rl map your memory would die
the house tiles are saved when the house tile is added inside of IOMap::loadMap
to do the same, you'd save each tile in the map to a std::list (look in house.h for HouseTileList) when it loads through IOMap::loadMap (thousands upon thousands of tiles)
when you save you'll have to loop through all of those tiles in the list and check tile->getItems() and loop through that to check for movable items, and then add it to a db query (you'll need a new table for this) with columns like x y z data (where data is the tile items serialized, luckily you already have IOMapSerialize::saveTile to do that)
when loading the map youll need to go through the database table you saved that information in and unserialize the data and put it back on the map (IOMapSerialize::loadItem)
good luck
 
Solution
if you tried to do this on a rl map your memory would die
the house tiles are saved when the house tile is added inside of IOMap::loadMap
to do the same, you'd save each tile in the map to a std::list (look in house.h for HouseTileList) when it loads through IOMap::loadMap (thousands upon thousands of tiles)
when you save you'll have to loop through all of those tiles in the list and check tile->getItems() and loop through that to check for movable items, and then add it to a db query (you'll need a new table for this) with columns like x y z data (where data is the tile items serialized, luckily you already have IOMapSerialize::saveTile to do that)
when loading the map youll need to go through the database table you saved that information in and unserialize the data and put it back on the map (IOMapSerialize::loadItem)
good luck
Thanks for the advice.

I did it, I edited "clean" function to saveTiles as saveHouseItems do.

I didn't explain well enough, I had in mind to only save items that people throw. Trash etc.
For example, it help when someone is having saved potions and the server is saving game so it closes.

I edited clean function to save items into database as "blobs" as saveHouseItems do.
Then I just copied loadHouseItems to load items from my table and it works!

Thanks for help.
 
Back
Top