ID:2020447
 
(See the best response by Tacurumin.)
Alright I'm using Forum_Account's Map instancing Lib.
The problem is the map i'm trying to make a copy of is not copying exactly the map I coded it to copy if on an icon file that I had there there's more than 1 state it will use any of the states changing all the icons.. also it doesn't copy the mobs or objs on the map i coded to copy.. Anyone could help me? maybe I'm using the lib wrong.

Code:
var
const
CUTSCENE_Z = 3

var/Map/cutscene_map = maps.copy(CUTSCENE_Z)

mob
proc
start_tutorial()
for(var/mob/actor/Tutorial_Master in cutscene_map.objects)
spawn()
Tutorial_Master.cutscene()




//Create stuff here
src.loc=locate(30,8,cutscene_map.z)
cutscene_map.repop()
start_tutorial()
cutscene_map.free()

How the original map(the one supposed to be copied looks)


How it looks after you login and create



I'm trying to make the player after creating its character they go to an instancing map where a "mini scene" takes place. Also I have a question if multiple players create at the same time is there a possibility that they go to the same instance map? if so how could I stop it? Any help is appreciated


Looks like it's saving the icons but not the icon_state? So when it loads up it's using the default icon state for each icon?
Yeah something like that
Best response
I have a fix for this, i will post when i get home.

Here is :

var
Maps/maps = new()

atom
var
// this is used to determine if an object was
// created as part of an instanced map or not.
__instanced = 0

proc
// This is used to determine if an object should
// be stored as part of a MapBase or not. You can
// override it to make certain object types not
// be instanced. By default, all objects are stored
// except for mobs with clients.
is_instanced()
return 1

mob
is_instanced()
if(client)
return 0
else
return 1

Maps
var
list/z = list()
list/bases = list()
list/file_bases = list()

New()
for(var/i = 1 to world.maxz)
bases += 0

proc
load(filename)

if(!fexists(filename))
CRASH("The file '[filename]' does not exist.")

var/savefile/f = new(filename)
var/MapBase/base
f >> base

return base

// create a MapBase for the z level (if we haven't already)
// and create an instance of that base
copy(map_z)

// the argument to copy can be a z level or
// a filename, if it's a filename we load the
// MapBase from the file, then create an instance
// of it
if(istext(map_z))

var/filename = map_z

var/MapBase/base

// if we've loaded it before, use the already-loaded one
if(filename in file_bases)
base = file_bases[filename]

// otherwise we load it from disk
else
base = load(filename)

// return a new instance of this base
return base.make()

var/MapBase/base = bases[map_z]

// if we don't have a base for this z level, create one
if(!base)
base = new(map_z)
bases[map_z] = base

// create an instance of the base and return it
return base.make()

// makes a z level available for use
clear(map_z)

// if the z level is already available, do nothing
if(map_z in z)
return 0

// otherwise, add it to the list of available z levels
z += map_z
return 1

// return the next available z level, creating a new one if necessary
__get_z()
if(z.len == 0)
world.maxz += 1
return world.maxz
else
var/next_z = z[1]
z -= next_z

return next_z

MapBase
var
// the size of the base map
maxx
maxy

// a 2D list of turf types
list/turfs

// a 2D list of turf overlays
list/overlays

// a 2D list of turf underlays
list/underlays

// a 2D list of turf icon_states
list/states

// a 2D list of changed turf icons
list/icons

// a 2D list of area types for each turf
list/areas

// a 2D list of Pixel_X
list/Px

// a 2D list of Pixel_Y
list/Py

// a 2D list of Layer
list/Layer

// a 2D list of Density
list/Density

// the list of objects placed on the map, for every
// object three values are added to this list:
// the object's type path
// the object's x coordinate
// the object's y coordinate

bolaSpawn = FALSE

list/objects = list()

list/compIguais = list()



New(z = -1)

// if no z level was specified, do nothing
if(z == -1)
return

// otherwise, a z level was specified so we extract data from that map

// first we find the maxx and maxy for the z level
for(var/x = 1 to world.maxx)
var/turf/t = locate(x, 1, z)

if(t)
maxx = x
else
break

for(var/y = 1 to world.maxy)
var/turf/t = locate(1, y, z)

if(t)
maxy = y
else
break

// then we create lists to determine the turf and area
// type for each tile in the z level
turfs = new(maxx, maxy)
overlays = new(maxx, maxy)
underlays = new(maxx, maxy)
icons = new(maxx, maxy)
areas = new(maxx, maxy)
states = new(maxx, maxy)
Px = new(maxx, maxy)
Py = new(maxx, maxy)
Layer = new(maxx, maxy)
Density = new(maxx, maxy)

for(var/x = 1 to maxx)
for(var/y = 1 to maxy)
var/turf/t = locate(x, y, z)
turfs[x][y] = t.type
overlays[x][y] = t.overlays
underlays[x][y] = t.underlays
states[x][y] = t.icon_state
Px[x][y] = t.pixel_x
Py[x][y] = t.pixel_y
Layer[x][y] = t.layer
Density[x][y] = t.density
icons[x][y] = t.icon != initial(t.icon) ? t.icon : null

var/area/area = t.loc
areas[x][y] = area.type

