Unity - IndexOutOfRangeException: Array index is out of range

перелопатил кучу вопросов по данной тематике, ни одно из решений мне не подошло или не сработало. Дело в том что скрипт то работает, но иногда при выполнении выдает эту ошибку. Вот скрипт полностью:

using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using Oxide.Core;
using Oxide.Core.Plugins;
using Oxide.Core.Configuration;
using Oxide.Plugins;
using UnityEngine;
using RustExtended;

namespace Oxide.Plugins{
    [Info("Warps", "XBOCT", "1.0.2")]
    [Description("Система варпов")]
    class Warps : RustLegacyPlugin
    {
        static float teleportTime       = 15f;//Время телепорта в секундах
        static float TimeAntiSpawnKill  = 30f;//Антикилл время после тп (не работает)
        static string chatTag           = "Варпы";//Префикс в чате
        static int warpсd               = 15;//Перезарядка телепорта в секундах
        static int pointsPerWarp        = 5;//Количество точек на один варп
        const string permTeleportDellay = "warps.delay";
        
        private Core.Configuration.DynamicConfigFile Data;
        string[] warps = {"small","medvega","hangar","big","factory","central","hackerka","bochki","ruins","sfera"};
        string[] wnames = {"Смал РТ","Медвега","Ангар","Биг РТ","Фактори","Центр","Хакерка","Бочки","Руины","Сфера"};//Сюда добавлять новые варпы. Названия варпа по русски обязательно
        
        static Dictionary<string, object[]> NamesLocations = GetNamesLocations();
        static Dictionary<string, object[]> GetNamesLocations(){
            var dict = new Dictionary<string, object[]>();
            dict.Add("small1", new object[] { 6000.3f, 381.3f, -3613.3f });
            dict.Add("small2", new object[] { 6143.7f, 376.4f, -3549.2f });
            dict.Add("small3", new object[] { 6102.1f, 376.0f, -3642.4f });
            dict.Add("small4", new object[] { 6000.3f, 381.3f, -3613.3f });
            dict.Add("small5", new object[] { 6066.8f, 376.4f, -3488.7f });
            dict.Add("medvega1", new object[] { 4577.6f, 457.6f, -3825.3f });
            dict.Add("medvega2", new object[] { 4755.8f, 439.3f, -3731.5f });
            dict.Add("medvega3", new object[] { 5005.5f, 420.7f, -3792.2f });
            dict.Add("medvega4", new object[] { 4980.5f, 423.0f, -4000.9f });
            dict.Add("medvega5", new object[] { 4775.8f, 460.5f, -4129.6f });
            dict.Add("hangar1", new object[] { 6568.6f, 367.5f, -4306.9f });
            dict.Add("hangar2", new object[] { 6829.5f, 339.1f, -4079.7f });
            dict.Add("hangar3", new object[] { 6907.7f, 320.7f, -4382.9f });
            dict.Add("hangar4", new object[] { 6731.6f, 348.0f, -4280.6f });
            dict.Add("hangar5", new object[] { 6482.8f, 380.7f, -4091.9f });
            dict.Add("big1", new object[] { 5269.8f, 369.6f, -4768.0f });
            dict.Add("big2", new object[] { 5180.2f, 363.8f, -4913.0f });
            dict.Add("big3", new object[] { 5347.3f, 363.2f, -4763.6f });
            dict.Add("big4", new object[] { 5165.2f, 370.1f, -4750.8f });
            dict.Add("big5", new object[] { 5348.2f, 366.0f, -4714.8f });
            dict.Add("factory1", new object[] { 6318.8f, 366.0f, -4770.2f });
            dict.Add("factory2", new object[] { 6284.9f, 360.2f, -4616.9f });
            dict.Add("factory3", new object[] { 6348.8f, 360.2f, -4520.4f });
            dict.Add("factory4", new object[] { 6449.3f, 361.1f, -4626.6f });
            dict.Add("factory5", new object[] { 6340.8f, 360.5f, -4679.9f });
            dict.Add("central1", new object[] { 5849.2f, 406.3f, -4139.1f });
            dict.Add("central2", new object[] { 5967.6f, 408.8f, -4270.2f });
            dict.Add("central3", new object[] { 6159.2f, 378.7f, -4362.2f });
            dict.Add("central4", new object[] { 6281.4f, 430.6f, -4292.8f });
            dict.Add("central5", new object[] { 6294.3f, 417.9f, -4143.0f });
            dict.Add("hackerka1", new object[] { 5520.6f, 434.3f, -2753.7f });
            dict.Add("hackerka2", new object[] { 5684.5f, 393.4f, -2142.2f });
            dict.Add("hackerka3", new object[] { 4717.7f, 478.2f, -2907.6f });
            dict.Add("hackerka4", new object[] { 4976.9f, 462.2f, -2660.9f });
            dict.Add("hackerka5", new object[] { 5402.0f, 443.8f, -2591.5f });
            dict.Add("bochki1", new object[] { 6629.2f, 353.0f, -3856.7f });
            dict.Add("bochki2", new object[] { 6867.7f, 353.0f, -3867.9f });
            dict.Add("bochki3", new object[] { 6796.6f, 353.8f, -3983.3f });
            dict.Add("bochki4", new object[] { 6608.7f, 360.8f, -3725.1f });
            dict.Add("bochki5", new object[] { 6552.0f, 361.1f, -3957.9f });
            dict.Add("ruins1", new object[] { 6055.60f, 395.60f, -2350.80f });
            dict.Add("ruins2", new object[] { 6021.30f, 407.40f, -2440.90f });
            dict.Add("ruins3", new object[] { 6055.60f, 395.60f, -2350.80f });
            dict.Add("ruins4", new object[] { 6021.30f, 407.40f, -2440.90f });
            dict.Add("ruins5", new object[] { 6055.60f, 395.60f, -2350.80f });
            dict.Add("sfera1", new object[] { 3172.80f, 640.70f, -4853.40f });
            dict.Add("sfera2", new object[] { 3092.90f, 640.70f, -4775.50f });
            dict.Add("sfera3", new object[] { 2996.90f, 660.82f, -4817.00f });
            dict.Add("sfera4", new object[] { 3024.30f, 700.00f, -4952.40f });
            dict.Add("sfera5", new object[] { 3125.70f, 700.00f, -4959.50f });
            //wood+farm 1591.50f, 354.90f, 2295.80f
            return dict;
        }
        
