1. Hey I have a noob question about using dictionary's/config's hopefully someone can help me with

    This is in relation to my GunGame plugin and was hoping to get this done before I release it. The plugin works fine but I want to have each ranks weapons changeable in the config file. At the moment giving players items according to there ranks looks like this
    Code:
    if (playerLevel == 2)
                {
                    GiveItem(player, "smg.thompson", 1, player.inventory.containerBelt);
                    GiveItem(player, "ammo.pistol", 300, player.inventory.containerMain);
                    SendReply(player, "You are now Rank 2");
                }
    To make it configurable and easy for others to use I thought I could put the items in a dictionary and then what its set to in the config is what the player will get. So I have all the various levels in my config and have written out all the dictionarys for each level which look like this;
    Config
    Code:
    static string KitLVL2 = "Thompson";
    Dictionary
    Code:
    var Thompson = new Dictionary<string, object>();
                Thompson.Add("smg.thompson", 1);
                Thompson.Add("ammo.pistol", 200);
    and then I would give the player the items using something like this
    Code:
    var Lvl2 = (Dictionary<string, object>) KitLVL2;
    foreach (var item in Lvl2)
                    {
                        GiveItem(player, item.Key, (int)item.Value, player.inventory.containerBelt);
                    }
                    SendReply(player, "You are Rank 2");
    So I am sure you can see the error there :p I am unsure how to use the string from the config to call upon the dictionary with the same name.

    Any help would be greatly appreciated
     
  2. You are using your dictionary as a list pretty much, that's not really how they are meant to be used. The point of a dictionary is to provide access to items based on keys, but you are basically just using it to create a two-variable association and looping through them.

    Something like that:

    Code:
            class GunGameConfig
            {
                public List<GunGameLevel> levels = new List<GunGameLevel>();
            }        class KitEntry
            {
                public string shortname;
                public int amount;
            }        class GunKit
            {
                public string kitname;
                public List<KitEntry> items = new List<KitEntry>();
            }        class GunGameLevel
            {
                public int level;
                public GunKit kit;
                // + whatever else might relate to the level
            }        GunGameConfig g_config = new GunGameConfig();        public void SetupDefaultLevelsAndKits()
            {
                // LEVEL 1
                g_config.levels.Add(new GunGameLevel
                {
                    level = 1,
                    kit = new GunKit
                    {
                        kitname = "bow and arrow",
                        items = {
                                                    new KitEntry { shortname = "bow", amount = 1 },
                                                    new KitEntry { shortname = "arrow", amount = 20 }
                                                }
                    }
                });
               
                // LEVEL 2
                g_config.levels.Add(new GunGameLevel
                {
                    level = 2,
                    kit = new GunKit
                    {
                        kitname = "revolver",
                        items = {
                                                    new KitEntry { shortname = "revolver", amount = 1 },
                                                    new KitEntry { shortname = "ammo.9mm", amount = 20 }
                                                }
                    }
                });            // ETC
                Config.WriteConfig(g_config);
            }
    
     
  3. Thanks, I was using dictionary's because I saw something similar in another plugin, I'm learning as I go and everyone else's plugins are examples for me :p Making the plugin was easy, making everything adjustable is a pain in the ass haha
     
  4. That's the Pareto Principle for you: 20% of the effort gets it 80% done, and 80% of the effort is needed for the final 20%.