示例#1
0
        private async void LoadDatabase()
        {
            await Delay(5000);

            Exports["ghmattimysql"].execute("SELECT * FROM loadout;", new object[] {  }, new Action <dynamic>((loadout) =>
            {
                if (loadout.Count != 0)
                {
                    WeaponClass wp;
                    foreach (var row in loadout)
                    {
                        try
                        {
                            JObject ammo = Newtonsoft.Json.JsonConvert.DeserializeObject(row.ammo.ToString());
                            JArray comp  = Newtonsoft.Json.JsonConvert.DeserializeObject(row.components.ToString());
                            int charId   = -1;
                            if (row.charidentifier != null)
                            {
                                charId = row.charidentifier;
                            }
                            Dictionary <string, int> amunition = new Dictionary <string, int>();
                            List <string> components           = new List <string>();
                            foreach (JProperty ammos in ammo.Properties())
                            {
                                amunition.Add(ammos.Name, int.Parse(ammos.Value.ToString()));
                            }
                            foreach (JToken x in comp)
                            {
                                components.Add(x.ToString());
                            }

                            bool auused = false;
                            if (row.used == 1)
                            {
                                auused = true;
                            }
                            wp = new WeaponClass(int.Parse(row.id.ToString()), row.identifier.ToString(), row.name.ToString(), amunition, components, auused, charId);
                            ItemDatabase.userWeapons[wp.getId()] = wp;
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(ex.Message);
                        }
                    }
                }
            }));
        }
        private void getInventory([FromSource] Player source)
        {
            string steamId = "steam:" + source.Identifiers["steam"];

            Debug.WriteLine(steamId);

            Exports["ghmattimysql"].execute("SELECT identifier,inventory FROM characters WHERE identifier = ?;", new[] { steamId }, new Action <dynamic>((uinvento) =>
            {
                if (uinvento.Count == 0)
                {
                    Debug.WriteLine("No users inventory");
                    Dictionary <string, ItemClass> items = new Dictionary <string, ItemClass>();
                    ItemDatabase.usersInventory.Add(steamId, items); // Si no existe le metemos en la caché para tenerlo preparado para recibir cosas
                }
                else
                {
                    //Carga del inventario
                    Dictionary <string, ItemClass> userinv = new Dictionary <string, ItemClass>();
                    List <WeaponClass> userwep             = new List <WeaponClass>();
                    if (uinvento[0].inventory != null)
                    {
                        dynamic thing = Newtonsoft.Json.JsonConvert.DeserializeObject <dynamic>(uinvento[0].inventory);
                        foreach (dynamic itemname in ItemDatabase.items)
                        {
                            if (thing[itemname.item.ToString()] != null)
                            {
                                ItemClass item = new ItemClass(int.Parse(thing[itemname.item.ToString()].ToString()), int.Parse(itemname.limit.ToString()),
                                                               itemname.label, itemname.item, itemname.type, itemname.usable, itemname.can_remove);
                                userinv.Add(itemname.item.ToString(), item);
                            }
                        }
                        ItemDatabase.usersInventory[steamId] = userinv;
                    }
                    else
                    {
                        ItemDatabase.usersInventory[steamId] = userinv;
                    }

                    source.TriggerEvent("vorpInventory:giveInventory", uinvento[0].inventory);
                }
            }));

            Exports["ghmattimysql"].execute("SELECT * FROM loadout WHERE identifier = ?;", new[] { steamId }, new Action <dynamic>((weaponsinvento) =>
            {
                if (weaponsinvento.Count == 0)
                {
                }
                else
                {
                    WeaponClass wp;
                    foreach (var row in weaponsinvento)
                    {
                        JObject ammo = Newtonsoft.Json.JsonConvert.DeserializeObject(row.ammo.ToString());
                        JArray comp  = Newtonsoft.Json.JsonConvert.DeserializeObject(row.components.ToString());
                        Dictionary <string, int> amunition = new Dictionary <string, int>();
                        List <string> components           = new List <string>();
                        foreach (JProperty ammos in ammo.Properties())
                        {
                            //Debug.WriteLine(ammos.Name);
                            amunition.Add(ammos.Name, int.Parse(ammos.Value.ToString()));
                        }
                        foreach (JToken x in comp)
                        {
                            components.Add(x.ToString());
                        }

                        bool auused = false;
                        if (row.used == 1)
                        {
                            auused = true;
                        }
                        wp = new WeaponClass(int.Parse(row.id.ToString()), row.identifier.ToString(), row.name.ToString(), amunition, components, auused);
                        ItemDatabase.userWeapons[wp.getId()] = wp;
                    }

                    source.TriggerEvent("vorpInventory:giveLoadout", weaponsinvento);
                }
            }));
        }
