错误CS0030无法将类型'char'转换为'string'

时间:2018-03-30 19:17:55

标签: c# compiler-errors

嗨所以我试图让这个读取游戏的配置字符串我试图制作一个插件,奖励列表中的人这是我的错误。

我试了很多东西我得到了一堆不同的错误,我只是想弄清楚如何做到这一点。

  

严重级代码描述项目文件行抑制状态   错误CS0030无法将类型'char'转换为'string'PerkPlugin C:\ Users \ f \ Downloads \ Smod2-master \ Smod2-master \ ExamplePlugin \ PerkPlugin \ PerkPlugin.cs 73 Active

using Smod2;

using Smod2.API;

using Smod2.Events;

using System;

namespace Smod.PerkPlugin
{
    class RoundStartHandler : IEventRoundStart
    {
        private Plugin plugin;
        private IConfigFile config;
        public RoundStartHandler(Plugin plugin)
        {
            this.plugin = plugin;
        }

        public void OnRoundStart(Server server)
        {

            string[] ItemString = new string[15];
            int[,,] ItemList = new int[15, 8, 16];
            int[] maxitem = new int[15];
            int[,] maxitemchance = new int[15, 8];

            ItemString[(int)Classes.CLASSD] = plugin.GetConfigString("default_item_classd");

            ItemString[(int)Classes.NTF_SCIENTIST] = plugin.GetConfigString("default_item_ntfscientist");

            ItemString[(int)Classes.SCIENTIST] = plugin.GetConfigString("default_item_scientist");

            ItemString[(int)Classes.CHAOS_INSUGENCY] = plugin.GetConfigString("default_item_ci");

            ItemString[(int)Classes.NTF_LIEUTENANT] = plugin.GetConfigString("default_item_lieutenant");

            ItemString[(int)Classes.NTF_COMMANDER] = plugin.GetConfigString("default_item_commander");

            ItemString[(int)Classes.NTF_GUARD] = plugin.GetConfigString("default_item_guard");

            ItemString[(int)Classes.TUTORIAL] = plugin.GetConfigString("default_item_tutorial");

            for (int i = 0; i < 15; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    for (int k = 0; k < 16; k++)
                    {
                        ItemList[i, j, k] = -1;
                    }
                }
                if (ItemString[i] != "-1" && ItemString[i] != null)
                {
                    ItemString[i].Replace(" ", string.Empty);
                    string[] items = ItemString[i].Split(',');
                    for (maxitem[i] = 0; maxitem[i] < items.Length; maxitem[i]++)
                    {
                        string[] itemchance = items[maxitem[i]].Split(':');
                        for (maxitemchance[i, maxitem[i]] = 0; maxitemchance[i, maxitem[i]] < itemchance.Length; maxitemchance[i, maxitem[i]]++)
                        {
                            ItemList[i, maxitem[i], maxitemchance[i, maxitem[i]]] = System.Convert.ToInt32(itemchance[maxitemchance[i, maxitem[i]]]);
                        }
                    }
                }
            }
            foreach (Player player in server.GetPlayers())
            {
                string playerIP = player.IpAddress;
                string[] playerIPSplit = playerIP.Split(':');
                playerIP = (playerIPSplit.Length >= 1 ? playerIPSplit[playerIPSplit.Length - 1] : playerIP).Trim();
                string perks = plugin.GetConfigString("perk_ips");
                foreach (string perkIP in plugin.GetConfigString("perk_ips"))
                {
                    string[] perkIPSplit = perkIP.Split(':');
                    string endperkIP = (perkIPSplit.Length >= 1 ? perkIPSplit[perkIPSplit.Length - 1] : perkIP).Trim();

                    if (playerIP.Equals(endperkIP))
                    {


                        int classtype = (int)player.Class.ClassType;
                        if (classtype > -1 && classtype < 15)
                        {
                            foreach (Item item in player.GetInventory())
                            {
                                item.Remove();
                            }

                            for (int i = 0; i < maxitem[classtype]; i++)
                            {
                                Random rd = new Random();
                                int result = ItemList[classtype, i, rd.Next(0, maxitemchance[classtype, i])];
                                if (result != -1)
                                {
                                    player.GiveItem((ItemType)result);
                                }
                            }
                        }
                    }


                }
            }
        }
    }

}

感谢您的帮助:)

1 个答案:

答案 0 :(得分:4)

看起来像这一行:

foreach (string perkIP in plugin.GetConfigString("perk_ips"))

让你迭代一个字符串,这会产生一个字符。似乎GetConfigString没有返回字符串集合,只返回一个字符串。