        void OnPlayerConnected(NetUser netuser)
        {
            string filename = string.Format("warp-{0}", netuser.userID.ToString());
            Core.Configuration.DynamicConfigFile ConfigurationData = Interface.GetMod().DataFileSystem.GetDatafile(filename);
        }
        
        void Init(){
            permission.RegisterPermission(permTeleportDellay, this);
        }
        
        protected override void LoadDefaultConfig(){}
        
        void TeleportPlayer(NetUser netuser, Vector3 location){
            var management = RustServerManagement.Get();
            management.TeleportPlayerToWorld(netuser.playerClient.netPlayer, location);
        }
        
        bool AcessDellay(NetUser netuser){
            if(netuser.CanAdmin())return true;
            if(permission.UserHasPermission(netuser.userID.ToString(), permTeleportDellay))return true;
            return false;
        }
        
        int getUnixDate(){
            return (int)(DateTime.Now - new DateTime(1970, 1, 1)).TotalSeconds;
        }
        
        void HelpLocationsNames(NetUser netuser){
            rust.SendChatMessage(netuser, chatTag, "===== [color Lime] Список варпов [color clear]========");
            foreach(var pair in warps)
            rust.SendChatMessage(netuser, chatTag, "Используйте /w [color red]\"[color Green]" + pair + "[color red]\"");
            rust.SendChatMessage(netuser, chatTag, "===========================");
        }
        