示例#3
0
        private void registerWeapon(int target, string name, ExpandoObject ammos, ExpandoObject components)//Needs dirt level
        {
            PlayerList pl             = new PlayerList();
            Player     p              = null;
            bool       targetIsPlayer = false;

            foreach (Player pla in pl)
            {
                if (int.Parse(pla.Handle) == target)
                {
                    p = pl[target];
                    targetIsPlayer = true;
                }
            }

            string  identifier;
            dynamic CoreUser       = vorpinventory_sv.CORE.getUser(target).getUsedCharacter;
            int     charIdentifier = CoreUser.charIdentifier;

            if (targetIsPlayer)
            {
                identifier = "steam:" + p.Identifiers["steam"];
                if (Config.MaxWeapons != 0)
                {
                    int totalcount = getUserTotalCountWeapons(identifier, charIdentifier);
                    totalcount += 1;
                    if (totalcount > Config.MaxWeapons)
                    {
                        Debug.WriteLine($"{p.Name} Can't carry more weapons");
                        return;
                    }
                }
            }
            else
            {
                identifier = target.ToString();
            }

            Dictionary <string, int> ammoaux = new Dictionary <string, int>();

            if (ammos != null)
            {
                foreach (KeyValuePair <string, object> ammo in ammos)
                {
                    ammoaux.Add(ammo.Key, int.Parse(ammo.Value.ToString()));
                }
            }

            List <string> auxcomponents = new List <string>();

            if (components != null)
            {
                foreach (KeyValuePair <string, object> component in components)
                {
                    auxcomponents.Add(component.Key);
                }
            }

            Exports["ghmattimysql"].execute("INSERT INTO loadout (`identifier`,`charidentifier`,`name`,`ammo`,`components`) VALUES (?,?,?,?,?)", new object[] { identifier, charIdentifier, name, Newtonsoft.Json.JsonConvert.SerializeObject(ammoaux), Newtonsoft.Json.JsonConvert.SerializeObject(auxcomponents) }, new Action <dynamic>((result) =>
            {
                int weaponId          = result.insertId;
                WeaponClass auxWeapon = new WeaponClass(weaponId, identifier, name, ammoaux, auxcomponents, false, false, charIdentifier);
                ItemDatabase.userWeapons.Add(weaponId, auxWeapon);
                if (targetIsPlayer)
                {
                    TriggerEvent("syn_weapons:registerWeapon", weaponId);
                    p.TriggerEvent("vorpinventory:receiveWeapon", weaponId, ItemDatabase.userWeapons[weaponId].getPropietary(),
                                   ItemDatabase.userWeapons[weaponId].getName(), ItemDatabase.userWeapons[weaponId].getAllAmmo(), ItemDatabase.userWeapons[weaponId].getAllComponents());
                }
            }));
        }
