示例#1
0
文件: Main.cs 项目: RavageV/outbreak
        public static void AddItem([FromSource] CitizenFX.Core.Player Source, string Name, int Amount)
        {
            if (!Enum.IsDefined(typeof(Weapon.Hash), Name) && Inventory.Items.ContainsKey(Name))
            {
                string PlayerInventory = Inventory.GetInventory(Source);
                var    Dictionary      = JsonConvert.DeserializeObject <Dictionary <string, dynamic> >(PlayerInventory);

                bool found = false;
                foreach (var Item in Dictionary)
                {
                    if (Item.Key == Name)
                    {
                        Dictionary[Name] += Amount;
                        found             = true;
                        break;
                    }
                }
                if (!found)
                {
                    Dictionary.Add(Name, Amount);
                }

                string NewInventory = JsonConvert.SerializeObject(Dictionary);
                Inventory.UpdateInventory(Source, NewInventory);
            }
            else
            {
                ChatMessage.Error(Source, $"Item [{Name}] does not exist in table \"items\" database!");
            }
        }
示例#2
0
文件: Main.cs 项目: RavageV/outbreak
        public static void AddWeapon([FromSource] CitizenFX.Core.Player Source, string Name, int Ammo = 0, dynamic Component = null, int Tint = 1)
        {
            string PlayerInventory = Inventory.GetInventory(Source);
            var    Dictionary      = JsonConvert.DeserializeObject <Dictionary <string, dynamic> >(PlayerInventory);

            if (Enum.IsDefined(typeof(Weapon.Hash), Name) && Inventory.Items.ContainsKey(Name))
            {
                bool found = false;
                foreach (var Item in Dictionary)
                {
                    if (Item.Key == Name)
                    {
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    dynamic Data = new ExpandoObject();
                    Data.Ammo       = Ammo;
                    Data.Components = Component; //Not ready yet
                    if (Tint == null)            //Not ready yet
                    {
                        Data.Tint = 0;
                    }                 //Not ready yet
                    else
                    {
                        Data.Tint = Tint;
                    }                         //Not ready yet

                    Dictionary.Add(Name, Data);
                }
            }
            else
            {
                ChatMessage.Error(Source, $"Weapon [{Name}] does not exist in table \"items\" database!");
            }

            string NewInventory = JsonConvert.SerializeObject(Dictionary);

            Inventory.UpdateInventory(Source, NewInventory);
        }
示例#3
0
        public Admin()
        {
            Events();

            Command.Register("giveitem", "Admin", new Action <CitizenFX.Core.Player, List <object>, string>((Source, Arguments, Raw) =>
            {
                try
                {
                    if (Arguments.ToList().Count() < 1)
                    {
                        ChatMessage.Error(Source, "Missing arguments to define");
                    }
                    else if (Arguments.ToList().Count() < 3)
                    {
                        Player.AddItem(Source, Arguments[0].ToString(), Convert.ToInt32(Arguments[1]));
                    }
                    else
                    {
                        CitizenFX.Core.Player TargetPlayer = Players.AsEnumerable().ToList().FirstOrDefault(k => k.Handle == Arguments[2].ToString());
                        if (TargetPlayer == null)
                        {
                            ChatMessage.Error(Source, "Player ID not found");
                        }
                        else
                        {
                            Player.AddItem(TargetPlayer, Arguments[0].ToString(), Convert.ToInt32(Arguments[1]));
                        }
                    }
                }
                catch { }
            }), "Add items to player inventory",
                             new { name = "Item", help = "Item to be added" },
                             new { name = "Amount", help = "Amount of items" },
                             new { name = "ID", help = "Player ID" });

            Command.Register("removeitem", "Admin", new Action <CitizenFX.Core.Player, List <object>, string>((Source, Arguments, Raw) =>
            {
                try
                {
                    if (Arguments.ToList().Count() < 1)
                    {
                        ChatMessage.Error(Source, "Missing arguments to define");
                    }
                    else if (Arguments.ToList().Count() < 3)
                    {
                        Player.RemoveItem(Source, Arguments[0].ToString(), Convert.ToInt32(Arguments[1]));
                    }
                    else
                    {
                        CitizenFX.Core.Player TargetPlayer = Players.AsEnumerable().ToList().FirstOrDefault(k => k.Handle == Arguments[2].ToString());
                        if (TargetPlayer == null)
                        {
                            ChatMessage.Error(Source, "Player ID not found");
                        }
                        else
                        {
                            Player.RemoveItem(TargetPlayer, Arguments[0].ToString(), Convert.ToInt32(Arguments[1]));
                        }
                    }
                }
                catch { }
            }), "Remove items from player inventory",
                             new { name = "Item", help = "Item to be removed" },
                             new { name = "Amount", help = "Amount of items" },
                             new { name = "ID", help = "Player ID" });

            Command.Register("giveweapon", "Admin", new Action <CitizenFX.Core.Player, List <object>, string>((Source, Arguments, Raw) =>
            {
                try
                {
                    if (Arguments.ToList().Count() < 1)
                    {
                        ChatMessage.Error(Source, "Missing arguments to define");
                    }
                    else if (Arguments.ToList().Count() < 3)
                    {
                        Player.AddWeapon(Source, Arguments[0].ToString(), Convert.ToInt32(Arguments[1]));
                    }
                    else
                    {
                        CitizenFX.Core.Player TargetPlayer = Players.AsEnumerable().ToList().FirstOrDefault(k => k.Handle == Arguments[2].ToString());
                        if (TargetPlayer == null)
                        {
                            ChatMessage.Error(Source, "Player ID not found");
                        }
                        else
                        {
                            Player.AddWeapon(TargetPlayer, Arguments[0].ToString(), Convert.ToInt32(Arguments[1]));
                        }
                    }
                }
                catch { }
            }), "Add Weapon to player inventory",
                             new { name = "Weapon", help = "Weapon name" },
                             new { name = "Ammo", help = "Weapon ammo" },
                             new { name = "ID", help = "Player ID" });

            Command.Register("removeweapon", "Admin", new Action <CitizenFX.Core.Player, List <object>, string>((Source, Arguments, Raw) =>
            {
                try
                {
                    if (Arguments.ToList().Count() < 1)
                    {
                        ChatMessage.Error(Source, "Missing arguments to define");
                    }
                    else if (Arguments.ToList().Count() < 3)
                    {
                        Player.RemoveWeapon(Source, Arguments[0].ToString());
                    }
                    else
                    {
                        CitizenFX.Core.Player TargetPlayer = Players.AsEnumerable().ToList().FirstOrDefault(k => k.Handle == Arguments[2].ToString());
                        if (TargetPlayer == null)
                        {
                            ChatMessage.Error(Source, "Player ID not found");
                        }
                        else
                        {
                            Player.RemoveWeapon(TargetPlayer, Arguments[0].ToString());
                        }
                    }
                }
                catch { }
            }), "Remove Weapon from player inventory",
                             new { name = "Weapon", help = "Weapon name" },
                             new { name = "Ammo", help = "Weapon ammo" },
                             new { name = "ID", help = "Player ID" });
        }