void cmdClaimKit(BasePlayer player, string command, string[] args)
        {
            if (WipeBlocked(player))
            {
                return;
            }

            var userData = GetPlayerData(player.userID, SteamName(player));

            var i     = 0;
            var error = false;

            foreach (var s in Site)
            {
                if (error)
                {
                    break;
                }
                List <string> list = new List <string>(userData.Sites[s.Key].KitsNotClaimed);
                if (list.Count() > 0)
                {
                    foreach (var kit in list)
                    {
                        var flag = Kits?.Call("CanRedeemKit", player, kit, true);
                        if (flag is string || flag == null)
                        {
                            error = true;
                            break;
                        }
                        var succecss = Kits?.Call("GiveKit", player, kit);
                        if (succecss is string || succecss == null)
                        {
                            error = true;
                            break;
                        }
                        userData.Sites[s.Key].KitsNotClaimed.Remove(kit);
                    }
                }
                else
                {
                    ++i;
                }
            }

            if (i == 3)
            {
                MessageChat(player, "AlreadyClaimed");
            }
            else if (error)
            {
                MessageChat(player, "ErrorKit");
            }
            else
            {
                MessageChat(player, "RewardKit");
                SaveData(Users, "VoteData");
            }
        }
Beispiel #2
0
        void NPCKitGUI(BasePlayer player, ulong npc, string kit)
        {
            IsOpen(player.userID, true);
            CuiHelper.DestroyUi(player, NPCGUK);

            string description            = Lang("npcguikit");
            CuiElementContainer container = UI.Container(NPCGUK, UI.Color("242424", 1f), "0.1 0.1", "0.9 0.9", true, "Overlay");

            UI.Label(ref container, NPCGUK, UI.Color("#ffffff", 1f), description, 18, "0.23 0.92", "0.7 1");
            UI.Button(ref container, NPCGUK, UI.Color("#d85540", 1f), Lang("close"), 12, "0.92 0.93", "0.985 0.98", $"npcgui selkitclose");

            int           col  = 0;
            int           row  = 0;
            List <string> kits = new List <string>();

            Kits?.CallHook("GetKitNames", kits);
            if (kits == null)
            {
                return;
            }
            foreach (var kitinfo in kits)
            {
                if (row > 10)
                {
                    row = 0;
                    col++;
                }
                float[] posb = GetButtonPositionP(row, col);

                if (kit == null)
                {
                    kit = Lang("none");
                }
                if (kitinfo == kit)
                {
                    UI.Button(ref container, NPCGUK, UI.Color("#d85540", 1f), kitinfo, 12, $"{posb[0]} {posb[1]}", $"{posb[0] + ((posb[2] - posb[0]) / 2)} {posb[3]}", $"npcgui kitsel {npc.ToString()} {kitinfo}");
                }
                else
                {
                    UI.Button(ref container, NPCGUK, UI.Color("#424242", 1f), kitinfo, 12, $"{posb[0]} {posb[1]}", $"{posb[0] + ((posb[2] - posb[0]) / 2)} {posb[3]}", $"npcgui kitsel {npc.ToString()} {kitinfo}");
                }
                row++;
            }

            CuiHelper.AddUi(player, container);
        }