示例#4
0
        private void registerWeapon(int target, string name, ExpandoObject ammos, ExpandoObject components)//Needs dirt level
        {
            PlayerList pl             = new PlayerList();
            Player     p              = null;
            bool       targetIsPlayer = false;

            foreach (Player pla in pl)
            {
                if (int.Parse(pla.Handle) == target)
                {
                    p = pl[target];
                    targetIsPlayer = true;
                }
            }

            string identifier;

            if (targetIsPlayer)
            {
                identifier = "steam:" + p.Identifiers["steam"];
                if (Config.MaxWeapons != 0)
                {
                    int totalcount = getUserTotalCountWeapons(identifier);
                    totalcount += 1;
                    if (totalcount > Config.MaxWeapons)
                    {
                        Debug.WriteLine($"{p.Name} Can't carry more weapons");
                        return;
                    }
                }
            }
            else
            {
                identifier = target.ToString();
            }

            Dictionary <string, int> ammoaux = new Dictionary <string, int>();

            if (ammos != null)
            {
                foreach (KeyValuePair <string, object> ammo in ammos)
                {
                    ammoaux.Add(ammo.Key, int.Parse(ammo.Value.ToString()));
                }
            }

            List <string> auxcomponents = new List <string>();

            if (components != null)
            {
                foreach (KeyValuePair <string, object> component in components)
                {
                    auxcomponents.Add(component.Key);
                }
            }
            int weaponId = -1;

            Exports["ghmattimysql"].execute("SELECT `AUTO_INCREMENT` FROM  INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'vorp' AND TABLE_NAME   = 'loadout';",
                                            new Action <dynamic>((id) =>
            {
                weaponId = int.Parse(id[0].AUTO_INCREMENT.ToString());
                Debug.WriteLine(weaponId.ToString());
                Exports["ghmattimysql"]
                .execute(
                    "INSERT INTO loadout (`identifier`,`name`,`ammo`,`components`) VALUES (?,?,?,?)", new object[] { identifier, name
                                                                                                                     , Newtonsoft.Json.JsonConvert.SerializeObject(ammoaux), Newtonsoft.Json.JsonConvert.SerializeObject(auxcomponents) });

                WeaponClass auxWeapon = new WeaponClass(weaponId, identifier, name, ammoaux, auxcomponents, false);
                ItemDatabase.userWeapons.Add(weaponId, auxWeapon);
                if (targetIsPlayer)
                {
                    p.TriggerEvent("vorpinventory:receiveWeapon", weaponId, ItemDatabase.userWeapons[weaponId].getPropietary(),
                                   ItemDatabase.userWeapons[weaponId].getName(), ItemDatabase.userWeapons[weaponId].getAllAmmo(), ItemDatabase.userWeapons[weaponId].getAllComponents());
                }
            }));
        }
        private async void LoadDatabase()
        {
            await Delay(2000);

            Exports["ghmattimysql"].execute("SELECT * FROM items", new Action <dynamic>((result) =>
            {
                if (result.Count == 0)
                {
                    Debug.WriteLine("There`re no items in database");
                }
                else
                {
                    items = result;
                    foreach (dynamic item in items)
                    {
                        svItems.Add(item.item.ToString(), new Items(item.item, item.label, int.Parse(item.limit.ToString()), item.can_remove, item.type, item.usable));
                    }
                    Exports["ghmattimysql"].execute("SELECT identifier,inventory FROM characters", new Action <dynamic>((uinvento) =>
                    {
                        if (uinvento.Count == 0)
                        {
                            Debug.WriteLine("No users inventory");
                        }
                        else
                        {
                            foreach (var userInventory in uinvento)
                            {
                                //Carga del inventario
                                string user = userInventory.identifier.ToString();
                                Dictionary <string, ItemClass> userinv = new Dictionary <string, ItemClass>();
                                List <WeaponClass> userwep             = new List <WeaponClass>();
                                if (userInventory.inventory != null)
                                {
                                    dynamic thing = Newtonsoft.Json.JsonConvert.DeserializeObject <dynamic>(userInventory.inventory);
                                    foreach (dynamic itemname in items)
                                    {
                                        if (thing[itemname.item.ToString()] != null)
                                        {
                                            ItemClass item = new ItemClass(int.Parse(thing[itemname.item.ToString()].ToString()), int.Parse(itemname.limit.ToString()),
                                                                           itemname.label, itemname.item, itemname.type, itemname.usable, itemname.can_remove);
                                            userinv.Add(itemname.item.ToString(), item);
                                        }
                                    }
                                    usersInventory.Add(user, userinv);
                                }
                                else
                                {
                                    usersInventory.Add(user, userinv);
                                }
                            }
                        }
                    }));
                    Exports["ghmattimysql"].execute("SELECT * FROM loadout", new Action <dynamic>((weaponsinvento) =>
                    {
                        if (weaponsinvento.Count == 0)
                        {
                            Debug.WriteLine("There is no loadout on server database");
                        }
                        else
                        {
                            WeaponClass wp;
                            foreach (var row in weaponsinvento)
                            {
                                JObject ammo = Newtonsoft.Json.JsonConvert.DeserializeObject(row.ammo.ToString());
                                JArray comp  = Newtonsoft.Json.JsonConvert.DeserializeObject(row.components.ToString());
                                Dictionary <string, int> amunition = new Dictionary <string, int>();
                                List <string> components           = new List <string>();
                                foreach (JProperty ammos in ammo.Properties())
                                {
                                    //Debug.WriteLine(ammos.Name);
                                    amunition.Add(ammos.Name, int.Parse(ammos.Value.ToString()));
                                }
                                foreach (JToken x in comp)
                                {
                                    components.Add(x.ToString());
                                }

                                bool auused = false;
                                if (row.used == 1)
                                {
                                    auused = true;
                                }
                                wp = new WeaponClass(int.Parse(row.id.ToString()), row.identifier.ToString(), row.name.ToString(), amunition, components, auused);
                                userWeapons.Add(wp.getId(), wp);
                            }
                        }
                    }));
                }
            }));
        }
