• 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++ Game.loadmap with offset

Karain

Jack of all trades
Joined
Jul 9, 2009
Messages
338
Solutions
3
Reaction score
147
Location
Egypt
Hello, I was fiddling around with Game.loadmap but i realized there is no way to offset the loaded map like you would do in remere.

Is it easy to add the offset parameters into the source code?

Thanks.
 
Hello, I was fiddling around with Game.loadmap but i realized there is no way to offset the loaded map like you would do in remere.

Is it easy to add the offset parameters into the source code?

Thanks.
Easy? Sort of. There's quite a few changes you need to make in iomap & game.cpp/h. (I recently did exactly this)
My method to solve this was to add a new Position parameter to IO::loadMap and IOMap::parseTileArea + whatever deals with loading map in game.cpp (as well as luascript.cpp for a new function to load map with a position parameter).
Then I just added pos.x pos.y pos.z to the base coordinates that are being loaded inside of parseTileArea.
 
the bigger problem here is that it might break all kind of actions which are performed for static coordinates, so you have to keep that in mind aswell and calculate the offset for such positions aswell.
 
the bigger problem here is that it might break all kind of actions which are performed for static coordinates, so you have to keep that in mind aswell and calculate the offset for such positions aswell.
What do you mean? Example?
 
I mean like you load a certain piece of map which contains a tile which you need to step on and then it removes a wall/door from a specific coordinate let's say (100,100,7) but now instead of loading the map on the default coordinates you load them like x +100, y +100.
If you now walk onto that tile it would ofc remove the wrong wall/door in this case, you should be careful if your server includes such things.
 
I've created an indexing system for training rooms like years back, this might also give you a hint on how to work with offsets and such.
 
I've finally gotten around to uploading my code when I did this ~2 months ago here: dynamic map loading · Vulcanx/forgottenserver@c1cd03c (https://github.com/Vulcanx/forgottenserver/commit/c1cd03ce5f7e6e8606dddce0f210141207c2b709)
I screwed up a few changes like the leech/copyright dates at the top of files so just ignore those and look at the changes related to map/parsing tiles.
It introduces a new function called Game.loadMapChunk(path, position, remove)
Path: The path to the OTBM file (with the .otbm extension in it, example "data/world/test.otbm")
Position: The position offset (remember to put the map you're loading at x:0 y:0 in map editor so the offset works properly, example: Position(1000, 1000, 0) will offset x with +1000, y +1000, and z +0, so the map will load at Position(1000, 1000, 7) if you map it on the 7th floor)
Remove: Boolean, true makes it remove all items instead of adding them, if you want to just add/load the chunk you don't have to set this argument or set it to false if you do.
Full example of calling this function: Game.loadMapChunk("data/world/test.otbm", Position(1000, 1000, 0))
Adding then removing after 10 seconds for example:
Lua:
Game.loadMapChunk("data/world/test.otbm", Position(1000, 1000, 0)) -- load the chunk
addEvent(Game.loadMapChunk, 10000, "data/world/test.otbm", Position(1000, 1000, 0), true) -- remove it after 10 sec
Enjoy.
 
Last edited:
Back
Top