Пример #1
0
 public static void Modify(BasePlayer player, BaseEntity entity)
 {
     if (data.Limits.Any(x => x.Id == player.userID))
     {
         PlayerLimit info = data.Limits.Find(x => x.Id == player.userID) ?? null;
         if (!info.limit.Any(x => x.Name == entity.ShortPrefabName))
         {
             info.limit.Add(new Entities()
             {
                 Count = 1, Name = entity.ShortPrefabName
             });
         }
         else
         {
             Entities playerEnt = info.limit.Find(x => x.Name == entity.ShortPrefabName) ?? null;
             if (Cfg.MaxLimits.Any(x => x.Key == playerEnt.Name))
             {
                 if (playerEnt.Count == Cfg.MaxLimits[playerEnt.Name])
                 {
                     player.ChatMessage(LangMsg("MAX_ENTITIES"));
                     var item = ItemManager.CreateByName(entity.ShortPrefabName.Replace("_", "."), 1);
                     player.inventory.GiveItem(item, player.inventory.containerBelt);
                     player.Command(string.Concat(new object[4]
                     {
                         (object)"note.inv ",
                         (object)item.info.itemid,
                         (object)" ",
                         (object)"1"
                     }));
                     entity.KillMessage();
                     return;
                 }
                 playerEnt.Count += 1;
                 Plugin.Puts(playerEnt.Count.ToString());
                 return;
             }
         }
     }
 }
Пример #2
0
            public static void RunTimer(Types type)
            {
                float timeinterval = 1f;

                                #if RUST
                timeinterval = 4.5f;
                                #endif

                switch (type)
                {
                case Types.InGameTime:
                    if (InGame != null)
                    {
                        InGame.Destroy();
                    }
                    Plugin.Puts("The InGame timer has started");
                    AllTimers.Add(InGame = Plugin.timer.Repeat(timeinterval, 0, () =>
                    {
                        foreach (var cmd in Plugin.Config["InGameTime-Timer"] as Dictionary <string, object> )
                        {
                            if (Plugin.covalence.Server.Time.ToShortTimeString() == cmd.Key)
                            {
                                Plugin.covalence.Server.Command(cmd.Value.ToString());
                                Plugin.Puts(string.Format("ran CMD: {0}", cmd.Value));
                            }
                        }
                    }
                                                               ));
                    break;

                case Types.RealTime:
                    if (Real != null)
                    {
                        Real.Destroy();
                    }
                    Plugin.Puts("The RealTime timer has started");
                    AllTimers.Add(Real = Plugin.timer.Repeat(1, 0, () =>
                    {
                        foreach (var cmd in Plugin.Config["RealTime-Timer"] as Dictionary <string, object> )
                        {
                            if (System.DateTime.Now.ToString("HH:mm:ss") == cmd.Key.ToString())
                            {
                                Plugin.covalence.Server.Command(cmd.Value.ToString());
                                Plugin.Puts(string.Format("ran CMD: {0}", cmd.Value));
                            }
                        }
                    }
                                                             ));
                    break;

                case Types.Repeater:
                    if (Repeat != null)
                    {
                        Repeat.Destroy();
                    }
                    Plugin.Puts("The Repeat timer has started");
                    foreach (var cmd in Plugin.Config["TimerRepeat"] as Dictionary <string, object> )
                    {
                        Repeat = Plugin.timer.Repeat(Convert.ToSingle(cmd.Value), 0, () => {
                            Plugin.covalence.Server.Command(cmd.Key);
                            Plugin.Puts(string.Format("ran CMD: {0}", cmd.Key));
                        });
                    }
                    AllTimers.Add(Repeat);
                    break;

                case Types.TimerOnce:
                    if (Once != null)
                    {
                        Once.Destroy();
                    }
                    Plugin.Puts("The Timer-Once timer has started");
                    foreach (var cmd in Plugin.Config["TimerOnce"] as Dictionary <string, object> )
                    {
                        Once = Plugin.timer.Once(Convert.ToSingle(cmd.Value), () => {
                            Plugin.covalence.Server.Command(cmd.Key);
                            Plugin.Puts(string.Format("ran CMD: {0}", cmd.Key));
                        });
                    }
                    AllTimers.Add(Once);
                    break;
                }
            }
