示例#1
0
        private void Kit(BasePlayer player, string kit)
        {
            if (player == null)
            {
                return;
            }

            PlayerInfo info = playerInfo[player.userID];

            // Check if the kit exists
            if (!kitItems.ContainsKey(kit))
            {
                player.ChatMessage("<color=#d00>ERROR</color> That kit does not exists.");
                return;
            }

            KitItem item = kitItems[kit];

            // Check for the permissions
            if (!info.HasSubscription($"kit_{kit}") && !AllowKit(player, kit))
            {
                player.ChatMessage("<color=#d00>ERROR</color> You dont have permissions for this kit, you can buy them in the shop.");
                return;
            }

            // Check for the cooldown
            int cooldown = info.HasCooldown($"kit_{kit}");

            if (cooldown > 0)
            {
                player.ChatMessage($"<color=#d00>ERROR</color> Wait {cooldown} seconds.");
                return;
            }

            // Add the cooldown
            info.AddCooldown($"kit_{kit}", item.cooldown);

            // Execute the command
            string[] commands = item.command.Split('|');
            foreach (string command in commands)
            {
                GameLimits.ExecuteCommand(player, command);
            }

            // Add logging
            MInsert(MBuild("INSERT INTO kits_history (user_id, kit_id) VALUES (@0, @1);", info.id, item.id));
        }
示例#2
0
        public void BuyItem(BasePlayer player, string productId)
        {
            // Check if the item exists
            if (!ShopItems.ContainsKey(productId))
            {
                return;
            }

            PlayerInfo info    = playerInfo[player.userID];
            ShopItem   product = ShopItems[productId];

            // Check if there are enough reward points on the users account
            MQuery(MBuild("SELECT SUM(points) AS points FROM reward_points WHERE user_id=@0;", info.id), records =>
            {
                if (records.Count == 0)
                {
                    Puts("Failed to fetch when buying item");
                    return;
                }

                int points = 0;
                if (records[0]["points"].ToString().Length > 0)
                {
                    points = Convert.ToInt32(records[0]["points"]);
                }

                if (product.price > points)
                {
                    UpdateInfoGUI(player, $"<color=#B70E30>Not enough Reward Points</color> visit https://rust.gamelimits.com/ to buy Reward Points.");
                    return;
                }

                MInsert(MBuild("INSERT INTO reward_points (user_id, points, description) VALUES (@0, @1, @2);", info.id, -product.price, $"Bought {product.name} from the shop"), done =>
                {
                    string[] commands = product.command.Split('|');
                    foreach (string command in commands)
                    {
                        GameLimits.ExecuteCommand(player, command);
                    }

                    info.LoadRewardPoints(() => UpdateInfoGUI(player, $"<color=#0E84B7>Bought</color> {product.name}"));
                });

                MInsert(MBuild("INSERT INTO shop_history (user_id, shop_item_id) VALUES (@0, @1);", info.id, product.id));
            });
        }