Beispiel #3
0
        private void Init()
        {
            Instance = this;

            JsonConvert.DefaultSettings = () => new JsonSerializerSettings
            {
                DefaultValueHandling = DefaultValueHandling.Ignore
            };

            _data.Kits    = Interface.Oxide.DataFileSystem.ReadObject <HashSet <Kit> >("Kits/Kits");
            _data.Players = Interface.Oxide.DataFileSystem.ReadObject <HashSet <PlayerData> >("Kits/PlayerData");

            permission.RegisterPermission("kits.admin", this);
            foreach (var kit in _data.Kits)
            {
                permission.RegisterPermission($"kits.{kit.Name}", this);
            }
        }
        void GetReward(BasePlayer player, string s)
        {
            MessageChat(player, "Thanks", s);

            var userData = GetPlayerData(player.userID, SteamName(player));

            userData.Sites[s].Votes++;
            if (userData.Sites[s].KitsNotClaimed.Count > 0)
            {
                userData.Sites[s].KitsNotClaimed.Clear();
            }

            var getdefault = true;

            foreach (var key in Rewards.Groups.Keys)
            {
                var g = key.Split('.')[0];
                if (g == "default")
                {
                    continue;
                }
                if (permission.UserHasGroup(player.UserIDString, g))
                {
                    getdefault = false;
                    break;
                }
            }

            var           totmoney = 0;
            var           totrp    = 0;
            var           kit      = false;
            var           kiterror = false;
            List <string> commands = new List <string>();

            foreach (var g in Rewards.Groups)
            {
                if (g.Value.Count == 0)
                {
                    continue;
                }
                var args = g.Key.Split('.');
                if ((args[0] == "default" && !getdefault && !_config.AllGroupsGetDefault) ||
                    !permission.UserHasGroup(player.UserIDString, args[0]))
                {
                    continue;
                }
                if (!permission.GroupExists(args[0]))
                {
                    PrintWarning(Lang("NoGroup", null, args[0]));
                    continue;
                }
                var m = 0;
                if (args.Length <= 1 || !int.TryParse(args[1], out m))
                {
                    PrintWarning(Lang("InvalidReward", null, g.Key));
                    continue;
                }
                if (userData.Sites[s].Votes < m || (userData.Sites[s].Votes % m) != 0)
                {
                    continue;
                }

                foreach (var r in g.Value)
                {
                    switch (r.Key)
                    {
                    case "money":
                    {
                        if (!Economics)
                        {
                            break;
                        }
                        var eco = Convert.ToDouble(r.Value);
                        Economics.Call("Deposit", player.userID, eco);
                        totmoney += Convert.ToInt32(r.Value);
                        break;
                    }

                    case "rp":
                    {
                        if (!ServerRewards)
                        {
                            break;
                        }
                        var p = Convert.ToInt32(r.Value);
                        ServerRewards.Call("AddPoints", new object[] { player.userID, p });
                        totrp += Convert.ToInt32(r.Value);
                        break;
                    }

                    case "kit":
                    {
                        if (!Kits || r.Value == "")
                        {
                            break;
                        }
                        var flag = Kits?.Call("CanRedeemKit", player, r.Value, true);
                        if (flag is string || flag == null || kiterror)
                        {
                            if (!kiterror)
                            {
                                kiterror = true;
                            }
                            userData.Sites[s].KitsNotClaimed.Add(r.Value);
                        }
                        else
                        {
                            var success = Kits?.Call("GiveKit", player, r.Value);
                            if (success is string || success == null)
                            {
                                kiterror = true;
                                userData.Sites[s].KitsNotClaimed.Add(r.Value);
                            }
                            else if (!kit)
                            {
                                kit = true;
                            }
                        }
                        break;
                    }

                    default:
                    {
                        rust.RunServerCommand(r.Value.Replace("$player.id", player.UserIDString).Replace("$player.name", player.displayName));
                        if (!commands.Contains(r.Key))
                        {
                            commands.Add(r.Key);
                        }
                        break;
                    }
                    }
                }
            }

            if (totmoney > 0)
            {
                MessageChat(player, "RewardCoins", totmoney);
            }
            if (totrp > 0)
            {
                MessageChat(player, "RewardRP", totrp);
            }
            if (kiterror)
            {
                MessageChat(player, "ErrorKits");
            }
            else if (kit)
            {
                MessageChat(player, "RewardKit");
            }
            foreach (var c in commands)
            {
                MessageChat(player, "RewardCommand", c);
            }

            try
            {
                var i       = Settings[s].Interval.Split('.').Select(n => Convert.ToInt32(n)).ToArray();
                var newdate = DateTime.Now + new TimeSpan(i[0], i[1], 0, 0);
                userData.Sites[s].ExpDate = newdate.ToString();
                SaveData(Users, "VoteData");
            }
            catch
            {
                MessageChat(player, "InvalidInterval");
                var newdate = DateTime.Now + new TimeSpan(1, 0, 0, 0);
                userData.Sites[s].ExpDate = newdate.ToString();
                SaveData(Users, "VoteData");
            }
        }
        void cmdVoteRewards(IPlayer player, string command, string[] args)
        {
            if (args.Length < 2)
            {
                player.Reply(Lang("MissingArg", player.Id));
                return;
            }

            var msg   = "";
            var error = "";

            switch (args[0].ToLower())
            {
            case "add":
            {
                if (args.Length < 3)
                {
                    error = Lang("MissingArg", player.Id);
                    break;
                }

                var p = args[1].ToLower();
                if (p == "group")
                {
                    var x = args[2].Split('.');
                    if (x.Length < 2 || !x[1].All(char.IsDigit))
                    {
                        error = Lang("InvalidValue", player.Id, args[2]);
                    }
                    else if (!permission.GroupExists(x[0]))
                    {
                        error = Lang("NoGroup", player.Id, x[0]);
                    }
                    else
                    {
                        Rewards.Groups.Add(args[2], new Dictionary <string, string>());
                        _group = args[2];
                        msg    = Lang("GroupAdded", player.Id, args[2]);
                    }
                }
                else
                {
                    if (_group == "")
                    {
                        error = Lang("NotSelected", player.Id);
                        break;
                    }

                    var rg = Rewards.Groups[_group];
                    if (rg.ContainsKey(p) || (p == "cmd" && rg.ContainsKey(args[2])))
                    {
                        error = Lang("AlreadyExists", player.Id);
                        break;
                    }
                    switch (p)
                    {
                    case "money":
                    {
                        if (!Economics)
                        {
                            error = Lang("NoPlugin", player.Id, "Economics");
                            break;
                        }
                        if (!args[2].All(char.IsDigit))
                        {
                            error = Lang("InvalidValue", player.Id, args[2]);
                        }
                        else
                        {
                            rg.Add("money", args[2]);
                        }
                        break;
                    }

                    case "rp":
                    {
                        if (!ServerRewards)
                        {
                            error = Lang("NoPlugin", player.Id, "ServerRewards");
                            break;
                        }
                        if (!args[2].All(char.IsDigit))
                        {
                            error = Lang("InvalidValue", player.Id, args[2]);
                        }
                        else
                        {
                            rg.Add("rp", args[2]);
                        }
                        break;
                    }

                    case "kit":
                    {
                        if (!Kits)
                        {
                            error = Lang("NoPlugin", player.Id, "Rust Kits");
                            break;
                        }
                        var flag = (bool)Kits?.Call("isKit", args[2]);
                        if (!flag)
                        {
                            error = Lang("NoKit", player.Id, args[2]);
                        }
                        else
                        {
                            rg.Add("kit", args[2]);
                        }
                        break;
                    }

                    case "cmd":
                    {
                        if (args.Length < 4)
                        {
                            error = Lang("MissingArg", player.Id);
                        }
                        else
                        {
                            rg.Add(args[2], args[3]);
                            p = args[2];
                        }
                        break;
                    }

                    default:
                    {
                        error = Lang("InvalidArg", player.Id, args[1]);
                        break;
                    }
                    }
                    if (error == "")
                    {
                        msg = Lang("RewardAdded", player.Id, p);
                    }
                }
                break;
            }

            case "remove":
            {
                var p = args[1].ToLower();
                if (p == "group")
                {
                    if (args.Length < 3)
                    {
                        error = Lang("MissingArg", player.Id);
                        break;
                    }

                    if (!Rewards.Groups.ContainsKey(args[2]))
                    {
                        error = Lang("NotFound", player.Id, args[2]);
                    }
                    else
                    {
                        Rewards.Groups.Remove(args[2]);
                        if (_group == args[2])
                        {
                            _group = "";
                        }
                        msg = Lang("GroupRemoved", player.Id, args[2]);
                    }
                }
                else
                {
                    if (_group == "")
                    {
                        error = Lang("NotSelected", player.Id);
                        break;
                    }

                    var rg = Rewards.Groups[_group];
                    if (p == "cmd")
                    {
                        if (args.Length < 3)
                        {
                            error = Lang("MissingArg", player.Id);
                        }
                        else if (!rg.ContainsKey(args[2]))
                        {
                            error = Lang("NoReward", player.Id, args[2]);
                        }
                        else
                        {
                            rg.Remove(args[2]);
                            p = args[2];
                        }
                    }
                    else
                    {
                        if (!rg.ContainsKey(p))
                        {
                            error = Lang("NoReward", player.Id, p);
                            break;
                        }
                        switch (p)
                        {
                        case "money":
                        {
                            rg.Remove("money");
                            break;
                        }

                        case "rp":
                        {
                            rg.Remove("rp");
                            break;
                        }

                        case "kit":
                        {
                            rg.Remove("kit");
                            break;
                        }

                        default:
                        {
                            error = Lang("InvalidArg", player.Id, args[1]);
                            break;
                        }
                        }
                    }
                    if (error == "")
                    {
                        msg = Lang("RewardRemoved", player.Id, p);
                    }
                }
                break;
            }

            case "edit":
            {
                if (args.Length < 3)
                {
                    error = Lang("MissingArg", player.Id);
                    break;
                }
                if (_group == "")
                {
                    error = Lang("NotSelected", player.Id);
                    break;
                }

                var p  = args[1].ToLower();
                var rg = Rewards.Groups[_group];
                if (p == "cmd")
                {
                    if (args.Length < 4)
                    {
                        error = Lang("MissingArg", player.Id);
                    }
                    else if (!rg.ContainsKey(args[2]))
                    {
                        error = Lang("NoReward", player.Id, args[2]);
                    }
                    else
                    {
                        rg[args[2]] = args[3];
                        msg         = Lang("Edited", player.Id, args[2], args[3]);
                    }
                }
                else
                {
                    if (!rg.ContainsKey(p))
                    {
                        error = Lang("NoReward", player.Id, p);
                        break;
                    }
                    switch (p)
                    {
                    case "money":
                    {
                        if (!args[2].All(char.IsDigit))
                        {
                            error = Lang("InvalidValue", player.Id, args[2]);
                        }
                        else
                        {
                            rg["money"] = args[2];
                        }
                        break;
                    }

                    case "rp":
                    {
                        if (!args[2].All(char.IsDigit))
                        {
                            error = Lang("InvalidValue", player.Id, args[2]);
                        }
                        else
                        {
                            rg["rp"] = args[2];
                        }
                        break;
                    }

                    case "kit":
                    {
                        var flag = (bool)Kits?.Call("isKit", args[2]);
                        if (!flag)
                        {
                            error = Lang("NoKit", player.Id, args[2]);
                        }
                        else
                        {
                            rg["kit"] = args[2];
                        }
                        break;
                    }

                    default:
                    {
                        error = Lang("InvalidArg", player.Id, args[1]);
                        break;
                    }
                    }
                    if (error == "")
                    {
                        msg = Lang("Edited", player.Id, args[1], args[2]);
                    }
                }
                break;
            }

            case "set":
            {
                if (!Rewards.Groups.ContainsKey(args[1]))
                {
                    error = Lang("NotFound", player.Id, args[1]);
                }
                else
                {
                    _group = args[1];
                    msg    = Lang("Selected", player.Id, args[1]);
                }
                break;
            }

            case "list":
            {
                switch (args[1].ToLower())
                {
                case "groups":
                    msg = Lang("GroupsList", player.Id, string.Join(", ", Rewards.Groups.Keys));
                    break;

                case "rewards":
                    if (_group == "")
                    {
                        error = Lang("NotSelected", player.Id);
                        break;
                    }
                    var list = new StringBuilder();
                    foreach (var r in Rewards.Groups[_group])
                    {
                        list.Append($"\n{r.Key}: {r.Value}");
                    }
                    msg = Lang("RewardsList", player.Id, _group, list.ToString());
                    break;

                default:
                {
                    error = Lang("InvalidArg", player.Id, args[1]);
                    break;
                }
                }
                break;
            }

            default:
            {
                error = Lang("InvalidArg", player.Id, args[0]);
                break;
            }
            }

            if (error != "")
            {
                player.Reply(error);
            }
            else
            {
                SaveData(Rewards, "Rewards");
                player.Reply(msg);
            }
        }
Beispiel #6
0
 public Kit this[string name] => Kits.SingleOrDefault(x => x.Name == name);