Пример #3
0
            public static void RunTimer(Types type, string timerName = "")
            {
                float timeinterval = 1f;

                #if RUST
                timeinterval = 4.5f;
                #endif

                Destroy(type);

                switch (type)
                {
                case Types.InGameTime:
                    Plugin.Puts($"The {type} timer has started");

                    var inGameTimers = Plugin.Config["InGameTime-Timer"] as Dictionary <string, object>;

                    if (inGameTimers == null)
                    {
                        return;
                    }

                    var inGame = Plugin.timer.Repeat(timeinterval, 0, () =>
                    {
                        foreach (var cmd in inGameTimers)
                        {
                            if (Plugin.covalence.Server.Time.ToShortTimeString() == cmd.Key)
                            {
                                Plugin.covalence.Server.Command(cmd.Value.ToString());
                                Plugin.Puts(string.Format("Ran CMD: {0}", cmd.Value));
                            }
                        }
                    });

                    AllTimers.Add(inGame, new TimerType(type, string.Empty));
                    break;

                case Types.RealTime:
                    Plugin.Puts($"The {type} timer has started");

                    var realTimeTimers = Plugin.Config["RealTime-Timer"] as Dictionary <string, object>;

                    if (realTimeTimers == null)
                    {
                        return;
                    }

                    var real = Plugin.timer.Repeat(1, 0, () =>
                    {
                        foreach (var cmd in realTimeTimers)
                        {
                            if (System.DateTime.Now.ToString("HH:mm:ss") == cmd.Key.ToString())
                            {
                                Plugin.covalence.Server.Command(cmd.Value.ToString());
                                Plugin.Puts(string.Format("Ran CMD: {0}", cmd.Value));
                            }
                        }
                    });

                    AllTimers.Add(real, new TimerType(type, string.Empty));
                    break;

                case Types.Repeater:
                    Plugin.Puts($"The {type} timer has started");

                    var repeatTimers = Plugin.Config["TimerRepeat"] as Dictionary <string, object>;

                    if (repeatTimers == null)
                    {
                        return;
                    }

                    foreach (var cmd in repeatTimers)
                    {
                        var repeat = Plugin.timer.Repeat(Convert.ToSingle(cmd.Value), 0, () => {
                            Plugin.covalence.Server.Command(cmd.Key);
                            Plugin.Puts(string.Format("Ran CMD: {0}", cmd.Key));
                        });

                        AllTimers.Add(repeat, new TimerType(type, string.Empty));
                    }
                    break;

                case Types.TimerOnce:
                    if (string.IsNullOrEmpty(timerName))
                    {
                        Plugin.Puts($"The {type} timer has started");
                    }

                    var onceTimers = Plugin.Config["TimerOnce"] as List <object>;

                    if (onceTimers == null)
                    {
                        return;
                    }

                    foreach (var onceTimer in onceTimers)
                    {
                        var timer = onceTimer as Dictionary <string, object>;

                        if (timer == null || timer.Count != 2)
                        {
                            continue;
                        }

                        string name = timer["Name"]?.ToString();

                        if (!string.IsNullOrEmpty(timerName))
                        {
                            if (name != timerName)
                            {
                                continue;
                            }
                        }

                        if (!string.IsNullOrEmpty(timerName))
                        {
                            Plugin.Puts($"The {type} timer '{timerName}' has started");
                        }

                        var commands = timer["Commands"] as Dictionary <string, object>;

                        if (commands == null)
                        {
                            continue;
                        }

                        foreach (var cmd in commands)
                        {
                            var once = Plugin.timer.Once(Convert.ToSingle(cmd.Value), () =>
                            {
                                Plugin.covalence.Server.Command(cmd.Key);
                                Plugin.Puts(string.Format("Ran CMD: {0}", cmd.Key));
                            });

                            AllTimers.Add(once, new TimerType(type, name));
                        }
                    }
                    break;

                case Types.TimerWeekday:
                    var weekdayTimers = Plugin.Config["TimerWeekday"] as Dictionary <string, object>;

                    if (weekdayTimers == null)
                    {
                        return;
                    }

                    Plugin.Puts("The Weekday timer has started");

                    foreach (var cmd in weekdayTimers)
                    {
                        var week = Plugin.timer.Repeat(1, 0, () =>
                        {
                            List <string> elements = cmd.Key.ToString().Split(' ').ToList();
                            DateTime today         = DateTime.Now;

                            if (today.ToString("HH:mm:ss") == elements[0] && CheckWeek(today, elements[1], elements[2]))
                            {
                                Plugin.covalence.Server.Command(cmd.Value.ToString());
                                Plugin.Puts(string.Format("ran CMD: {0}", cmd.Value));
                            }
                        });
                        AllTimers.Add(week, new TimerType(type, string.Empty));
                    }
                    break;
                }
            }