// we also keep a list of objects
for(var/atom/a in t)
if(a in compIguais)
continue
else
if(a.is_instanced())
compIguais += a // Lista utilizada para comparações de objetos duplicados :

objects += a.type
objects += a.x
objects += a.y
objects += a.icon_state
objects += a.pixel_x
objects += a.pixel_y
objects += a.layer
objects += a.density

proc
save(filename)
var/savefile/f = new(filename)
f << src

// create a new instance of this map and return
// a /Map object that represents it.
make(z = 0)

var/Map/map

// if the argument is a Map object, we use that
if(istype(z, /Map))
map = z

// otherwise we create a new one.
else
map = new(src)

// if we passed a z value to make(), use that
if(z)
map.z = z

// otherwise, find an available z value
else
map.z = maps.__get_z()

// set all turfs on the new map
for(var/x = 1 to world.maxx)
for(var/y = 1 to world.maxy)
if(x > maxx || y > maxy)
var/turf/t = locate(x, y, map.z)
t.icon = null
else
// remove existing objects on the map
var/turf/t = locate(x, y, map.z)
for(var/atom/movable/m in t)
if(m.__instanced)
m.loc = null

// set the turf's area
var/area/a = locate(areas[x][y])
a.contents += t

// make a new turf of the appropriate type
var/turf_type = turfs[x][y]
new turf_type(t)

t.overlays += overlays[x][y]
t.underlays += underlays[x][y]
t.icon_state = states[x][y]
if(icons[x][y]) t.icon = icons[x][y]

// populate the map with objects
for(var/i = 1 to objects.len / 8)
var/obj_type = objects[i * 8 - 7]
var/obj_x = objects[i * 8 - 6]
var/obj_y = objects[i * 8 - 5]
var/state = objects[i * 8 - 4]
var/px = objects[i * 8 - 3]
var/py = objects[i * 8 - 2]
var/layer = objects[i * 8 - 1]
var/density = objects[i * 8 - 0]

var/atom/a = new obj_type(locate(obj_x, obj_y, map.z))
a.icon_state = state
a.pixel_x = px
a.pixel_y = py
a.layer = layer
a.density = density

return map

// A /Map object is created to represent an instance
// of a map that you've made.
Map
var
// the z level this map copy is placed on
z

// a list of references to each object that was created
// as part of this map instance, this is what lets us
// be able to repop() an individual map instance.
list/objects = list()

// the /MapBase objec that was used to create this instance
MapBase/base

New(MapBase/b)

if(!b)
CRASH("The Map object's constructor must be passed a MapBase object.")

base = b

proc
limparMapa(Mapa)
switch(Mapa)
if("Lobby")
for(var/x = 1 to 45)
for(var/y = 31 to 63)
var/turf/t = locate(x, y, z)

for(var/atom/movable/m in t)
m.loc = null
del(t)
if("Jogo")
for(var/x = 1 to world.maxx)
for(var/y = 1 to world.maxy)
var/turf/t = locate(x, y, z)

for(var/atom/movable/m in t)
m.loc = null
del(t)

maps.z += z
del src

// make this map's z level available for other maps to use
free()
maps.z += z
del src

// repopulate the map with objects that were initially there,
// but have since been deleted
repop()
for(var/i = 1 to objects.len)
if(objects[i])
continue

var/obj_type = base.objects[i * 8 - 7]
var/obj_x = base.objects[i * 8 - 6]
var/obj_y = base.objects[i * 8 - 5]
var/state = base.objects[i * 8 - 4]
var/px = base.objects[i * 8 - 3]
var/py = base.objects[i * 8 - 2]
var/layer = base.objects[i * 8 - 1]
var/density = base.objects[i * 8 - 0]

var/obj/A = objects[i]
A = new obj_type(locate(obj_x, obj_y, z))
A.icon_state = state
A.pixel_x = px
A.pixel_y = py
A.layer = layer
A.density = density

reset()
for(var/i = 1 to objects.len)
del objects[i]

objects.Cut()

base.make(src)

get(type_path)

var/is_turf = derived_from(type_path, /turf)
var/is_area = derived_from(type_path, /area)
var/is_mob = derived_from(type_path, /atom/movable)

var/list/L = list()

if(is_mob)
for(var/x = 1 to base.maxx)
for(var/y = 1 to base.maxy)
var/turf/t = locate(x, y, z)

for(var/atom/movable/m in t)
if(istype(m, type_path))
L += m

else if(is_turf)
for(var/x = 1 to base.maxx)
for(var/y = 1 to base.maxy)
var/turf/t = locate(x, y, z)

if(istype(t, type_path))
L += t

else if(is_area)
for(var/x = 1 to base.maxx)
for(var/y = 1 to base.maxy)
var/turf/t = locate(x, y, z)
var/area/a = t.loc

if(istype(a, type_path))
L += a

return L

proc
derived_from(child, parent)
return (child in typesof(parent)) ? 1 : 0


Let me know if it work.
It fixed a lot of things and now it copies most of the stuff exactly like it should but its not copying the object in it (the board on the screenshot) and the mob isn't being copied
You'll need to add Obj to MapBase/New()

And you'll need to place the mob in the new location.
Alright thanks both of you :)