Page 1 of 1

Get map directory Method.

PostPosted: 27 Jun 2014, 01:41
by Leeizazombie
Hey, I've decided to make a method that will give me the directory of a map that the player is currently inside.
This is handy for making changes to the level file, for example: moving, deleting, copying or uploading...

Method Code:
Code: Select all
private string GetMapDir(Player p)
        {
            string mapname = p.level.name;
            string directory = "";
            if (p.level.mapType == MapType.Home)
            {
                directory = Environment.CurrentDirectory + "/maps/home/" + mapname + ".lvl";
            }
            else if (p.level.mapType == MapType.MyMap)
            {
                string one = p.name.Substring(0, 1).ToLower();
                string two = p.name.Substring(1, 1).ToLower();
                string three = p.name.Substring(2, 1).ToLower();
                directory = Environment.CurrentDirectory + "/maps/mymaps/" + one + "/" + two + "/" + three + "/" + p.name.ToLower() + "/" + mapname + ".lvl";
            }
            else if (p.level.mapType == MapType.Freebuild)
            {
                directory = Environment.CurrentDirectory + "/levels/" + mapname + ".lvl";
            }
            else if (p.level.mapType == MapType.Zombie)
            {
                directory = Environment.CurrentDirectory + "/infection/maps/" + mapname + ".lvl";
            }
            else if (p.level.mapType == MapType.Lava)
            {
                directory = Environment.CurrentDirectory + "/lava/maps/" + mapname + ".lvl";
            }
            return directory;
        }


So now you can simply get the directory by using the following code:

Code: Select all
GetMapDir(p);

//For Example:
string file = GetMapDir(p);


I hope you find this useful! :D

PS: Took a while for me to understand how MyMaps were located :lol:

Re: Get map directory Method.

PostPosted: 27 Jun 2014, 21:14
by _Retaliate_
Nice. There's one case where this wouldn't work though, it would be when a developer uses a command to load a map from a custom directory, so if someone used, for instance,

Code: Select all
Level l = Level.Load("C:/Users/Guest", "level.lvl", p.name, MapType.Freebuild, false);
p.SendToMap(l);
string map = GetMapDir(p);

map would be equal to levels/level.lvl, which is not true.

I'm working on a fix.