        [ChatCommand("w")]
        void cmdWarp(NetUser netuser, string command, string[] args)
        {
            UserData userData = Users.GetBySteamID(netuser.userID);
            
            if(args.Length == 0){HelpLocationsNames(netuser);}
            if(args.Length == 1){
                string warpSubName = args[0];
                int warpNum = Array.IndexOf(warps, args[0]);
                string warpName = wnames[warpNum];
                Puts("Игрок: "+netuser+" варпнулся в зону под номером: "+warpNum+" с названием: "+warpName+" и тех. названием: "+warpSubName);
                if(NamesLocations.ContainsKey(warpSubName+"1"))
                {
                    string id = netuser.userID.ToString();
                    int unixNow = getUnixDate();
                    int cdEnd = unixNow + warpсd;
                    
                    string filename = string.Format("warp-{0}", id);
                    Core.Configuration.DynamicConfigFile ConfigurationData = Interface.GetMod().DataFileSystem.GetDatafile(filename);
                    
                    if(ConfigurationData["cd"] == null)
                    {
                        ConfigurationData["cd"] = cdEnd;
                    } else {
                        if(!AcessDellay(netuser)){
                            int cd = Convert.ToInt32(ConfigurationData["cd"].ToString());
                            if(unixNow > cd)
                            {
                                rust.Notice(netuser, "Вы будете телепортированы в " + warpName + " через " + teleportTime + " сек.", "➲");//warpSubName
                                ConfigurationData["cd"] = unixNow + warpсd;
                                timer.Once(teleportTime, ()=>{
                                    if(netuser.playerClient == null)return;
                                    int randomInt = UnityEngine.Random.Range(1, pointsPerWarp+1);
                                    object[] objectLocation = NamesLocations[warpSubName+randomInt.ToString()];
                                    Vector3 location = new Vector3((float)objectLocation[0], (float)objectLocation[1], (float)objectLocation[2]);
                                    TeleportPlayer(netuser, location);
                                    rust.Notice(netuser, "Вы были телепортированы в " + warpName + ".", "➲");//warpSubName
                                });
                            } else {
                                int toNext = cd - unixNow;
                                int min = toNext / 60;
                                int sec = toNext - min * 60;
                                string timeString = "";
                                if(min > 0)
                                {
                                    timeString = " " + min.ToString() + " мин. " + sec.ToString() + " сек.";
                                }
                                else
                                {
                                    timeString = " " + sec.ToString() + " сек.";
                                }
                                rust.Notice(netuser, "До следующей телепортации осталось " + timeString, "➲");
                            }
                        } else {
                            if(netuser.playerClient == null)return;
                            int randomInt = UnityEngine.Random.Range(1, pointsPerWarp+1);
                            object[] objectLocation = NamesLocations[warpSubName+randomInt.ToString()];
                            Vector3 location = new Vector3((float)objectLocation[0], (float)objectLocation[1], (float)objectLocation[2]);
                            TeleportPlayer(netuser, location);
                            rust.Notice(netuser, "Вы были телепортированы в " + warpName + ".", "➲");//warpSubName
                        }
                    }
                    Interface.GetMod().DataFileSystem.SaveDatafile(filename);
                } else {
                    rust.Notice(netuser, "Точка варпа \"" + warpName + "\" найдена!", "➲");//warpSubName
                }
                //Дополнительно
                /*if(args[0].ToString() == "sfera" || args[0].ToString() == "ruins")
                {
                    rust.Notice(netuser, "Точка варпа \"" + warpName + "\" пока на ремонте! Инфо в группе vk.com/megapub2020", "➲");
                }
                if(args[0].ToString() == "random")
                {
                    //возможно добавлю /w random - телепорт в случайный варп
                }*/
            }
        }
    }
}

Найдите в коде такую (127) строку int warpNum = Array.IndexOf(warps, args[0]); тут я устанавливаю номер по порядку из одного массива, что бы потом можно было по тому же номеру взять значение из другого. Массивы по количеству значений одинаковы, то есть он не может присвоить ему число большее чем есть в массиве. Но ошибка почему то вылазит (не всегда, куда чаще все успешно выполняется)


Ответы (0 шт):