Get map directory Method.

Get map directory Method.

Postby Leeizazombie » 27 Jun 2014, 01:41

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:
Owner of:
LeeIzaZombie Freebuild and Lava Survival V2 (Shut Down and updated)
LeeIzaZombie Survival (Comming back soon)

Contact:
Skype: leeizazombie
IRC: irc.geekshed.net, #leeizazombie, #mcclassichosting
User avatar
Leeizazombie
 
Posts: 536
Joined: 10 Jun 2013, 17:45
Location: Ireland.

Re: Get map directory Method.

Postby _Retaliate_ » 27 Jun 2014, 21:14

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.
Image
_Retaliate_
 
Posts: 68
Joined: 26 Sep 2013, 11:16


Return to Drafts

Who is online

Users browsing this forum: No registered users and 1 guest

cron