示例#6
0
        private void getInventory([FromSource] Player source)
        {
            string steamId = "steam:" + source.Identifiers["steam"];

            dynamic CoreUser = CORE.getUser(int.Parse(source.Handle)).getUsedCharacter;

            int    charIdentifier = CoreUser.charIdentifier;
            string inventory      = CoreUser.inventory;

            Dictionary <string, Item> userinv = new Dictionary <string, Item>();
            List <WeaponClass>        userwep = new List <WeaponClass>();

            if (inventory != null)
            {
                Dictionary <string, int> ITEMS = Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <string, int> >(inventory);
                foreach (var item in ITEMS)
                {
                    userinv.Add(item.Key, new Item(item.Key, ItemDatabase.svItems[item.Key].Label, ItemDatabase.svItems[item.Key].Type, ItemDatabase.svItems[item.Key].Model, item.Value, ItemDatabase.svItems[item.Key].Limit, ItemDatabase.svItems[item.Key].Weight, ItemDatabase.svItems[item.Key].CanUse, ItemDatabase.svItems[item.Key].CanRemove, ItemDatabase.svItems[item.Key].DropOnDeath));
                }
                ItemDatabase.usersInventory[steamId] = userinv;
            }
            else
            {
                ItemDatabase.usersInventory[steamId] = userinv;
            }

            source.TriggerEvent("vorpInventory:giveInventory", inventory);

            Exports["ghmattimysql"].execute("SELECT * FROM loadout WHERE `identifier` = ? AND `charidentifier` = ?;", new object[] { steamId, charIdentifier }, new Action <dynamic>((weaponsinvento) =>
            {
                if (weaponsinvento.Count == 0)
                {
                }
                else
                {
                    WeaponClass wp;
                    foreach (var row in weaponsinvento)
                    {
                        JObject ammo = Newtonsoft.Json.JsonConvert.DeserializeObject(row.ammo.ToString());
                        JArray comp  = Newtonsoft.Json.JsonConvert.DeserializeObject(row.components.ToString());
                        Dictionary <string, int> amunition = new Dictionary <string, int>();
                        List <string> components           = new List <string>();
                        foreach (JProperty ammos in ammo.Properties())
                        {
                            //Debug.WriteLine(ammos.Name);
                            amunition.Add(ammos.Name, int.Parse(ammos.Value.ToString()));
                        }
                        foreach (JToken x in comp)
                        {
                            components.Add(x.ToString());
                        }

                        bool auused = false;
                        if (row.used == 1)
                        {
                            auused = true;
                        }
                        wp = new WeaponClass(int.Parse(row.id.ToString()), row.identifier.ToString(), row.name.ToString(), amunition, components, auused, charIdentifier);
                        ItemDatabase.userWeapons[wp.getId()] = wp;
                    }

                    source.TriggerEvent("vorpInventory:giveLoadout", weaponsinvento);
                }
            }));
        }